Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e4810b2a
Commit
e4810b2a
authored
Sep 05, 2019
by
Raymond Hettinger
Committed by
GitHub
Sep 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-36324: Apply review comments from Allen Downey (GH-15693)
parent
8f9cc877
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
85 deletions
+83
-85
Doc/library/statistics.rst
Doc/library/statistics.rst
+65
-64
Lib/statistics.py
Lib/statistics.py
+17
-21
Misc/ACKS
Misc/ACKS
+1
-0
No files found.
Doc/library/statistics.rst
View file @
e4810b2a
This diff is collapsed.
Click to expand it.
Lib/statistics.py
View file @
e4810b2a
...
...
@@ -322,7 +322,6 @@ def fmean(data):
"""Convert data to floats and compute the arithmetic mean.
This runs faster than the mean() function and it always returns a float.
The result is highly accurate but not as perfect as mean().
If the input dataset is empty, it raises a StatisticsError.
>>> fmean([3.5, 4.0, 5.25])
...
...
@@ -538,15 +537,16 @@ def mode(data):
``mode`` assumes discrete data, and returns a single value. This is the
standard treatment of the mode as commonly taught in schools:
>>> mode([1, 1, 2, 3, 3, 3, 3, 4])
3
>>> mode([1, 1, 2, 3, 3, 3, 3, 4])
3
This also works with nominal (non-numeric) data:
>>> mode(["red", "blue", "blue", "red", "green", "red", "red"])
'red'
>>> mode(["red", "blue", "blue", "red", "green", "red", "red"])
'red'
If there are multiple modes, return the first one encountered.
If there are multiple modes with same frequency, return the first one
encountered:
>>> mode(['red', 'red', 'green', 'blue', 'blue'])
'red'
...
...
@@ -615,28 +615,28 @@ def multimode(data):
# position is that fewer options make for easier choices and that
# external packages can be used for anything more advanced.
def
quantiles
(
d
ist
,
/
,
*
,
n
=
4
,
method
=
'exclusive'
):
"""Divide *d
ist
* into *n* continuous intervals with equal probability.
def
quantiles
(
d
ata
,
/
,
*
,
n
=
4
,
method
=
'exclusive'
):
"""Divide *d
ata
* into *n* continuous intervals with equal probability.
Returns a list of (n - 1) cut points separating the intervals.
Set *n* to 4 for quartiles (the default). Set *n* to 10 for deciles.
Set *n* to 100 for percentiles which gives the 99 cuts points that
separate *d
ist
* in to 100 equal sized groups.
separate *d
ata
* in to 100 equal sized groups.
The *d
ist
* can be any iterable containing sample data or it can be
The *d
ata
* can be any iterable containing sample data or it can be
an instance of a class that defines an inv_cdf() method. For sample
data, the cut points are linearly interpolated between data points.
If *method* is set to *inclusive*, *d
ist
* is treated as population
If *method* is set to *inclusive*, *d
ata
* is treated as population
data. The minimum value is treated as the 0th percentile and the
maximum value is treated as the 100th percentile.
"""
if
n
<
1
:
raise
StatisticsError
(
'n must be at least 1'
)
if
hasattr
(
d
ist
,
'inv_cdf'
):
return
[
d
ist
.
inv_cdf
(
i
/
n
)
for
i
in
range
(
1
,
n
)]
data
=
sorted
(
d
ist
)
if
hasattr
(
d
ata
,
'inv_cdf'
):
return
[
d
ata
.
inv_cdf
(
i
/
n
)
for
i
in
range
(
1
,
n
)]
data
=
sorted
(
d
ata
)
ld
=
len
(
data
)
if
ld
<
2
:
raise
StatisticsError
(
'must have at least two data points'
)
...
...
@@ -745,7 +745,7 @@ def variance(data, xbar=None):
def
pvariance
(
data
,
mu
=
None
):
"""Return the population variance of ``data``.
data should be a
n iterable
of Real-valued numbers, with at least one
data should be a
sequence or iterator
of Real-valued numbers, with at least one
value. The optional argument mu, if given, should be the mean of
the data. If it is missing or None, the mean is automatically calculated.
...
...
@@ -766,10 +766,6 @@ def pvariance(data, mu=None):
>>> pvariance(data, mu)
1.25
This function does not check that ``mu`` is actually the mean of ``data``.
Giving arbitrary values for ``mu`` may lead to invalid or impossible
results.
Decimals and Fractions are supported:
>>> from decimal import Decimal as D
...
...
@@ -913,8 +909,8 @@ class NormalDist:
"NormalDist where mu is the mean and sigma is the standard deviation."
if
sigma
<
0.0
:
raise
StatisticsError
(
'sigma must be non-negative'
)
self
.
_mu
=
mu
self
.
_sigma
=
sigma
self
.
_mu
=
float
(
mu
)
self
.
_sigma
=
float
(
sigma
)
@
classmethod
def
from_samples
(
cls
,
data
):
...
...
Misc/ACKS
View file @
e4810b2a
...
...
@@ -416,6 +416,7 @@ Dima Dorfman
Yves Dorfsman
Michael Dorman
Steve Dower
Allen Downey
Cesar Douady
Dean Draayer
Fred L. Drake, Jr.
...
...
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