text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import accuracy_score

from sklearn.model_selection import RandomizedSearchCV

from sklearn.model_selection import cross_val_score

from sklearn.naive_bayes import GaussianNB

from sklearn.neighbors import KNeighborsClassifier

from sklearn.preprocessing import StandardScaler

from sklearn.svm import SVC

from xgboost import XGBClassifier

from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X_train)
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)

gnb = GaussianNB()
cv = cross_val_score(gnb, X_train, y_train, cv=5)

lr = LogisticRegression(max_iter=2000)
cv = cross_val_score(lr, X_train, y_train, cv=5)

knn = KNeighborsClassifier(n_neighbors=4)
cv = cross_val_score(knn, X_train, y_train, cv=5)

rf = RandomForestClassifier(random_state=42)
cv = cross_val_score(rf, X_train, y_train, cv=5)

svc = SVC(probability=True)
cv = cross_val_score(svc, X_train, y_train, cv=5)

from xgboost import XGBClassifier
xgb = XGBClassifier(random_state=1)
cv = cross_val_score(xgb, X_train, y_train, cv=5)

def performance(classifier, model_name):
    pass

svc = SVC(probability=True)
param_grid = tuned_parameters = [{'kernel': ['rbf'], 'gamma': [0.1, 0.5, 1, 2, 5, 10], 'C': [0.1, 1, 10, 100, 1000]}, {'kernel': ['linear'], 'C': [0.1, 1, 10, 100, 1000]}, {'kernel': ['poly'], 'degree': [2, 3, 4, 5], 'C': [0.1, 1, 10, 100, 1000]}]
clf_svc = RandomizedSearchCV(svc, param_grid, cv=5, verbose=True, n_jobs=-1)
best_clf_svc = clf_svc.fit(X_train, y_train)
performance(best_clf_svc, 'SVC')

best_svc = best_clf_svc.best_estimator_.fit(X_train, y_train)

y_pred = best_svc.predict(X_test)
accuracy_score(y_pred, y_test)

xgb = XGBClassifier(random_state=42)
param_grid = {'n_estimators': [450, 500, 550], 'colsample_bytree': [0.75, 0.8, 0.85], 'max_depth': [None], 'reg_alpha': [1], 'reg_lambda': [2, 5, 10], 'subsample': [0.55, 0.6, 0.65], 'learning_rate': [0.5], 'gamma': [0.5, 1, 2], 'min_child_weight': [0.01], 'sampling_method': ['uniform']}
clf_xgb = RandomizedSearchCV(xgb, param_grid, cv=5, verbose=True, n_jobs=-1)
best_clf_xgb = clf_xgb.fit(X_train, y_train)
performance(best_clf_xgb, 'XGB')

best_xgb = best_clf_xgb.best_estimator_.fit(X_train, y_train)
y_pred = best_xgb.predict(X_test)
accuracy_score(y_pred, y_test)