text_plain_output_1.png
from sklearn.ensemble import GradientBoostingClassifier

from sklearn.ensemble import RandomForestClassifier

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)

xgb = XGBClassifier(booster='gbtree', learning_rate=0.3, n_estimators=10)
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.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)

from sklearn.ensemble import RandomForestClassifier
rfc = RandomForestClassifier(criterion='entropy', max_features='auto', n_estimators=50, random_state=123)
model3 = rfc.fit(X_train, y_train)
y_hat3 = model3.predict(X_test)
f1 = f1_score(y_test, y_hat3)
acc = accuracy_score(y_test, y_hat3)
(f1, acc)

from sklearn.ensemble import GradientBoostingClassifier
gb = GradientBoostingClassifier()
parameters = {'loss': ['deviance', 'exponential'], 'criterion': ['friedman_mse', 'squared_error'], 'learning_rate': [0.1, 0.3, 10], 'n_estimators': [10, 100, 200]}
grid = GridSearchCV(gb, param_grid=parameters, cv=5, verbose=1)
grid.fit(X_train, y_train)

gb = GradientBoostingClassifier(criterion='friedman_mse', learning_rate=0.1, loss='exponential', n_estimators=100, random_state=123)
model = gb.fit(X_train, y_train)
y_hat = model.predict(X_test)
f1 = f1_score(y_test, y_hat)
acc = accuracy_score(y_test, y_hat)
(f1, acc)