-
Notifications
You must be signed in to change notification settings - Fork 2
/
randomforest_model.py
43 lines (38 loc) · 1.67 KB
/
randomforest_model.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
from sklearn.ensemble import RandomForestRegressor
import configuration_parser
import ast
__author__ = 'hao yuan'
def get():
config = configuration_parser.parse()
estimators = config.getint(__name__, 'estimators')
exec('max_depth = ' + config.get(__name__, 'max_depth'),locals(),globals())
min_samples_split = config.getint(__name__, 'min_samples_split')
min_samples_leaf = config.getint(__name__, 'min_samples_leaf')
exec('max_leaf_nodes=' + config.get(__name__, 'max_leaf_nodes'),locals(),globals())
jobs = config.getint(__name__, 'jobs')
model = RandomForestRegressor(n_estimators=estimators,
max_depth=max_depth,
min_samples_split=min_samples_split,
min_samples_leaf=min_samples_leaf,
max_leaf_nodes=max_leaf_nodes,
n_jobs=jobs)
return model
def __executeStringNoneOrNumber__(readFromConfig,varAssignment):
try:
int(readFromConfig)
return varAssignment + '=' + readFromConfig # a number
except:
try:
float(readFromConfig)
return varAssignment + '=' + readFromConfig # a number
except:
try:
if exec(readFromConfig) == None: return varAssignment + '=' + readFromConfig # None
except:
return varAssignment + '= \' ' + readFromConfig + '\'' # string
def __executeStringOrInt__(readFromConfig,varAssignment):
try:
int(readFromConfig)
return varAssignment + '=' + readFromConfig # a number
except:
return varAssignment + '= \' ' + readFromConfig + '\'' # string