Skip to Content
Python数据科学手册
book

Python数据科学手册

by Jake VanderPlas
January 2018
Intermediate to advanced
470 pages
13h 23m
Chinese
Posts & Telecom Press
Content preview from Python数据科学手册
428
|
第
5
章
5.13.1
 
KDE
的由来
:
直方图
正如前面所讨论过的,密度评估器是一种寻找数据集生成概率分布模型的算法。你可能很
熟悉一维数据的密度估计——直方图,那是一个简单的密度评估器。直方图将数据分成若
干区间,统计落入每个区间内的点的数量,然后用直观的方式将结果可视化。
例如,下面创建两组服从正态分布的数据:
In[2]: def make_data(N, f=0.3, rseed=1):
rand = np.random.RandomState(rseed)
x = rand.randn(N)
x[int(f * N):] += 5
return x
x = make_data(1000)
前面已经介绍过,基于计数的标准直方图可以用
plt.hist()
函数来生成。只要确定直方图
的
normed
参数,就可以得到一个正态分布直方图。在这个直方图中,区间的高度并不反映
统计频次,而是反映概率密度(如图
5-140
所示):
In[3]: hist = plt.hist(x, bins=30, normed=True)
图 5-140:不同正态分布的组合数据
值得注意的是,在区间不变的条件下,这个标准化(计算概率密度)只是简单地改变了
y
轴的比例,相对高度仍然与频次直方图一致。标准化是为了让直方图的总面积等于
1
,可
以通过检查直方图函数的输出结果来确认这一点:
In[4]: density, bins, patches = hist
widths = bins[1:] - bins[:-1] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python数据分析基础

Python数据分析基础

Clinton W. Brownley
精通機器學習

精通機器學習

Aurélien Géron
基于Python的智能文本分析

基于Python的智能文本分析

Benjamin Bengfort, Rebecca Bilbro, Tony Ojeda

Publisher Resources

ISBN: 9787115475893