From 56beef86e8a718532d722ed26510f1c324ce1a53 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 25 Aug 2019 00:08:08 -0700 Subject: [PATCH 1/3] Remove questionable examples --- Doc/library/statistics.rst | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/Doc/library/statistics.rst b/Doc/library/statistics.rst index bb77228ceac150..a892544b74073f 100644 --- a/Doc/library/statistics.rst +++ b/Doc/library/statistics.rst @@ -734,32 +734,6 @@ Find the `quartiles `_ and `deciles >>> [round(sat.inv_cdf(p / 10)) for p in range(1, 10)] [810, 896, 958, 1011, 1060, 1109, 1162, 1224, 1310] -What percentage of men and women will have the same height in `two normally -distributed populations with known means and standard deviations -`_? - - >>> men = NormalDist(70, 4) - >>> women = NormalDist(65, 3.5) - >>> ovl = men.overlap(women) - >>> round(ovl * 100.0, 1) - 50.3 - -To estimate the distribution for a model than isn't easy to solve -analytically, :class:`NormalDist` can generate input samples for a `Monte -Carlo simulation `_: - -.. doctest:: - - >>> def model(x, y, z): - ... return (3*x + 7*x*y - 5*y) / (11 * z) - ... - >>> n = 100_000 - >>> X = NormalDist(10, 2.5).samples(n) - >>> Y = NormalDist(15, 1.75).samples(n) - >>> Z = NormalDist(5, 1.25).samples(n) - >>> NormalDist.from_samples(map(model, X, Y, Z)) # doctest: +SKIP - NormalDist(mu=19.640137307085507, sigma=47.03273142191088) - Normal distributions commonly arise in machine learning problems. Wikipedia has a `nice example of a Naive Bayesian Classifier From f5dd91b7f103ac0ea03dc1dde9942847712d9639 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 25 Aug 2019 00:20:31 -0700 Subject: [PATCH 2/3] Remove two external links --- Doc/library/statistics.rst | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Doc/library/statistics.rst b/Doc/library/statistics.rst index a892544b74073f..cd1ee538a68b0b 100644 --- a/Doc/library/statistics.rst +++ b/Doc/library/statistics.rst @@ -667,12 +667,8 @@ of applications in statistics. .. method:: NormalDist.overlap(other) - Compute the `overlapping coefficient (OVL) - `_ - between two normal distributions, giving a measure of agreement. - Returns a value between 0.0 and 1.0 giving `the overlapping area for - the two probability density functions - `_. + Returns a value between 0.0 and 1.0 giving the overlapping area for + the two probability density functions. Instances of :class:`NormalDist` support addition, subtraction, multiplication and division by a constant. These operations From 7ab4c9ce0ee0c4ed3e6d93f32a34418e64f7d708 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 25 Aug 2019 00:38:26 -0700 Subject: [PATCH 3/3] Use more stable monte carlo example --- Doc/library/statistics.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Doc/library/statistics.rst b/Doc/library/statistics.rst index cd1ee538a68b0b..04b731dcc44400 100644 --- a/Doc/library/statistics.rst +++ b/Doc/library/statistics.rst @@ -730,6 +730,23 @@ Find the `quartiles `_ and `deciles >>> [round(sat.inv_cdf(p / 10)) for p in range(1, 10)] [810, 896, 958, 1011, 1060, 1109, 1162, 1224, 1310] +To estimate the distribution for a model than isn't easy to solve +analytically, :class:`NormalDist` can generate input samples for a `Monte +Carlo simulation `_: + +.. doctest:: + + >>> def model(x, y, z): + ... return (3*x + 7*x*y - 5*y) / (11 * z) + ... + >>> n = 100_000 + >>> seed = 86753099035768 + >>> X = NormalDist(10, 2.5).samples(n, seed=seed) + >>> Y = NormalDist(15, 1.75).samples(n, seed=seed) + >>> Z = NormalDist(50, 1.25).samples(n, seed=seed) + >>> NormalDist.from_samples(map(model, X, Y, Z)) # doctest: +SKIP + NormalDist(mu=1.8661894803304777, sigma=0.65238717376862) + Normal distributions commonly arise in machine learning problems. Wikipedia has a `nice example of a Naive Bayesian Classifier