Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-115532: Add kernel density estimation to the statistics module#115863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
rhettinger merged 19 commits intopython:mainfromrhettinger:kde
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
19 commits
Select commitHold shift + click to select a range
2a5841d
Add docs and code for kde()
rhettingerFeb 23, 2024
940795f
Alphabetize the function order
rhettingerFeb 23, 2024
482c9c1
Add blurb
rhettingerFeb 23, 2024
e9386ed
Add PDF area test
rhettingerFeb 23, 2024
c3ddb1e
Add tests
rhettingerFeb 23, 2024
a2771cb
Early test for non-numeric data. Tests for name and docstring
rhettingerFeb 23, 2024
e29d64f
Use StatisticsError for invalid kernels
rhettingerFeb 23, 2024
5d8bab0
.
rhettingerFeb 23, 2024
9e6aaa7
Add kde() to __all__
rhettingerFeb 23, 2024
c8b19d8
Add test for non-sequence input
rhettingerFeb 23, 2024
d571452
Fix markup for external link
rhettingerFeb 23, 2024
ddc32b8
Remove outdated KDE recipe
rhettingerFeb 23, 2024
5ac1055
Improve variable names in integration using the midpoint rule.
rhettingerFeb 24, 2024
24e38e2
Improve appearance of generated docstring
rhettingerFeb 24, 2024
e729127
Put the kernel names in italics
rhettingerFeb 24, 2024
e6d6e0f
Add a whatsnew entry
rhettingerFeb 24, 2024
b3fd269
Add test for support interval boundary conditions
rhettingerFeb 25, 2024
9dec308
Sync the docstring with the main docs.
rhettingerFeb 25, 2024
771a232
Fix missing angle bracket markup
rhettingerFeb 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Early test for non-numeric data. Tests for name and docstring
  • Loading branch information
@rhettinger
rhettinger committedFeb 23, 2024
commita2771cbc22e108a9763cd01ed72ca31b06026335
3 changes: 3 additions & 0 deletionsLib/statistics.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -887,6 +887,9 @@ def kde(data, h, kernel='normal'):
if not n:
raise StatisticsError('Empty data sequence')

if not isinstance(data[0], (int, float)):
raise TypeError('Data sequence must contain ints or floats')

if h <= 0.0:
raise StatisticsError(f'Bandwidth h must be positive, not {h=}')

Expand Down
11 changes: 9 additions & 2 deletionsLib/test/test_statistics.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2383,9 +2383,8 @@ def integrate(func, low, high, steps=10_000):

with self.assertRaises(StatisticsError):
kde([], h=1.0) # Empty dataset
f_hat = kde(['abc', 'def'], 1.5) # Non-numeric data
with self.assertRaises(TypeError):
f_hat(0)
kde(['abc', 'def'], 1.5) # Non-numeric data
with self.assertRaises(StatisticsError):
kde(sample, h=0.0) # Zero bandwidth
with self.assertRaises(StatisticsError):
Expand All@@ -2395,6 +2394,14 @@ def integrate(func, low, high, steps=10_000):
with self.assertRaises(ValueError):
kde(sample, h=1.0, kernel='bogus') # Invalid kernel

# Test name and docstring
h = 1.5
kernel = 'cosine'
f_hat = kde(sample, h, kernel)
self.assertEqual(f_hat.__name__, 'pdf')
self.assertIn(kernel, f_hat.__doc__)
self.assertIn(str(h), f_hat.__doc__)


class TestQuantiles(unittest.TestCase):

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp