Skip to Main Content
Python 机器学习实践:测试驱动的开发方法
book

Python 机器学习实践:测试驱动的开发方法

by Matthew Kirk
January 2018
Intermediate to advanced content levelIntermediate to advanced
211 pages
8h 31m
Chinese
China Machine Press
Content preview from Python 机器学习实践:测试驱动的开发方法
朴素贝叶斯分类
47
a = [1,2,3]
b = [1,4,5]
set(a) | set(b) #=> [1,2,3,4,5]?
最后,给定
B
条件下
A
的概率,在
Python
中如下所示:
a = set([1,2,3])
b = set([1,4,5])
total = 6.0
p_a_cap_b = len(a & b) / total
p_b = len(b) / total
p_a_given_b = p_a_cap_b / p_b #=> 0.33
这个定义的基本意思是:在给定
B
发生的条件下,
A
发生的概率为
A
B
同时发生
的概率除以
B
发生的概率,如图
4-1
所示。
4-1:条件概率如何计算
4-1
显示了如何使用
P
(
A
and
B
)
P
(
B
)
来计算出
P
(
A
|
B
)
在欺诈订单案例中,假设我们想要计算一个订单在使用了礼品卡的情况下是欺诈订单
的概率。计算方法如下:
A B could be called the OR function, as it is both A and B. For instance, in Python
it looks like the following:
a = [1,2,3]
b = [1,4,5]
set(a) | set(b) #=> [1,2,3,4,5]
Finally, the probability of A given B looks as follows in Python:
a = set([1,2,3])
b = set([1,4,5]) ...
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.
Start your free trial

You might also like

Mastering Python for Bioinformatics

Mastering Python for Bioinformatics

Ken Youens-Clark

Publisher Resources

ISBN: 9787111581666