Skip to content

Commit ccaff44

Browse files
committed
Updates for review process plus README
1 parent c4a9ca8 commit ccaff44

File tree

5 files changed

+48
-24
lines changed

5 files changed

+48
-24
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
<h1 class="custom-font miami-neon-text">Conformist</h1>
1414

15+
## About
16+
1517
Conformist v1.1.1 is an implementation of conformal prediction, specifically conformal risk control. It was written using Python 3.8.
1618

1719
*BaseCoP* contains utility functions common to all conformal predictors, such as splitting data into calibration and validation sets, and setting up runs. It is extended by *FNRCoP* that implements conformal risk control.
@@ -68,3 +70,8 @@ mcp.calibrate()
6870
formatted_predictions = mcp.predict(testpd,
6971
OUTPUT_DIR)
7072
```
73+
74+
## Publication
75+
76+
Mariya Lysenkova Wiklander et al. Error Reduction in Leukemia Machine Learning Classification With Conformal Prediction. JCO Clin Cancer Inform 9, e2400324(2025).
77+
DOI:[10.1200/CCI-24-00324](https://doi.org/10.1200/CCI-24-00324)

src/conformist/base_cop.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class BaseCoP(OutputDir):
2020
FIGURE_HEIGHT = 8
2121
plt.rcParams.update({'font.size': FIGURE_FONTSIZE})
2222

23+
plt.rcParams["pdf.fonttype"] = 42 # If saving as PDF too
24+
plt.rcParams["font.family"] = "Univers, DejaVu Sans" # Choose a font that supports embedding
25+
26+
27+
2328
def __init__(self, prediction_dataset: PredictionDataset, alpha=0.1):
2429
self.prediction_dataset = prediction_dataset
2530
self.alpha = alpha
@@ -198,8 +203,9 @@ def prediction_sets_to_text(self, prediction_sets, display_classes=None):
198203
for prediction_set in prediction_sets]
199204

200205
def upset_plot(self, predictions_sets, output_dir, color="black"):
201-
plt.figure(figsize=(self.FIGURE_WIDTH,
202-
self.FIGURE_HEIGHT))
206+
fig = plt.figure(figsize=(8, 3))
207+
plt.tight_layout()
208+
plt.rcParams.update({'font.size': 6})
203209

204210
class_names = self.class_names
205211

@@ -214,8 +220,17 @@ def upset_plot(self, predictions_sets, output_dir, color="black"):
214220
# Set a multi-index
215221
upset_data.set_index(upset_data.columns.tolist(), inplace=True)
216222

217-
plot(upset_data, sort_by="cardinality", facecolor=color, show_counts="%d", show_percentages="{:.0%}")
223+
plot(upset_data,
224+
fig=fig,
225+
element_size=15,
226+
sort_by="cardinality",
227+
facecolor=color,
228+
show_counts="%d",
229+
show_percentages="{:.0%}")
230+
231+
# fig.set_size_inches(8, 3)
232+
plt.tight_layout(w_pad=0)
218233

219-
path = f'{output_dir}/upset_plot.png'
234+
path = f'{output_dir}/upset_plot.pdf'
220235
print("Saving upset plot to", path)
221-
plt.savefig(path)
236+
plt.savefig(path, bbox_inches='tight', format='pdf')

src/conformist/model_vs_cop_fnr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def run_reports(self):
103103
plt.legend(loc='upper right')
104104

105105
# Save the plot to a file
106-
fig.set_size_inches(4, 3)
106+
fig.set_size_inches(4, 2)
107107
plt.tight_layout(w_pad=0)
108108
plt.savefig(f'{self.output_dir}/model_vs_CoP_FNR.pdf', format='pdf')
109109
print(f'Reports saved to {self.output_dir}')

src/conformist/performance_report.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class PerformanceReport(OutputDir):
99
FIGURE_WIDTH = 12
1010
FIGURE_HEIGHT = 8
1111
plt.rcParams.update({'font.size': FIGURE_FONTSIZE})
12+
plt.rcParams["pdf.fonttype"] = 42 # If saving as PDF too
13+
plt.rcParams["font.family"] = "Univers, DejaVu Sans" # Choose a font that supports embedding
14+
15+
1216

1317
def __init__(self, base_output_dir):
1418
self.create_output_dir(base_output_dir)
@@ -48,10 +52,12 @@ def _class_report(self,
4852
items_by_class,
4953
output_file_prefix,
5054
ylabel,
51-
color):
55+
color,
56+
title=None):
5257
# Reset plt
53-
plt.figure(figsize=(self.FIGURE_WIDTH,
54-
self.FIGURE_HEIGHT))
58+
fig = plt.figure()
59+
plt.tight_layout()
60+
plt.rcParams.update({'font.size': 6})
5561

5662
# Remove the grid
5763
plt.grid(False)
@@ -69,31 +75,27 @@ def _class_report(self,
6975

7076
# Visualize this dict as a bar chart
7177
# sns.set_style('whitegrid')
72-
fig, ax = plt.subplots(figsize=(
73-
self.FIGURE_WIDTH,
74-
self.FIGURE_HEIGHT))
78+
fig, ax = plt.subplots()
79+
plt.tight_layout()
7580
bars = ax.bar(range(len(mean_sizes)), mean_sizes.values(), color=color)
7681
ax.set_xticks(range(len(mean_sizes)))
7782
ax.set_xticklabels(mean_sizes.keys(),
7883
rotation='vertical')
79-
ax.tick_params(axis='both',
80-
labelsize=PerformanceReport.FIGURE_FONTSIZE)
81-
ax.set_ylabel(ylabel,
82-
fontsize=PerformanceReport.FIGURE_FONTSIZE)
83-
ax.set_xlabel('True class', fontsize=PerformanceReport.FIGURE_FONTSIZE)
84+
ax.tick_params(axis='both')
85+
ax.set_ylabel(ylabel)
86+
ax.set_xlabel('True class')
8487

8588
# Print the number above each bar
8689
for bar in bars:
8790
height = bar.get_height()
8891
ax.text(
8992
bar.get_x() + bar.get_width() / 2.0, height, f'{height:.2f}',
9093
ha='center',
91-
va='bottom',
92-
fontsize=PerformanceReport.FIGURE_FONTSIZE)
93-
94+
va='bottom')
9495

95-
plt.tight_layout()
96-
plt.savefig(f'{self.output_dir}/{output_file_prefix}.png')
96+
fig.set_size_inches(4, 3)
97+
plt.tight_layout(w_pad=0)
98+
plt.savefig(f'{self.output_dir}/{output_file_prefix}.pdf', format='pdf')
9799

98100
def visualize_mean_set_sizes_by_class(self,
99101
mean_set_sizes_by_class):

src/conformist/prediction_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def visualize_prediction_stripplot(self,
660660
loc='lower center',
661661
frameon=False,
662662
ncol=4,
663-
bbox_to_anchor=(0.35, -0.2),
663+
bbox_to_anchor=(0.35, -0.3),
664664
handletextpad=1, # Increase padding between legend handle and text
665665
columnspacing=2 # Increase spacing between columns
666666
)
@@ -680,7 +680,7 @@ def visualize_prediction_stripplot(self,
680680

681681
# plt.tight_layout()
682682

683-
fig.set_size_inches(3.75, 6)
683+
fig.set_size_inches(4, 4)
684684

685685
# Save the plot to a file
686686
# plt.subplots_adjust(hspace=0.5)

0 commit comments

Comments
 (0)