pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/2f126a70f36e36dd90db53ebdcdff9b990cf3452

5097560d244c08.css" /> Update KDE recipe to match the standard use of the h parameter (gh-#1… · python/cpython@2f126a7 · GitHub
Skip to content

Commit 2f126a7

Browse files
authored
Update KDE recipe to match the standard use of the h parameter (gh-#113958)
1 parent 2e7577b commit 2f126a7

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Doc/library/statistics.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,17 +1104,15 @@ from a fixed number of discrete samples.
11041104
The basic idea is to smooth the data using `a kernel function such as a
11051105
normal distribution, triangular distribution, or uniform distribution
11061106
<https://en.wikipedia.org/wiki/Kernel_(statistics)#Kernel_functions_in_common_use>`_.
1107-
The degree of smoothing is controlled by a single
1108-
parameter, ``h``, representing the variance of the kernel function.
1107+
The degree of smoothing is controlled by a scaling parameter, ``h``,
1108+
which is called the *bandwidth*.
11091109

11101110
.. testcode::
11111111

1112-
import math
1113-
11141112
def kde_normal(sample, h):
11151113
"Create a continuous probability density function from a sample."
1116-
# Smooth the sample with a normal distribution of variance h.
1117-
kernel_h = NormalDist(0.0, math.sqrt(h)).pdf
1114+
# Smooth the sample with a normal distribution kernel scaled by h.
1115+
kernel_h = NormalDist(0.0, h).pdf
11181116
n = len(sample)
11191117
def pdf(x):
11201118
return sum(kernel_h(x - x_i) for x_i in sample) / n
@@ -1128,7 +1126,7 @@ a probability density function estimated from a small sample:
11281126
.. doctest::
11291127

11301128
>>> sample = [-2.1, -1.3, -0.4, 1.9, 5.1, 6.2]
1131-
>>> f_hat = kde_normal(sample, h=2.25)
1129+
>>> f_hat = kde_normal(sample, h=1.5)
11321130
>>> xarr = [i/100 for i in range(-750, 1100)]
11331131
>>> yarr = [f_hat(x) for x in xarr]
11341132

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy