统计学关我什么事?
林骥
共 3556字,需浏览 8分钟
·
2021-01-06 20:26
你好,我是林骥。
# 导入库
from pyecharts import options as opts
from pyecharts.charts import TreeMap
from pyecharts.globals import ThemeType
# 真命天子的概率
a = 0.1
# 无关路人的概率
b = 1 - a
# 送给真命天子的概率
c = 0.425
# 不送真命天子的概率
d = 1 - c
# 送给无关路人的概率
e = 0.22
# 不送无关路人的概率
f = 1 - e
# 定义数据
data = [
{
"value": 100,
"name": "后验概率",
"children": [
{
"value": 100,
"name": "送巧克力",
"children": [
{"value": round(a*c/(a*c+b*e)*100,2), "name": "送给真命天子"},
{"value": round(b*e/(a*c+b*e)*100,2), "name": "送给无关路人"},
],
}
],
},
{
"value": 100,
"name": "先验概率",
"children": [
{
"value": 100,
"name": "条件概率",
"children": [
{"value": round(a*c*100,2), "name": "送给真命天子"},
{"value": round(a*d*100,2), "name": "不送真命天子"},
{"value": round(b*e*100,2), "name": "送给无关路人"},
{"value": round(b*f*100,2), "name": "不送无关路人"},
],
}
],
},
]
# 绘制矩形树图
c = (
TreeMap(init_opts=opts.InitOpts(width='800px', height='800px', theme=ThemeType.LIGHT))
.add("推测送巧克力的女同事的心意",
data,
levels=[
opts.TreeMapLevelsOpts(
treemap_itemstyle_opts=opts.TreeMapItemStyleOpts(
border_color="#00589F", border_width=4, gap_width=4
)
),
opts.TreeMapLevelsOpts(
color_saturation=[0.3, 0.5],
treemap_itemstyle_opts=opts.TreeMapItemStyleOpts(
border_color_saturation=0.7, gap_width=2, border_width=2
),
),
opts.TreeMapLevelsOpts(
color_saturation=[0.3, 0.5],
treemap_itemstyle_opts=opts.TreeMapItemStyleOpts(
border_color_saturation=0.6, gap_width=1
),
),
opts.TreeMapLevelsOpts(color_saturation=[0.3, 0.5]),
],
)
.set_global_opts(title_opts=opts.TitleOpts(
title="推测送巧克力的女同事的心意,她把你当成真命天子的概率是"+'%.2f%%' % (a*c/(a*c+b*e)*100),
pos_left="center", pos_top="30",
))
.render("推测送巧克力的女同事的心意.html")
)
微软之所以在激烈的市场竞争中胜出,正是由于采用了贝叶斯统计。
我的 2020 年终总结
☟分享 ☟收藏 ? ☟点赞 ☟在看
评论