-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtraining_years_basic_graph.py
68 lines (50 loc) · 2.96 KB
/
training_years_basic_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import math
import os
import numpy as np
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
##############
# Parameters #
##############
training_data_dir = 'experiments/training_years_outliers'
n_folds = 3
depas_to_score = ['Overall', 'Néonatologie', 'Ob/gyn', 'Oncologie', 'Pédiatrie']
depa_rename_dict = {'Overall':'overall', 'Néonatologie':'NICU', 'Ob/gyn':'ob/gyn', 'Oncologie':'oncology', 'Pédiatrie':'general pediatrics'}
contamination_ratio = 0.2
anomaly_algorithm_rename_dict = {'LocalOutlierFactor(contamination={}, novelty=True)'.format(contamination_ratio):'Loc Out Fac', 'IsolationForest(contamination={})'.format(contamination_ratio):'Iso For', 'OneClassSVM(nu={})'.format(contamination_ratio):'One Cl SVM', 'EllipticEnvelope(contamination={})'.format(contamination_ratio):'Rob Cov'}
x_axis_name_in_figure = 'Years'
algorith_name_in_figure = 'Alg'
n_components_name_in_figure = 'components'
column_name_rename_dict = {'param_tsvd__n_components':n_components_name_in_figure, 'param_anomaly_algorithm':algorith_name_in_figure}
columns_to_extract = ['split{}_test_Ratio anomalies {}'.format(n, depa) for depa in depas_to_score for n in range(n_folds)]
columns_to_extract.extend([x_axis_name_in_figure, 'param_tsvd__n_components', 'param_anomaly_algorithm'])
metric_rename_dict = {'split{}_test_Ratio anomalies {}'.format(n,depa):'Atypical profiles ratio {}'.format(depa_rename_dict[depa]) for depa in depas_to_score for n in range(n_folds)}
#############
# Functions #
#############
def makegraphs(datapath):
# load the data files and concatenate them into a single pandas dataframe
files_data = []
for file in os.listdir(datapath):
if file.endswith('.csv'):
file_df = pd.read_csv(os.path.join(datapath, file))
file_df[x_axis_name_in_figure] = os.path.splitext(file)[0]
files_data.append(file_df)
all_data = pd.concat(files_data)
all_data_filtered = all_data[columns_to_extract]
all_data_filtered.rename(inplace=True, index=str, columns=column_name_rename_dict)
all_data_filtered[algorith_name_in_figure] = all_data_filtered[algorith_name_in_figure].map(anomaly_algorithm_rename_dict)
all_data_filtered.set_index([x_axis_name_in_figure, algorith_name_in_figure, n_components_name_in_figure], inplace=True)
all_data_graph_df = all_data_filtered.stack().reset_index()
all_data_graph_df.rename(inplace=True, index=str, columns={'level_3':'Metric', 0:'Result'})
all_data_graph_df['Metric'] = all_data_graph_df['Metric'].map(metric_rename_dict)
all_data_graph_df[x_axis_name_in_figure] = all_data_graph_df[x_axis_name_in_figure].astype('int8')
sns.set(style="whitegrid", font_scale=2.5)
sns.catplot(x=x_axis_name_in_figure, y="Result", hue="Metric", row=algorith_name_in_figure, col=n_components_name_in_figure,data=all_data_graph_df, kind='point', margin_titles=True)
plt.savefig(os.path.join(datapath, 'training_years_results.png'), dpi=200)
#############
## EXECUTE ##
#############
if __name__ == '__main__':
makegraphs(training_data_dir)