-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
51 lines (41 loc) · 1.17 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import click
import pandas as pd
from src.etl import Dataset
from src.gradientboost import GradientBoostModel
pd.set_option("display.max_rows", 100)
@click.command()
@click.option(
"--mode",
type=click.Choice(["train"]),
default="train",
)
def cli(mode):
if mode == "train":
train()
else:
pass
def train(
data: Dataset = None,
hparams: dict = None,
save_model: bool = True,
) -> float:
"""
Instantiates a Model object, loads the training data, splits the data into
training and test, stores the files locally and in s3 and finally trains the model.
Returns
-------
model_score [float]: The accuracy score of the model [0-1]
"""
model: GradientBoostModel = GradientBoostModel
data = Dataset(
experiment_model=model.model_type(),
load_from_cache=False,
save_experiment_data=True,
).make_training_data()
if hparams is not None:
for key, value in hparams.items():
model.model_params[key] = value
model_score = model.train(data=data, test_set_percentage=0.1)
return {"model_score": model_score, "model": model}
if __name__ == "__main__":
cli()