def TrainAllModels(splitData): for i in range(5): print("Current i: ", i) if splitData: X_train, X_test, y_train, y_test = getData(useImbalancer=True, useStratify=True) else: X_train, y_train = getData(splitData=splitData, useImbalancer=False, useStratify=True) X_test, y_test = None, None AdaBoostModel(splitData=splitData, X_train=X_train, X_test=X_test, y_train=y_train, y_test=y_test) LogisticRegressionModel(splitData=splitData, X_train=X_train, X_test=X_test, y_train=y_train, y_test=y_test) NeuralNetworkModel(splitData=splitData, X_train=X_train, X_test=X_test, y_train=y_train, y_test=y_test) RandomForestModel(splitData=splitData, X_train=X_train, X_test=X_test, y_train=y_train, y_test=y_test) SVMModel(splitData=splitData, X_train=X_train, X_test=X_test, y_train=y_train, y_test=y_test) XGBClassifierModel(splitData=splitData, X_train=X_train, X_test=X_test, y_train=y_train, y_test=y_test)
from sklearn.ensemble import AdaBoostClassifier, RandomForestClassifier from sklearn.svm import SVC from Utility import printMetrics, getMetrics, logAndSave, logAndSaveV2, getAnnealingData, getData splitData = False if splitData: X_train, X_test, y_train, y_test = getData(useImbalancer=True, useStratify=True) else: X_train, y_train = getData(splitData=splitData, useImbalancer=True, useStratify=True) X_test, y_test = None, None X_train, X_test, y_train, y_test = getAnnealingData() def AdaBoostModel(splitData, X_train, X_test, y_train, y_test): svc = SVC() clf = AdaBoostClassifier(base_estimator=svc, n_estimators=100, algorithm='SAMME') clf.fit(X_train, y_train.ravel()) if splitData: y_preds = clf.predict(X_test) printMetrics(y_test, y_preds) val_acc, val_pre, val_recall, val_auc, val_f1 = getMetrics(y_test, y_preds) else: val_acc, val_pre, val_recall, val_auc, val_f1 = 0, 0, 0, 0, 0 y_preds = clf.predict(X_train).reshape(-1, 1) acc, pre, recall, auc, f1 = getMetrics(y_train, y_preds) val_metrics = (val_acc, val_pre, val_recall, val_auc, val_f1) metrics = (acc, pre, recall, auc, f1)