Commit d346320a authored by Alessia Marcolini's avatar Alessia Marcolini
Browse files

Selection of best rows according to a reference metric, better output file

parent 931f24fa
......@@ -8,21 +8,31 @@ PATH = os.path.abspath(os.path.curdir)
import numpy as np
import pandas as pd
#%%
EXPERIMENT_NAME = 'predictions'
DAP_EXPERIMENT_NAME = 'kfold_radiomics_features_CT_F_SVC_Locoregional_DAPSVMClassifier'
EXPERIMENT_NAME = 'LR_noTx_branch_wise_free_aug_CT_20191027-124913'
DAP_EXPERIMENT_NAME = 'kfold_features_noTx_AUG_DAPSVMClassifier'
#%%
all_train = pd.read_csv(f'{PATH}/{EXPERIMENT_NAME}/{DAP_EXPERIMENT_NAME}/CI_All_train.csv')
all_train = pd.read_csv(f'{PATH}/experiments/{EXPERIMENT_NAME}/{DAP_EXPERIMENT_NAME}/CI_All_train.csv')
all_train.rename({'Unnamed: 0': 'metric'}, axis=1, inplace=True)
best_metrics_train = pd.DataFrame()
# %%
metrics = ['ACC', 'AUC', 'DOR', 'MCC', 'NPV', 'PPV', 'SENS', 'SPEC']
metrics = ['ACC', 'MCC', 'SENS', 'SPEC', 'AUC', 'DOR', 'NPV', 'PPV']
ref_metric = 'MCC'
assert ref_metric in metrics
# %%
only_ref_metric = all_train.loc[all_train['metric'].str.startswith(ref_metric)]
row_best_metric = only_ref_metric.iloc[np.where(only_ref_metric['Mean'].max() == only_ref_metric)[0][0]]
best_run = row_best_metric['metric'].split('-')[1]
for metric in metrics:
tmp_metric_df = all_train.loc[all_train['metric'].str.startswith(metric)]
max_tmp_metric_df = tmp_metric_df.iloc[np.where(tmp_metric_df['Mean'].max() == tmp_metric_df)[0][0]]
max_tmp_metric_df = tmp_metric_df.iloc[np.where(tmp_metric_df['metric'].values.str.split('-')[1] == best_run)[0][0]]
best_metrics_train = best_metrics_train.append(max_tmp_metric_df, ignore_index=True)
# %%
best_metrics_train.to_csv(f'{PATH}/{EXPERIMENT_NAME}/{DAP_EXPERIMENT_NAME}/CI_All_train_best_metrics.csv', index=False)
best_metrics_train = best_metrics_train.round(3)
best_metrics_train = best_metrics_train[['metric', 'Mean', 'Lower', 'Upper']]
best_metrics_train.to_csv(f'{PATH}/experiments/{EXPERIMENT_NAME}/{DAP_EXPERIMENT_NAME}/CI_All_train_best_metrics.csv', index=False)
# %%
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