text_plain_output_1.png
from sklearn.ensemble import AdaBoostClassifier

from sklearn.ensemble import BaggingClassifier

from sklearn.ensemble import ExtraTreesClassifier

from sklearn.ensemble import ExtraTreesClassifier

from sklearn.ensemble import GradientBoostingClassifier

from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import accuracy_score,f1_score

from sklearn.model_selection import GridSearchCV

from sklearn.naive_bayes import GaussianNB

from sklearn.svm import SVC

from xgboost import XGBClassifier

classes = [SVC(), RandomForestClassifier(), AdaBoostClassifier(), BaggingClassifier(), GradientBoostingClassifier(), GaussianNB(), XGBClassifier(), ExtraTreesClassifier()]
params = [[{'kernel': ['rbf'], 'gamma': [0.001, 0.0001], 'C': [1, 10, 100, 1000]}, {'kernel': ['linear'], 'C': [1, 10, 100, 1000]}], [{'n_estimators': [100, 200, 400], 'max_features': ['auto', 'sqrt', 'log2'], 'max_depth': [4, 5, 6, 7, 8], 'criterion': ['gini', 'entropy']}], [{'n_estimators': [100, 200, 300, 400, 500], 'learning_rate': [0.01, 0.1, 1]}], [{'n_estimators': [100, 200, 300, 400, 500], 'max_samples': [0.5, 0.75, 1.0]}], [{'loss': ['deviance'], 'n_estimators': [50, 100, 300, 400, 500], 'max_depth': [3, 5, 8]}], [{'priors': [None]}], [{'learning_rate': [0.03, 0.05], 'max_depth': [1, 2, 4, 6, 8, 10], 'n_estimators': [50, 100, 300, 500]}], [{'n_estimators': [100, 200, 400, 500], 'criterion': ['gini', 'entropy'], 'max_depth': [1, 2, 4, 6, 8, 10]}]]
'params1=[[ {\'n_estimators\': [100,200,400],\n\'learning_rate\':[0.01,0.1,1]}],[{\'n_estimators\': [100,200,400],\n\'max_samples\':[.5, .75, 1.0]}] ,[{"loss":["deviance"],"n_estimators":[50,100,300],\n"max_depth":[3,5,8]}] ,[{"priors":[None]}],[{\'learning_rate\':[.03, .05],\'max_depth\': [1,2,4,6,8,10],\'n_estimators\':[10, 50, 100, 300]}    ],\n [{\'n_estimators\':[100,200,400],\'criterion\':[\'gini\', \'entropy\'],\'max_depth\':[1,2,4,6,8,10]}]]\n'
testlist = []
paramslist = []
bestscore = []
bestestimator = []
for c, p in zip(classes, params):
    print('the model using  is {}'.format(c))
    print('\n')
    print('\n')
    grid_search = GridSearchCV(estimator=c, param_grid=p, cv=5, n_jobs=-1)
    grid_search.fit(train_x, train_y.values.ravel())
    best_param = grid_search.best_params_
    print(best_param)
    paramslist.append(best_param)
    best_score = grid_search.best_score_
    bestscore.append(best_score)
    best_estimator = grid_search.best_estimator_
    bestestimator.append(best_estimator)
    ypred = best_estimator.predict(test_x)
    testlist.append(tuple((accuracy_score(test_y, ypred), f1_score(test_y, ypred))))