86 lines
2.7 KiB
Python
86 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Fri Mar 11 11:15:50 2022
|
|
|
|
@author: tanu
|
|
"""
|
|
#%%
|
|
del(t3_res)
|
|
t3_res = MultClassPipeSKF(input_df = numerical_features_df
|
|
, y_targetF = target1
|
|
, var_type = 'numerical'
|
|
, skf_splits = 10)
|
|
pp.pprint(t3_res)
|
|
#print(t3_res)
|
|
|
|
#%% Manually: mean for each model, each metric
|
|
model_name = 'Logistic Regression'
|
|
model_name = 'Naive Bayes'
|
|
model_name = 'K-Nearest Neighbors'
|
|
model_name = 'SVM'
|
|
#%%
|
|
model_metric = 'F1_score'
|
|
|
|
log_reg_f1 = []
|
|
for key in t3_res[model_name]:
|
|
log_reg_f1.append(t3_res[model_name][key][model_metric])
|
|
log_reg_f1M = mean(log_reg_f1)
|
|
print('key:', key, model_metric, ':', log_reg_f1)
|
|
print(log_reg_f1M)
|
|
|
|
log_reg_f1df = pd.DataFrame({model_name: [log_reg_f1M]}, index = [model_metric])
|
|
log_reg_f1df
|
|
|
|
#%%
|
|
model_metric = 'MCC'
|
|
log_reg_mcc = []
|
|
for key in t3_res[model_name]:
|
|
log_reg_mcc.append(t3_res[model_name][key][model_metric])
|
|
log_reg_mccM = mean(log_reg_mcc)
|
|
print('key:', key, model_metric, ':', log_reg_mcc)
|
|
print(log_reg_mccM)
|
|
|
|
log_reg_mccdf = pd.DataFrame({model_name: [log_reg_mccM]}, index = [model_metric])
|
|
log_reg_mccdf
|
|
#%%
|
|
################################################################
|
|
# extract items from wwithin a nested dict
|
|
#%% Classification Metrics we need to mean()
|
|
classification_metrics = {
|
|
'F1_score': []
|
|
,'MCC': []
|
|
,'Precision': []
|
|
,'Recall': []
|
|
,'Accuracy': []
|
|
}
|
|
# "mean() of the current metric across all folds for this model"
|
|
|
|
# the output containing all the metrics across all folds for this model
|
|
out={}
|
|
# Just the mean() for each of the above metrics-per-model
|
|
out_means={}
|
|
|
|
# Build up out{} from t3_res, which came from loopity_loop
|
|
for model in t3_res:
|
|
# NOTE: can't copy objects in Python!!!
|
|
out[model]={'F1_score': [], 'MCC': [], 'Precision': [], 'Recall': [], 'Accuracy': []}
|
|
out_means[model]={} # just to make life easier
|
|
print(model)
|
|
for fold in t3_res[model]:
|
|
for metric in {'F1_score': [], 'MCC': [], 'Precision': [], 'Recall': [], 'Accuracy': []}:
|
|
metric_value = t3_res[model][fold][metric]
|
|
out[model][metric].append(metric_value)
|
|
# now that we've built out{}, let's mean() each metric
|
|
for model in out:
|
|
for metric in {'F1_score': [], 'MCC': [], 'Precision': [], 'Recall': [], 'Accuracy': []}:
|
|
metric_mean = mean(out[model][metric])
|
|
# just some debug output
|
|
# print('model:', model
|
|
# , 'metric: ', metric
|
|
# , metric_mean
|
|
# )
|
|
out[model].update({(metric+'_mean'): metric_mean })
|
|
out_means[model].update({(metric+'_mean'): metric_mean })
|
|
|
|
out_scores = pd.DataFrame(out_means)
|