Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mednet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
medai
software
mednet
Commits
661ab557
Commit
661ab557
authored
2 months ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
[engine.classify.evaluator] Fix small numpy-related API change on credible
parent
774e6ef2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#95347
failed
2 months ago
Stage: qa
Stage: doc
Stage: dist
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/mednet/engine/classify/evaluator.py
+6
-2
6 additions, 2 deletions
src/mednet/engine/classify/evaluator.py
src/mednet/scripts/classify/evaluate.py
+16
-0
16 additions, 0 deletions
src/mednet/scripts/classify/evaluate.py
with
22 additions
and
2 deletions
src/mednet/engine/classify/evaluator.py
+
6
−
2
View file @
661ab557
...
...
@@ -133,10 +133,12 @@ def run(
name
:
str
,
predictions
:
typing
.
Sequence
[
Prediction
],
binning
:
str
|
int
,
rng
:
numpy
.
random
.
Generator
,
threshold_a_priori
:
float
|
None
=
None
,
credible_regions
:
bool
=
False
,
)
->
dict
[
str
,
typing
.
Any
]:
"""
Run inference and calculates measures for binary or multilabel classification.
"""
Run inference and calculates measures for binary or multilabel
classification.
For multi-label problems, calculate the metrics in the
"
micro
"
sense by
first rasterizing all scores and labels (with :py:func:`numpy.ravel`), and
...
...
@@ -152,6 +154,8 @@ def run(
The binning algorithm to use for computing the bin widths and
distribution for histograms. Choose from algorithms supported by
:py:func:`numpy.histogram`.
rng
An initialized numpy random number generator.
threshold_a_priori
A threshold to use, evaluated *a priori*, if must report single values.
If this value is not provided, an *a posteriori* threshold is calculated
...
...
@@ -218,7 +222,7 @@ def run(
f
"
(samples =
{
len
(
predictions
)
}
) -
"
f
"
note this can be slow on very large datasets...
"
)
f1
=
credible
.
bayesian
.
metrics
.
f1_score
(
y_labels
,
y_predictions
)
f1
=
credible
.
bayesian
.
metrics
.
f1_score
(
y_labels
,
y_predictions
,
rng
=
rng
)
roc_auc
=
credible
.
bayesian
.
metrics
.
roc_auc_score
(
y_labels
,
y_scores
)
precision
=
credible
.
bayesian
.
metrics
.
precision_score
(
y_labels
,
y_predictions
)
recall
=
credible
.
bayesian
.
metrics
.
recall_score
(
y_labels
,
y_predictions
)
...
...
This diff is collapsed.
Click to expand it.
src/mednet/scripts/classify/evaluate.py
+
16
−
0
View file @
661ab557
...
...
@@ -114,6 +114,17 @@ logger = setup_cli_logger()
default
=
False
,
cls
=
ResourceOption
,
)
@click.option
(
"
--seed
"
,
"
-s
"
,
help
=
"""
Seed to use for the random number generator (used when doing Monte Carlo
"
simulations required for the evaluation of credible regions for F1-score).
"""
,
show_default
=
True
,
required
=
False
,
default
=
42
,
type
=
click
.
IntRange
(
min
=
0
),
cls
=
ResourceOption
,
)
@verbosity_option
(
logger
=
logger
,
expose_value
=
False
)
def
evaluate
(
predictions
:
pathlib
.
Path
,
...
...
@@ -122,6 +133,7 @@ def evaluate(
binning
:
str
,
plot
:
bool
,
credible_regions
:
bool
,
seed
:
int
,
**
_
,
# ignored
)
->
None
:
# numpydoc ignore=PR01
"""
Evaluate predictions (from a model) on a classification task.
"""
...
...
@@ -129,6 +141,7 @@ def evaluate(
import
typing
import
matplotlib.backends.backend_pdf
import
numpy
from
...engine.classify.evaluator
import
make_plots
,
make_table
,
run
from
..utils
import
save_json_metadata
,
save_json_with_backup
...
...
@@ -167,6 +180,8 @@ def evaluate(
or can not be converted to a float. Check your input.
"""
,
)
rng
=
numpy
.
random
.
default_rng
(
seed
)
results
:
dict
[
str
,
dict
[
str
,
typing
.
Any
]]
=
dict
()
for
k
,
v
in
predict_data
.
items
():
logger
.
info
(
f
"
Computing performance on split `
{
k
}
`...
"
)
...
...
@@ -174,6 +189,7 @@ def evaluate(
name
=
k
,
predictions
=
v
,
binning
=
int
(
binning
)
if
binning
.
isnumeric
()
else
binning
,
rng
=
rng
,
threshold_a_priori
=
use_threshold
,
credible_regions
=
credible_regions
,
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment