Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# we can set the range of the parameters tuned manually
# more info about the parameters to be tuned for each algorithm
# can be found in the MLOpt class
# kNN
tune_range = {'n_neighbors':[10,20,50,100]}
knn = KNNOpt(X_slice,y_slice,params_cv=params_cv,tune_range=tune_range,model_name='knn_porto_seguro',save_dir=save_dir)
knn.tune_params()
print('Best model parameters:')
print(knn.best_model)
knn.save_model()
# SVC
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:')