Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
bob.measure
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bob
bob.measure
Commits
f28c83ee
Commit
f28c83ee
authored
Aug 30, 2019
by
Amir MOHAMMADI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add log-scale variant of ROC AUC
parent
d61e7d62
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
5 deletions
+23
-5
bob/measure/__init__.py
bob/measure/__init__.py
+11
-2
bob/measure/script/figure.py
bob/measure/script/figure.py
+7
-3
bob/measure/test_error.py
bob/measure/test_error.py
+5
-0
No files found.
bob/measure/__init__.py
View file @
f28c83ee
...
...
@@ -474,7 +474,7 @@ def eer(negatives, positives, is_sorted=False, also_farfrr=False):
return
(
far
+
frr
)
/
2.0
def
roc_auc_score
(
negatives
,
positives
,
npoints
=
2000
,
min_far
=-
8
):
def
roc_auc_score
(
negatives
,
positives
,
npoints
=
2000
,
min_far
=-
8
,
log_scale
=
False
):
"""Area Under the ROC Curve.
Computes the area under the ROC curve. This is useful when you want to report one
number that represents an ROC curve. For more information, see:
...
...
@@ -490,14 +490,23 @@ def roc_auc_score(negatives, positives, npoints=2000, min_far=-8):
Number of points in the ROC curve. Higher numbers leads to more accurate ROC.
min_far : float, optional
Min FAR and FRR values to consider when calculating ROC.
log_scale : bool, optional
If True, converts the x axis (FPR) to log10 scale before calculating AUC. This is
useful in cases where len(negatives) >> len(positives)
Returns
-------
float
The ROC AUC
The ROC AUC
. If ``log_scale`` is False, the value should be between 0 and 1.
"""
fpr
,
fnr
=
roc
(
negatives
,
positives
,
npoints
,
min_far
=
min_far
)
tpr
=
1
-
fnr
if
log_scale
:
fpr_pos
=
fpr
>
0
fpr
,
tpr
=
fpr
[
fpr_pos
],
tpr
[
fpr_pos
]
fpr
=
numpy
.
log10
(
fpr
)
area
=
-
1
*
numpy
.
trapz
(
tpr
,
fpr
)
return
area
...
...
bob/measure/script/figure.py
View file @
f28c83ee
...
...
@@ -183,7 +183,7 @@ class Metrics(MeasureBase):
def
__init__
(
self
,
ctx
,
scores
,
evaluation
,
func_load
,
names
=
(
'False Positive Rate'
,
'False Negative Rate'
,
'Precision'
,
'Recall'
,
'F1-score'
,
'Area Under ROC Curve'
)):
'Precision'
,
'Recall'
,
'F1-score'
,
'Area Under ROC Curve'
,
'Area Under ROC Curve (log scale)'
)):
super
(
Metrics
,
self
).
__init__
(
ctx
,
scores
,
evaluation
,
func_load
)
self
.
names
=
names
self
.
_tablefmt
=
ctx
.
meta
.
get
(
'tablefmt'
)
...
...
@@ -229,8 +229,9 @@ class Metrics(MeasureBase):
# AUC ROC
auc
=
roc_auc_score
(
neg
,
pos
)
auc_log
=
roc_auc_score
(
neg
,
pos
,
log_scale
=
True
)
return
(
fta
,
fmr
,
fnmr
,
hter
,
far
,
frr
,
fm
,
ni
,
fnm
,
nc
,
precision
,
recall
,
f1_score
,
auc
)
recall
,
f1_score
,
auc
,
auc_log
)
def
_strings
(
self
,
metrics
):
n_dec
=
'.%df'
%
self
.
_decimal
...
...
@@ -246,9 +247,10 @@ class Metrics(MeasureBase):
recall_str
=
"%s"
%
format
(
metrics
[
11
],
n_dec
)
f1_str
=
"%s"
%
format
(
metrics
[
12
],
n_dec
)
auc_str
=
"%s"
%
format
(
metrics
[
13
],
n_dec
)
auc_log_str
=
"%s"
%
format
(
metrics
[
14
],
n_dec
)
return
(
fta_str
,
fmr_str
,
fnmr_str
,
far_str
,
frr_str
,
hter_str
,
prec_str
,
recall_str
,
f1_str
,
auc_str
)
prec_str
,
recall_str
,
f1_str
,
auc_str
,
auc_log_str
)
def
_get_all_metrics
(
self
,
idx
,
input_scores
,
input_names
):
''' Compute all metrics for dev and eval scores'''
...
...
@@ -308,6 +310,7 @@ class Metrics(MeasureBase):
[
self
.
names
[
3
],
all_metrics
[
0
][
7
]],
[
self
.
names
[
4
],
all_metrics
[
0
][
8
]],
[
self
.
names
[
5
],
all_metrics
[
0
][
9
]],
[
self
.
names
[
6
],
all_metrics
[
0
][
10
]],
]
if
self
.
_eval
:
...
...
@@ -325,6 +328,7 @@ class Metrics(MeasureBase):
rows
[
3
].
append
(
all_metrics
[
1
][
7
])
rows
[
4
].
append
(
all_metrics
[
1
][
8
])
rows
[
5
].
append
(
all_metrics
[
1
][
9
])
rows
[
6
].
append
(
all_metrics
[
1
][
10
])
click
.
echo
(
tabulate
(
rows
,
headers
,
self
.
_tablefmt
),
file
=
self
.
log_file
)
...
...
bob/measure/test_error.py
View file @
f28c83ee
...
...
@@ -517,3 +517,8 @@ def test_roc_auc_score():
oracle
=
0.9326
assert
numpy
.
allclose
(
auc
,
oracle
),
f"Expected
{
oracle
}
but got
{
auc
}
instead."
# test the function on log scale as well
auc
=
roc_auc_score
(
negatives
,
positives
,
log_scale
=
True
)
oracle
=
1.4183699583300993
assert
numpy
.
allclose
(
auc
,
oracle
),
f"Expected
{
oracle
}
but got
{
auc
}
instead."
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment