Skip to Content
Python机器学习基础教程
book

Python机器学习基础教程

by Andreas C. Müller, Sarah Guido
January 2018
Intermediate to advanced
301 pages
8h 54m
Chinese
Posts & Telecom Press
Content preview from Python机器学习基础教程
54
2
这里我们有
4
个数据点,每个点有
4
个二分类特征。一共有两个类别:
0
1
。对于类别
0
(第
1
3
个数据点),第一个特征有
2
个为零、
0
个不为零,第二个特征有
1
个为零、
1
不为零,以此类推。然后对类别
1
中的数据点计算相同的计数。计算每个类别中的非零元
素个数,大体上看起来像这样:
In[55]:
counts = {}
for label in np.unique(y):
# 对每个类别进行遍历
# 计算(求和)每个特征中1的个数
counts[label] = X[y == label].sum(axis=0)
print("Feature counts:\n{}".format(counts))
Out[55]:
Feature counts:
{0: array([0, 1, 0, 2]), 1: array([2, 0, 2, 1])}
另外两种朴素贝叶斯模型(MultinomialNB GaussianNB)计算的统计数据类型略有不同。
MultinomialNB 计算每个类别中每个特征的平均值,而 GaussianNB 会保存每个类别中每个
特征的平均值和标准差。
要想做出预测,需要将数据点与每个类别的统计数据进行比较,并将最匹配的类别作为预
测结果。有趣的是,MultinomialNB BernoulliNB 预测公式的形式都与线性模型完全相同
(见
2.3.3
节)。不幸的是,朴素贝叶斯模型 coef_ 的含义与线性模型稍有不同,因为 coef_
不同于
w
优点
缺点和参数 ...
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

数据驱动力:企业数据分析实战

数据驱动力:企业数据分析实战

Carl Anderson
Python应用开发指南

Python应用开发指南

Posts & Telecom Press, Ninad Sathaye
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey

Publisher Resources

ISBN: 9787115475619