text_html_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import f1_score ,accuracy_score

from sklearn.model_selection import GridSearchCV

from sklearn.model_selection import GridSearchCV

from xgboost import XGBClassifier

xgb = XGBClassifier()
model1 = xgb.fit(X_train, y_train)
y_hat = model1.predict(X_test)
f1 = f1_score(y_test, y_hat)
acc = accuracy_score(y_test, y_hat)
(f1, acc)

from sklearn.ensemble import RandomForestClassifier
rfc = RandomForestClassifier()
model2 = rfc.fit(X_train, y_train)
y_hat2 = model2.predict(X_test)
f1 = f1_score(y_test, y_hat2)
acc = accuracy_score(y_test, y_hat2)
(f1, acc)

parameters = {'booster': ['gbtree', 'gblinear', 'dart'], 'learning_rate': [0.1, 0.3, 0.6, 0.9, 1], 'n_estimators': [0.1, 1, 10, 15]}
grid = GridSearchCV(xgb, param_grid=parameters, cv=5, verbose=0)
grid.fit(X_train, y_train)

from sklearn.model_selection import GridSearchCV
rfc = RandomForestClassifier()
parameters = {'criterion': ['gini', 'entropy'], 'max_features': ['auto', 'sqrt', 'log2'], 'n_estimators': [15, 50, 100, 200]}
grid = GridSearchCV(rfc, param_grid=parameters, cv=5, verbose=1)
grid.fit(X_train, y_train)
print(grid.best_params_)