This repository has been archived by the owner on May 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [x] I have battle-tested on Overtaci (RMAPPS1279) - [x] At least one of the commits is prefixed with either "fix:" or "feat:" Fixes issue #393. ## Notes for reviewers We changed the name of the argument "prettify_bins" to "continuous_input_to_bins", since the functionality is whether is should be binned or not, rather than whether it should be pretty. Also, for both performance plots by age and sex, the metric is optional (default auc), though metric_fn_to_input can only handle roc_auc_score.
- Loading branch information
Showing
8 changed files
with
86 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/psycop_model_training/model_eval/base_artifacts/plots/performance_by_sex.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from collections.abc import Callable, Sequence | ||
from pathlib import Path | ||
from typing import Optional, Union | ||
|
||
from sklearn.metrics import roc_auc_score | ||
|
||
from psycop_model_training.model_eval.base_artifacts.plots.base_charts import ( | ||
plot_basic_chart, | ||
) | ||
from psycop_model_training.model_eval.base_artifacts.plots.utils import ( | ||
create_performance_by_input, | ||
) | ||
from psycop_model_training.model_eval.dataclasses import EvalDataset | ||
|
||
|
||
def plot_performance_by_sex( | ||
eval_dataset: EvalDataset, | ||
save_path: Optional[Path] = None, | ||
metric_fn: Callable = roc_auc_score, | ||
y_limits: Optional[tuple[float, float]] = (0.5, 1.0), | ||
) -> Union[None, Path]: | ||
"""Plot bar plot of performance (default AUC) by sex at time of prediction. | ||
Args: | ||
eval_dataset: EvalDataset object | ||
save_path (Path, optional): Path to save figure. Defaults to None. | ||
metric_fn (Callable): Callable which returns the metric to calculate | ||
y_limits (tuple[float, float], optional): y-axis limits. Defaults to (0.0, 1.0). | ||
Returns: | ||
Union[None, Path]: Path to saved figure or None if not saved. | ||
""" | ||
|
||
df = create_performance_by_input( | ||
eval_dataset=eval_dataset, | ||
input=eval_dataset.is_female, | ||
input_name="sex", | ||
metric_fn=metric_fn, | ||
bins=None, | ||
bin_continuous_input=False, | ||
) | ||
|
||
df.sex = df.sex.replace({1: "female", 0: "male"}) | ||
|
||
return plot_basic_chart( | ||
x_values=df["sex"], | ||
y_values=df["metric"], | ||
x_title="Sex", | ||
y_title="AUC", | ||
y_limits=y_limits, | ||
plot_type=["bar"], | ||
save_path=save_path, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters