Commit 901371de authored by Joaquin Torres's avatar Joaquin Torres

tuning post

parent 691640e6
...@@ -142,18 +142,17 @@ if __name__ == "__main__": ...@@ -142,18 +142,17 @@ if __name__ == "__main__":
# -------------------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------------------
# Store each df as a sheet in an excel file # Store each df as a sheet in an excel file
sheets_dict = {} sheets_dict = {}
for i, group in enumerate(['pre']): for i, group in enumerate(['post']):
for j, method in enumerate(['under_']): #['', '', 'over_', 'under_'] for j, method in enumerate(['', '', 'over_', 'under_']):
# Get dataset based on group and method # Get dataset based on group and method
X = data_dic['X_train_' + method + group] X = data_dic['X_train_' + method + group]
y = data_dic['y_train_' + method + group] y = data_dic['y_train_' + method + group]
# Use group of models with class weight if needed # Use group of models with class weight if needed
# models = models_CS if j == 2 else models_simple models = models_CS if j == 2 else models_simple
models = models_simple
# Save results: params and best score for each of the mdodels of this method and group # Save results: params and best score for each of the mdodels of this method and group
hyperparam_df = pd.DataFrame(index=list(models.keys()), columns=['Parameters','Score']) hyperparam_df = pd.DataFrame(index=list(models.keys()), columns=['Parameters','Score'])
for model_name, model in models.items(): for model_name, model in models.items():
print(f"{group}-{method_names[3]}-{model_name}") print(f"{group}-{method_names[j]}-{model_name}")
# Find optimal hyperparams for curr model # Find optimal hyperparams for curr model
params = hyperparameters[model_name] params = hyperparameters[model_name]
search = RandomizedSearchCV(model, param_distributions=params, cv=cv, n_jobs=8, scoring='precision') search = RandomizedSearchCV(model, param_distributions=params, cv=cv, n_jobs=8, scoring='precision')
...@@ -162,11 +161,11 @@ if __name__ == "__main__": ...@@ -162,11 +161,11 @@ if __name__ == "__main__":
hyperparam_df.at[model_name,'Score']=round(search.best_score_,4) hyperparam_df.at[model_name,'Score']=round(search.best_score_,4)
# Store the DataFrame in the dictionary with a unique key for each sheet # Store the DataFrame in the dictionary with a unique key for each sheet
sheet_name = f"{group}_{method_names[3]}" sheet_name = f"{group}_{method_names[j]}"
sheets_dict[sheet_name] = hyperparam_df sheets_dict[sheet_name] = hyperparam_df
# Write results to Excel file # Write results to Excel file
with pd.ExcelWriter('./output/hyperparam_pre_UNDER.xlsx') as writer: with pd.ExcelWriter('./output/hyperparam_post.xlsx') as writer:
for sheet_name, data in sheets_dict.items(): for sheet_name, data in sheets_dict.items():
data.to_excel(writer, sheet_name=sheet_name) data.to_excel(writer, sheet_name=sheet_name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment