Skip to content

Commit

Permalink
Account for new keyword in sklearn v1.5+
Browse files Browse the repository at this point in the history
  • Loading branch information
joeranbosma committed Sep 21, 2024
1 parent 84b8f49 commit 4ded80d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def run(self):
long_description = fh.read()

setuptools.setup(
version='1.4.6', # also update version in metrics.py -> version
version='1.4.7', # also update version in metrics.py -> version
author_email='[email protected]',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
20 changes: 15 additions & 5 deletions src/picai_eval/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from typing import Any, Dict, Hashable, List, Optional, Tuple, Union

import numpy as np
import sklearn
from packaging import version
from sklearn.metrics import auc, precision_recall_curve, roc_curve

try:
Expand Down Expand Up @@ -265,11 +267,19 @@ def calculate_precision_recall(self, subject_list: Optional[List[str]] = None) -
y_pred: "npt.NDArray[np.float64]" = np.array([pred for _, pred, *_ in lesion_y_list])

# calculate precision-recall curve
precision, recall, thresholds = precision_recall_curve(
y_true=y_true,
probas_pred=y_pred,
sample_weight=self.get_lesion_weight_flat(subject_list=subject_list)
)
if version.parse(sklearn.__version__) >= version.parse("1.5"):
# in the future this if/else block can be removed, then set 1.5 as minimum in requirements.txt
precision, recall, thresholds = precision_recall_curve(
y_true=y_true,
y_score=y_pred,
sample_weight=self.get_lesion_weight_flat(subject_list=subject_list)
)
else:
precision, recall, thresholds = precision_recall_curve(
y_true=y_true,
probas_pred=y_pred,
sample_weight=self.get_lesion_weight_flat(subject_list=subject_list)
)

# set precision to zero at a threshold of "zero", as those lesion
# candidates are included just to convey the number of lesions to
Expand Down

0 comments on commit 4ded80d

Please sign in to comment.