-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathrun.py
149 lines (98 loc) · 5 KB
/
run.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# pylint: disable=C0321,C0103,E1221,C0301,E1305,E1121,C0302,C0330
# -*- coding: utf-8 -*-
"""
Run template
python run.py data_profile --config_uri titanic_classifier.py::titanic_lightgbm
python run.py preprocess --config_uri titanic_classifier.py::titanic_lightgbm
python run.py train --config_uri titanic_classifier.py::titanic_lightgbm
python run.py predict --config_uri titanic_classifier.py::titanic_lightgbm
"""
import warnings, copy
warnings.filterwarnings('ignore')
import os, sys
import pandas as pd
####################################################################################
from source.util_feature import log
###### Path ########################################################################
print( os.getcwd())
root = os.path.abspath(os.getcwd()).replace("\\", "/") + "/"
print(root)
dir_data = os.path.abspath( root + "/data/" ) + "/"
dir_data = dir_data.replace("\\", "/")
print(dir_data)
def get_global_pars(config_uri=""):
log("#### Model Params Dynamic loading ###############################################")
from source.util_feature import load_function_uri
model_dict_fun = load_function_uri(uri_name=config_uri )
#### Get dict + Update Global variables
model_dict = model_dict_fun() ### params
return model_dict
####################################################################################################
########## Init variable ###########################################################################
# globals()[config_name]()
###################################################################################
########## Profile data #############################################################
def data_profile(config_uri='titanic_classifier.py::titanic_lightgbm'):
from source.run_feature_profile import run_profile
mdict = get_global_pars( root + config_uri)
m = mdict['global_pars']
log(mdict)
run_profile(path_data = m['path_data_train'],
path_output = m['path_model'] + "/profile/",
n_sample = 5000,
)
###################################################################################
########## Preprocess #############################################################
def preprocess(config_uri='titanic_classifier.py::titanic_lightgbm'):
from source import run_preprocess_old
mdict = get_global_pars( root + config_uri)
m = mdict['global_pars']
log(mdict)
run_preprocess_old.run_preprocess(model_name = m['model_class'],
path_data = m['path_data_train'],
path_output = m['path_model'],
path_config_model = m['path_config_model'],
n_sample = m['n_sample'],
mode = 'run_preprocess')
############################################################################
########## Train ###########################################################
def train(config_uri='titanic_classifier.py::titanic_lightgbm'):
from source import run_train
mdict = get_global_pars( root + config_uri)
m = mdict['global_pars']
log(mdict)
run_train.run_train(config_name= m['model_class'],
path_data = m['path_data_train'],
path_output = m['path_model'],
path_config_model = m['path_config_model'],
n_sample = m['n_sample']
)
######### Check model #############################################################
def check(config_uri='titanic_classifier.py::titanic_lightgbm'):
mdict = get_global_pars( root + config_uri)
m = mdict['global_pars']
log(mdict)
pass
########################################################################################
####### Inference ######################################################################
def predict(config_uri='titanic_classifier.py::titanic_lightgbm'):
from source import run_inference
mdict = get_global_pars( root + config_uri)
m = mdict['global_pars']
log(mdict)
run_inference.run_predict(model_name = m['model_class'],
path_model = m['path_model'],
path_data = m['path_data_test'],
path_output = m['path_output_pred'],
n_sample = m['n_sample']
)
def run_all(config_uri='titanic_classifier.py::titanic_lightgbm'):
preprocess(config_uri)
train(config_uri)
check(config_uri)
predict(config_uri)
###########################################################################################################
###########################################################################################################
if __name__ == "__main__":
import fire
fire.Fire()