-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_hyperparams_gridsearch.py
46 lines (29 loc) · 1.5 KB
/
run_hyperparams_gridsearch.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
from sklearn.ensemble import AdaBoostClassifier, RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
from xgboost import XGBClassifier
from hyperparams.hyperparam_tunning import HyperparamGridSearcher
from hyperparams.hyperparams import *
from utils.data_preprocess import generate_final_training_dataset
from logger import Logger
from sklearn.model_selection import train_test_split
DATA_TYPE = "small"
if __name__ == '__main__':
logger = Logger(show = True, html_output = True, config_file = "config.txt")
final_df = generate_final_training_dataset(DATA_TYPE, logger)
X = final_df.iloc[:, :-2].values
y = final_df.iloc[:, -2].values
y = (y > 0.5) * 1
X_train, _, y_train, _ = train_test_split(X, y, random_state = 13,
test_size = 0.1 if DATA_TYPE == "small" else 0.2)
_, X_valid, _, y_valid = train_test_split(X_train, y_train, random_state = 13,
test_size = 0.2)
valid_data = {'X': X_valid, 'y': y_valid}
grid_searcher = HyperparamGridSearcher(valid_data, logger)
classifier = DecisionTreeClassifier()
grid_searcher.rand_grid_search(classifier,dectree_hyperparams_grid, 200, DATA_TYPE)
classifier = AdaBoostClassifier(base_estimator = DecisionTreeClassifier())
grid_searcher.rand_grid_search(classifier, ada_hyperparams_grid, 200, DATA_TYPE)
classifier = RandomForestClassifier()
grid_searcher.rand_grid_search(classifier, randf_hyperparams_grid, 200, DATA_TYPE)
classifier = XGBClassifier()
grid_searcher.rand_grid_search(classifier, xgb_hyperparams_grid, 200, DATA_TYPE)