From 8fb5cde4eeb8e47a6e18a5932acd5f509dbf2e58 Mon Sep 17 00:00:00 2001 From: atloo1 Date: Fri, 22 Jul 2016 17:07:27 -0500 Subject: [PATCH] -made all model files use the config file, added defaults to said config file --- adaboost_model.py | 14 ++++++++++--- default.conf | 27 ++++++++++++++++++++++++ dtr_model.py | 11 ++++++++++ lkrr_model.py | 8 ++++++-- randomforest_model.py | 48 ++++++++++++++++++++++++++++++++++--------- 5 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 dtr_model.py diff --git a/adaboost_model.py b/adaboost_model.py index afd3750..f1ed006 100644 --- a/adaboost_model.py +++ b/adaboost_model.py @@ -1,9 +1,17 @@ __author__ = 'hao yuan' from sklearn.ensemble import AdaBoostRegressor from sklearn.tree import DecisionTreeRegressor +import configuration_parser def get(): - model = AdaBoostRegressor(DecisionTreeRegressor(max_depth=12), - n_estimators=275) - return model + config = configuration_parser.parse() + estimators = config.getint(__name__, 'estimators') + lr = config.getfloat(__name__, 'learning rate') + loss = config.get(__name__, 'loss function') + 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') + return AdaBoostRegressor(DecisionTreeRegressor(max_depth=max_depth,min_samples_split=min_samples_split, + min_samples_leaf=min_samples_leaf),n_estimators=estimators,loss=loss, + learning_rate=lr) \ No newline at end of file diff --git a/default.conf b/default.conf index e40cee8..be1c80d 100644 --- a/default.conf +++ b/default.conf @@ -25,6 +25,12 @@ test_cases = ${default:test_cases} [LeaveOutAlloyCV] save_path = ../DBTT/graphs/leaveoutAlloy/{}.png +[dtr_model] +max_depth = 5 +min_samples_split = 2 +min_samples_leaf = 1 +split criterion = mse + [gkrr_model] alpha = 0.00139 coef0 = 1 @@ -32,6 +38,27 @@ degree = 3 gamma = 0.518 kernel = rbf +[lkrr_model] +alpha = 0.00518 +gamma = 0.518 +kernel = laplacian + +[randomforest_model] +estimators = 100 +max_depth = 5 +min_samples_split = 2 +min_samples_leaf = 1 +max_leaf_nodes = None +jobs = 1 + +[adaboost_model] +estimators = 275 +max_depth = 12 +min_samples_split = 2 +min_samples_leaf = 1 +learning rate = 1 +loss function = linear + #minmax, size, transfer_function are the verbatim arguments for neurolab.net.newff() #training_algorithm is the verbatim 'support train fcn' for neurolab.train omitting 'train_' #see: https://pythonhosted.org/neurolab/lib.html#module-neurolab.net diff --git a/dtr_model.py b/dtr_model.py new file mode 100644 index 0000000..5c8f8b6 --- /dev/null +++ b/dtr_model.py @@ -0,0 +1,11 @@ +import configuration_parser +import sklearn.tree as tree + +def get(): + config = configuration_parser.parse() + 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') + criterion = config.get(__name__, 'split criterion') + return tree.DecisionTreeRegressor(criterion=criterion,max_depth=max_depth,min_samples_leaf=min_samples_leaf, + min_samples_split=min_samples_split) \ No newline at end of file diff --git a/lkrr_model.py b/lkrr_model.py index 5d4028f..9057812 100644 --- a/lkrr_model.py +++ b/lkrr_model.py @@ -1,8 +1,12 @@ from sklearn.kernel_ridge import KernelRidge +import configuration_parser __author__ = 'haotian' def get(): - - return KernelRidge(alpha= .00518, gamma = .518, kernel='laplacian') \ No newline at end of file + config = configuration_parser.parse() + alpha = config.getfloat(__name__, 'alpha') + gamma = config.getfloat(__name__, 'gamma') + kernel = config.get(__name__, 'kernel') + return KernelRidge(alpha=alpha,gamma=gamma,kernel=kernel) \ No newline at end of file diff --git a/randomforest_model.py b/randomforest_model.py index 4cfc86b..428d181 100644 --- a/randomforest_model.py +++ b/randomforest_model.py @@ -1,15 +1,43 @@ from sklearn.ensemble import RandomForestRegressor - +import configuration_parser +import ast __author__ = 'hao yuan' def get(): - model = RandomForestRegressor(n_estimators=100, - max_features='auto', - max_depth=5, - min_samples_split=2, - min_samples_leaf=1, - min_weight_fraction_leaf=0, - max_leaf_nodes=None, - n_jobs=1) - return model \ No newline at end of file + 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 \ No newline at end of file