-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc_p_vals.py
58 lines (49 loc) · 2.68 KB
/
calc_p_vals.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
# %%
import pandas as pd
import scipy.stats as stats
import matplotlib.pyplot as plt
from scipy.stats import ttest_rel
PAIRS = [
# ['bundle/runs/baseline_dice_brats_2021_high/inference_results/mean_dice_raw.csv', 'bundle/runs/hardl1ace_dice_brats_2021_high/inference_results/mean_dice_raw.csv'],
# ['bundle/runs/baseline_ce_brats_2021_high/inference_results/mean_dice_raw.csv', 'bundle/runs/hardl1ace_ce_brats_2021_high/inference_results/mean_dice_raw.csv'],
# ['bundle/runs/baseline_dice_ce_brats_2021_high/inference_results/mean_dice_raw.csv', 'bundle/runs/hardl1ace_dice_ce_brats_2021_high/inference_results/mean_dice_raw.csv'],
# ['bundle/runs/baseline_dice_brats_2021_high/inference_results/ace_raw.csv', 'bundle/runs/hardl1ace_dice_brats_2021_high/inference_results/ace_raw.csv'],
# ['bundle/runs/baseline_dice_brats_2021_high/inference_results/mce_raw.csv', 'bundle/runs/hardl1ace_dice_brats_2021_high/inference_results/mce_raw.csv'],
[
"bundle/runs/baseline_dice_brats_2021_high/inference_results/ece_raw.csv",
"bundle/runs/hardl1ace_dice_brats_2021_high/inference_results/ece_raw.csv",
],
# ['bundle/runs/baseline_ce_brats_2021_high/inference_results/mean_dice_raw.csv', 'bundle/runs/baseline_ce_brats_2021_high_temp_scaled/inference_results/mean_dice_raw.csv'],
# ['bundle/runs/baseline_dice_ce_brats_2021_high/inference_results/mean_dice_raw.csv', 'bundle/runs/baseline_dice_ce_brats_2021_high_temp_scaled/inference_results/mean_dice_raw.csv'],
# ['bundle/runs/baseline_dice_brats_2021_high/inference_results/mean_dice_raw.csv', 'bundle/runs/baseline_dice_ce_brats_2021_high_temp_scaled/inference_results/mean_dice_raw.csv'],
# ['bundle/runs/hardl1ace_dice_brats_2021_high/inference_results_b10/ace_raw.csv', 'bundle/runs/hardl1ace_dice_brats_2021_high/inference_results_b100/ace_raw.csv'],
#
]
def calc_p_values(pair):
df1 = pd.read_csv(pair[0])
df2 = pd.read_csv(pair[1])
# Columns for comparison
columns = ["class0", "class1", "class2", "mean"]
# Calculate p-values and plot histograms
for col in columns:
t_stat, p_value = ttest_rel(df1[col].dropna(), df2[col].dropna())
print(f"--- Metrics for {col} ---")
print(f"t-statistic: {t_stat}")
print(f"p-value: {p_value}")
# Plot histograms
plt.figure()
plt.hist(df1[col], alpha=0.5, label=pair[1])
plt.hist(df2[col], alpha=0.5, label=pair[0])
plt.xlabel(col)
plt.ylabel("Count")
plt.legend()
plt.show()
# save fig:
plt.savefig("hist.png")
plt.close()
# %%
if __name__ == "__main__":
plt.ion()
for pair in PAIRS:
calc_p_values(pair)
stop = "here"