How to use the mlopt.sklearn_tune.RandomForestClassifierOpt function in mlopt

To help you get started, we’ve selected a few mlopt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arnaudvl / ml-parameter-optimization / examples / ml_optimization.py View on Github external
tune_range = {'C':[0.01,0.1,1,10,100],
              'gamma':[0.01,0.1,1]}
svc = SVCOpt(X_slice,y_slice,params_cv=params_cv,tune_range=tune_range,model_name='svc_porto_seguro',save_dir=save_dir)
svc.tune_params()
print('Best model parameters:')
print(svc.best_model)
svc.save_model()

# we can also set the parameters that are not tuned

# random forest
params = {'criterion':'gini'}
tune_range = {'n_estimators':[50,100,200,500],
              'max_features':[0.5,0.75],
              'min_samples_leaf':[0.001,0.01]}
rf = RandomForestClassifierOpt(X_slice,y_slice,params=params,params_cv=params_cv,tune_range=tune_range,
                               model_name='rf_porto_seguro',save_dir=save_dir)
rf.tune_params()
print('Best model parameters:')
print(rf.best_model)
rf.save_model()

# increase dataset for xgboost and lightgbm
X_slice = X[:50000,:]
y_slice = y[:50000]

# more complex hyperparameter optimization is done for the xgboost and lightgbm algorithms
# the amount of hyperparameters that need to be tuned does not favour a gridsearch
# approach, so as a result the parameters are optimized in different steps:
# 1. fix learning rate and number of estimators for tuning tree-based parameters
# 2. tune max_depth and min_child_weight
# 3. tune gamma