-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAutoMxL_example.py
More file actions
66 lines (48 loc) · 1.88 KB
/
Copy pathAutoMxL_example.py
File metadata and controls
66 lines (48 loc) · 1.88 KB
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
59
60
61
62
63
64
65
66
from AutoMxL import *
from AutoMxL.Utils.Display import print_dict, color_print, print_title1
from AutoMxL.Modelisation.Utils import classifier_evaluate
# Import data
df_raw = import_data('data/bank-additional-full.csv', verbose=False)
df, target = category_to_target(df_raw, "y", "yes")
# df_raw = import_data('data/covtype.csv', verbose=False)
# df, target = category_to_target(df_raw, "target", 2)
print(df.shape)
"""
df.rename(columns={'y_yes': 'target'})
target= 'target'
print(df.columns.tolist())
"""
# instantiate AutoML object
auto_df = AML(df.copy(), target=target)
# explore data
auto_df.explore(verbose=False)
# print_dict(auto_df.d_features)
# data preparation
auto_df.preprocess(process_outliers=True, cat_method='one_hot', verbose=False)
print('\n\n')
print_dict(auto_df.d_preprocess)
print_dict(auto_df.d_features)
# features selection
auto_df.select_features(method='pca', verbose=False)
# random search
res_dict, l_valid_models, best_model_index, df_model_res = auto_df.model_trian_predict(clf='XGBOOST', n_comb=2,
comb_seed=None, verbose=True)
print(pd.DataFrame(res_dict['features_importance']))
"""
# train
auto_df.model_train(clf='RF', n_comb=2, comb_seed=None, verbose=True)
# dev
print_title1("Apply")
df_apply = auto_df.preprocess_apply(df, verbose=False)
df_apply = auto_df.select_features_apply(df_apply, verbose=False)
res_dict, l_valid_models, best_model_index, df_model_res = auto_df.model_predict(df_apply, metric='F1', verbose=True)
# test
y = df_apply[target]
X = df_apply.drop(target, axis=1)
y_proba = res_dict[best_model_index]['model'].predict_proba(X)[:, 1]
y_pred = res_dict[best_model_index]['model'].predict(X)
eval_dict = classifier_evaluate(y, y_pred, y_proba, verbose=0)
color_print("eval_dict")
print_dict(eval_dict)
print(auto_df.hyperopt[best_model_index]['train_metrics'])
"""