Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
73022908
Commit
73022908
authored
May 11, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
binary stats
parent
32f4366f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
1 deletion
+57
-1
tensorpack/utils/stat.py
tensorpack/utils/stat.py
+57
-1
No files found.
tensorpack/utils/stat.py
View file @
73022908
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
import
numpy
as
np
import
numpy
as
np
__all__
=
[
'StatCounter'
,
'Accuracy'
,
'BinaryStatistics'
]
class
StatCounter
(
object
):
class
StatCounter
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
reset
()
self
.
reset
()
...
@@ -35,7 +37,61 @@ class Accuracy(object):
...
@@ -35,7 +37,61 @@ class Accuracy(object):
@
property
@
property
def
accuracy
(
self
):
def
accuracy
(
self
):
if
self
.
tot
<
0.001
:
if
self
.
tot
==
0
:
return
0
return
0
return
self
.
corr
*
1.0
/
self
.
tot
return
self
.
corr
*
1.0
/
self
.
tot
class
BinaryStatistics
(
object
):
"""
Statistics for binary decision,
including precision, recall, false positive, false negative
"""
def
__init__
(
self
):
self
.
reset
()
def
reset
(
self
):
self
.
nr_pos
=
0
# positive label
self
.
nr_neg
=
0
# negative label
self
.
nr_pred_pos
=
0
self
.
nr_pred_neg
=
0
self
.
corr_pos
=
0
# correct predict positive
self
.
corr_neg
=
0
# correct predict negative
def
feed
(
self
,
pred
,
label
):
"""
:param pred: 0/1 np array
:param label: 0/1 np array of the same size
"""
nr
=
label
.
size
assert
pred
.
size
==
label
.
size
self
.
nr_pos
+=
(
label
==
1
)
.
sum
()
self
.
nr_neg
+=
(
label
==
0
)
.
sum
()
self
.
nr_pred_pos
+=
(
pred
==
1
)
.
sum
()
self
.
nr_pred_neg
+=
(
pred
==
0
)
.
sum
()
self
.
corr_pos
+=
((
pred
==
1
)
&
(
pred
==
label
))
.
sum
()
self
.
corr_neg
+=
((
pred
==
0
)
&
(
pred
==
label
))
.
sum
()
@
property
def
precision
(
self
):
if
self
.
nr_pred_pos
==
0
:
return
0
return
self
.
corr_pos
*
1.
/
self
.
nr_pred_pos
@
property
def
recall
(
self
):
if
self
.
nr_pos
==
0
:
return
0
return
self
.
corr_pos
*
1.
/
self
.
nr_pos
@
property
def
false_positive
(
self
):
if
self
.
nr_pred_pos
==
0
:
return
0
return
1
-
self
.
precision
@
property
def
false_negative
(
self
):
if
self
.
nr_pos
==
0
:
return
0
return
1
-
self
.
recall
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