diff --git a/model_selection/hyperparam_tuning.py b/model_selection/hyperparam_tuning.py index 0e5bcda12e9050595f9d68b88c5aa0324a832abf..fa7dc543803ba9d93f026a40aa805d78d05b1a4d 100644 --- a/model_selection/hyperparam_tuning.py +++ b/model_selection/hyperparam_tuning.py @@ -11,6 +11,7 @@ # -------------------------------------------------------------------------------------------------------- import pandas as pd import numpy as np + from xgboost import XGBClassifier from sklearn.model_selection import StratifiedKFold from sklearn.ensemble import RandomForestClassifier, BaggingClassifier, AdaBoostClassifier @@ -78,7 +79,7 @@ if __name__ == "__main__": "AB" : AdaBoostClassifier(algorithm='SAMME'), "XGB": XGBClassifier(), "LR" : LogisticRegression(max_iter=1000), - "SVM" : SVC(), + "SVM" : SVC(max_iter=1000), "MLP" : MLPClassifier(max_iter=500) # "ElNet" : LogisticRegression(max_iter=1000, penalty='elasticnet') } @@ -89,7 +90,7 @@ if __name__ == "__main__": "Bagging" : BaggingClassifier(estimator= DecisionTreeClassifier(class_weight='balanced')), "AB" : AdaBoostClassifier(estimator= DecisionTreeClassifier(class_weight='balanced'), algorithm='SAMME'), "LR" : LogisticRegression(max_iter=1000, class_weight='balanced'), - "SVM" : SVC(class_weight='balanced'), + "SVM" : SVC(max_iter = 1000, class_weight='balanced'), # "ElNet" : LogisticRegression(max_iter=1000, penalty='elasticnet', class_weight='balanced'), # "XGB": XGBClassifier(), # <- # "MLP" : MLPClassifier(max_iter=500) # <- @@ -142,7 +143,7 @@ if __name__ == "__main__": # Store each df as a sheet in an excel file sheets_dict = {} for i, group in enumerate(['pre']): - for j, method in enumerate(['', '', 'over_', 'under_']): + for j, method in enumerate(['']): #['', '', 'over_', 'under_'] # Get dataset based on group and method X = data_dic['X_train_' + method + group] y = data_dic['y_train_' + method + group] @@ -154,18 +155,17 @@ if __name__ == "__main__": print(f"{group}-{method_names[j]}-{model_name}") # Find optimal hyperparams for curr model params = hyperparameters[model_name] - search = RandomizedSearchCV(model, param_distributions=params, cv=cv, n_jobs=3, scoring='precision') + search = RandomizedSearchCV(model, param_distributions=params, cv=cv, n_jobs=8, scoring='precision') search.fit(X,y) hyperparam_df.at[model_name,'Parameters']=search.best_params_ hyperparam_df.at[model_name,'Score']=round(search.best_score_,4) - os.system('clear') # Store the DataFrame in the dictionary with a unique key for each sheet sheet_name = f"{group}_{method_names[j]}" sheets_dict[sheet_name] = hyperparam_df # Write results to Excel file - with pd.ExcelWriter('./output/hyperparam_pre.xlsx') as writer: + with pd.ExcelWriter('./output/hyperparam_pre_ORIG.xlsx') as writer: for sheet_name, data in sheets_dict.items(): data.to_excel(writer, sheet_name=sheet_name) # -------------------------------------------------------------------------------------------------------- diff --git a/model_selection/output/hyperparam.xlsx b/model_selection/output/hyperparam.xlsx deleted file mode 100644 index cf23ae22eda7fecc10b15ae0a5a978074eb30f38..0000000000000000000000000000000000000000 Binary files a/model_selection/output/hyperparam.xlsx and /dev/null differ diff --git a/model_selection/output/hyperparam_pre_ORIG.xlsx b/model_selection/output/hyperparam_pre_ORIG.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..c1d30a63285d6fa1958c1db6b784d69e0b233314 Binary files /dev/null and b/model_selection/output/hyperparam_pre_ORIG.xlsx differ