-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrain_model_cv.py
58 lines (52 loc) · 1.69 KB
/
train_model_cv.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
52
53
54
55
56
57
58
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, recall_score, precision_score, roc_auc_score
from flare.model_training import CVTrainer
from flare.eval import scoring_maps, Evaluator
MLFLOW = True
EVAL_TESTING = True
SAVE_TESTING_MODEL = True
if __name__ == "__main__":
exp_params = {
"run_name": "Train Random Forest",
"model_type": RandomForestClassifier.__name__,
"training_data": "./merged_data/brfss_combine_train_v2.csv",
"testing_data": "./merged_data/brfss_combine_test_v2.csv",
"shuffle_seed": 42,
"train_tests_split_seed": 42,
"target": "ADDEPEV3",
"prob_threshold": 0.3,
"model_dir": "./models/",
}
model_params = {
"n_estimators": 100,
"n_jobs": 16,
"max_depth": 20,
"min_samples_leaf": 10,
}
scoring_funcs = (accuracy_score, recall_score, precision_score, roc_auc_score)
scoring = [scoring_maps[metric_func] for metric_func in scoring_funcs]
evaluator = Evaluator(
scoring_funcs,
prob_threshold=exp_params.get("prob_threshold", None),
use_mlflow=MLFLOW,
)
cv_params = {
"n_jobs": 16,
"cv": 5,
"scoring": scoring,
"return_train_score": True,
"verbose": True,
}
model_class = RandomForestClassifier
trainer = CVTrainer(
model_class=model_class,
model_params=model_params,
exp_params=exp_params,
cv_params=cv_params,
scoring_funcs=scoring_funcs,
evaluator=evaluator,
eval_testing=EVAL_TESTING,
save_testing_model=SAVE_TESTING_MODEL,
use_mlflow=MLFLOW,
)
trainer.run()