Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.measure
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
bob
bob.measure
Commits
880d989b
There was a problem fetching the pipeline summary.
Commit
880d989b
authored
7 years ago
by
Theophile GENTILHOMME
Browse files
Options
Downloads
Patches
Plain Diff
Add confidence interval functionalities
parent
8f6b2c07
No related branches found
No related tags found
2 merge requests
!54
Refactors the score loading and scripts functionality
,
!51
Confidence intervals
Pipeline
#
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bob/measure/test_utils.py
+17
-0
17 additions, 0 deletions
bob/measure/test_utils.py
bob/measure/utils.py
+38
-0
38 additions, 0 deletions
bob/measure/utils.py
doc/py_api.rst
+1
-0
1 addition, 0 deletions
doc/py_api.rst
with
56 additions
and
0 deletions
bob/measure/test_utils.py
0 → 100644
+
17
−
0
View file @
880d989b
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
import
numpy
from
.utils
import
confidence_for_indicator_variable
def
test_confidence_interval
():
def
assert_confidence
(
x
,
n
,
expected_lower
,
expected_upper
):
lower
,
upper
=
confidence_for_indicator_variable
(
x
,
n
)
assert
numpy
.
allclose
(
lower
,
expected_lower
)
assert
numpy
.
allclose
(
upper
,
expected_upper
)
assert_confidence
(
1
,
2
,
0.01257911709342505
,
0.98742088290657493
)
assert_confidence
(
10
,
10
,
0.69150289218123917
,
1
)
assert_confidence
(
0
,
10
,
0
,
0.30849710781876077
)
This diff is collapsed.
Click to expand it.
bob/measure/utils.py
0 → 100644
+
38
−
0
View file @
880d989b
'''
Utilities functionalities
'''
import
scipy.stats
import
numpy
def
confidence_for_indicator_variable
(
x
,
n
,
alpha
=
0.05
):
'''
Calculates the confidence interval for proportion estimates
The Clopper-Pearson interval method is used for estimating the confidence
intervals.
More info on confidence intervals
---------------------------------
https://en.wikipedia.org/wiki/Confidence_interval
https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Clopper-Pearson_interval
Parameters
----------
x : int
The number of successes.
n : int
The number of trials.
alpha : float, optional
The 1-confidence value that you want. For example, alpha should be 0.05
to obtain 95% confidence intervals.
Returns
-------
(float, float) Returns a tuple of (lower_bound, upper_bound) which
shows the limit of your success rate: lower_bound < x/n < upper_bound
'''
lower_bound
=
scipy
.
stats
.
beta
.
ppf
(
alpha
/
2.0
,
x
,
n
-
x
+
1
)
upper_bound
=
scipy
.
stats
.
beta
.
ppf
(
1
-
alpha
/
2.0
,
x
+
1
,
n
-
x
)
if
numpy
.
isnan
(
lower_bound
):
lower_bound
=
0
if
numpy
.
isnan
(
upper_bound
):
upper_bound
=
1
return
(
lower_bound
,
upper_bound
)
This diff is collapsed.
Click to expand it.
doc/py_api.rst
+
1
−
0
View file @
880d989b
...
...
@@ -97,3 +97,4 @@ Details
.. automodule:: bob.measure.calibration
.. automodule:: bob.measure.plot
.. automodule:: bob.measure.load
.. automodule:: bob.measure.utils
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