jpdefrutos commited on
Commit
e00c8e8
·
1 Parent(s): 7d43ed6

Added input arguments to change the CSV file, separator and output directory

Browse files
Files changed (1) hide show
  1. EvaluationScripts/statistics.py +31 -27
EvaluationScripts/statistics.py CHANGED
@@ -1,21 +1,20 @@
1
  import numpy as np
 
 
2
  from statsmodels.stats.multicomp import pairwise_tukeyhsd
3
  from statsmodels.stats.multitest import fdrcorrection
4
  from scipy import stats
5
  import pandas as pd
6
 
 
 
7
 
8
  # increase length of string in pandas
9
  pd.options.display.max_colwidth = 100
10
 
11
 
12
- def post_hoc_ixi():
13
- file_path = "/Users/andreped/Downloads/ALL_METRICS.csv"
14
-
15
- df = pd.read_csv(file_path, sep=";")
16
- df = df.iloc[:, 1:]
17
- df = df[df["Experiment"] == "IXI"]
18
- df["Model"] = [x.replace("_", "-") for x in df["Model"]]
19
 
20
  TRE_values = df["TRE"]
21
  m_comp = pairwise_tukeyhsd(df["TRE"], df["Model"], alpha=0.05)
@@ -53,20 +52,14 @@ def post_hoc_ixi():
53
  out_pd = out_pd.replace(-1.0, "-")
54
  out_pd = out_pd.replace(-0.0, '\cellcolor{green!25}$<$0.001')
55
 
56
- with open("./tukey_pvalues_result_IXI.txt", "w") as pfile:
57
  pfile.write("{}".format(out_pd.to_latex(escape=False, column_format="r" + "c"*all_pvalues.shape[1], bold_rows=True)))
58
 
59
  print(out_pd)
60
 
61
 
62
- def study_transfer_learning_benefit():
63
- file_path = "/Users/andreped/Downloads/ALL_METRICS.csv"
64
-
65
- df = pd.read_csv(file_path, sep=";")
66
- df = df.iloc[:, 1:]
67
- df["Model"] = [x.replace("_", "-") for x in df["Model"]]
68
-
69
- df_tl = df[df["Experiment"] == "COMET_TL_Ft2Stp"]
70
  df_orig = df[df["Experiment"] == "COMET"]
71
 
72
  pvs = []
@@ -91,14 +84,8 @@ def study_transfer_learning_benefit():
91
  print("UW-NSD:", corrected_pvs[2])
92
 
93
 
94
- def post_hoc_comet():
95
- file_path = "/Users/andreped/Downloads/ALL_METRICS.csv"
96
-
97
- df = pd.read_csv(file_path, sep=";")
98
- df = df.iloc[:, 1:]
99
- df["Model"] = [x.replace("_", "-") for x in df["Model"]]
100
-
101
- df_tl = df[df["Experiment"] == "COMET_TL_Ft2Stp"]
102
 
103
  filter_ = np.array([x in ["BL-N", "SG-NSD", "UW-NSD"] for x in df_tl["Model"]])
104
 
@@ -129,11 +116,28 @@ def post_hoc_comet():
129
 
130
 
131
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  print("\nComparing all contrasts in TRE of all models in the IXI dataset:")
133
- post_hoc_ixi()
134
 
135
  print("\nTransfer learning benefit (COMET):")
136
- study_transfer_learning_benefit()
137
 
138
  print("\nAssessing whether there is a benefit to segmentation-guiding and uncertainty weighting (COMET):")
139
- post_hoc_comet()
 
 
 
 
1
  import numpy as np
2
+ import statsmodels
3
+ import scipy
4
  from statsmodels.stats.multicomp import pairwise_tukeyhsd
5
  from statsmodels.stats.multitest import fdrcorrection
6
  from scipy import stats
7
  import pandas as pd
8
 
9
+ import argparse
10
+ import os
11
 
12
  # increase length of string in pandas
13
  pd.options.display.max_colwidth = 100
14
 
15
 
16
+ def post_hoc_ixi(df_in: pd.DataFrame, outdir: str = './'):
17
+ df = df_in[df_in["Experiment"] == "IXI"]
 
 
 
 
 
18
 
19
  TRE_values = df["TRE"]
20
  m_comp = pairwise_tukeyhsd(df["TRE"], df["Model"], alpha=0.05)
 
52
  out_pd = out_pd.replace(-1.0, "-")
53
  out_pd = out_pd.replace(-0.0, '\cellcolor{green!25}$<$0.001')
54
 
55
+ with open(os.path.join(outdir, "tukey_pvalues_result_IXI.txt"), "w") as pfile:
56
  pfile.write("{}".format(out_pd.to_latex(escape=False, column_format="r" + "c"*all_pvalues.shape[1], bold_rows=True)))
57
 
58
  print(out_pd)
59
 
60
 
61
+ def study_transfer_learning_benefit(df_in: pd.DataFrame):
62
+ df_tl = df_in[df_in["Experiment"] == "COMET_TL_Ft2Stp"]
 
 
 
 
 
 
63
  df_orig = df[df["Experiment"] == "COMET"]
64
 
65
  pvs = []
 
84
  print("UW-NSD:", corrected_pvs[2])
85
 
86
 
87
+ def post_hoc_comet(df_in: pd.DataFrame):
88
+ df_tl = df_in[df_in["Experiment"] == "COMET_TL_Ft2Stp"]
 
 
 
 
 
 
89
 
90
  filter_ = np.array([x in ["BL-N", "SG-NSD", "UW-NSD"] for x in df_tl["Model"]])
91
 
 
116
 
117
 
118
  if __name__ == "__main__":
119
+ parser = argparse.ArgumentParser()
120
+ parser.add_argument('--file', '-f', type=str, help='CSV file with the metrics')
121
+ parser.add_argument('--sep', type=str, help='CSV Separator (default: ;)', default=';')
122
+ parser.add_argument('--outdir', type=str, help='Output directory (default: .)', default='./')
123
+ args = parser.parse_args()
124
+
125
+ assert os.path.exists(args.file), 'CSV file not found'
126
+
127
+ df = pd.read_csv(args.file, sep=args.sep)
128
+ if "Unnamed" in df.columns[0]:
129
+ df = df.iloc[:, 1:]
130
+ if any(['_' in m for m in df["Model"].unique()]):
131
+ df["Model"] = [x.replace("_", "-") for x in df["Model"]]
132
+
133
  print("\nComparing all contrasts in TRE of all models in the IXI dataset:")
134
+ post_hoc_ixi(df, args.outdir)
135
 
136
  print("\nTransfer learning benefit (COMET):")
137
+ study_transfer_learning_benefit(df)
138
 
139
  print("\nAssessing whether there is a benefit to segmentation-guiding and uncertainty weighting (COMET):")
140
+ post_hoc_comet(df)
141
+
142
+ print('Statsmodels v.: ' + statsmodels.__version__)
143
+ print('Scipy v.: ' + scipy.__version__)