1 Star 0 Fork 51

花大虫张/Book5_Essentials-of-Probability-and-Statistics

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Bk5_Ch05_07.py 929 Bytes
一键复制 编辑 原始数据 按行查看 历史
Visualize-ML 提交于 2022-11-28 23:58 +08:00 . Add files via upload
###############
# Authored by Weisheng Jiang
# Book 5 | From Basic Arithmetic to Machine Learning
# Published and copyrighted by Tsinghua University Press
# Beijing, China, 2022
###############
from scipy.stats import hypergeom
import matplotlib.pyplot as plt
import numpy as np
N = 50 # total number of animals
K = 15 # number of rabbits among N
n = 20 # number of draws without replacement
hyper_g = hypergeom(N, K, n)
x_array = np.arange(np.maximum(0,n + K - N), np.minimum(K,n) + 1)
pmf_rabbits = hyper_g.pmf(x_array)
fig, ax = plt.subplots()
plt.stem(x_array, pmf_rabbits)
plt.xlabel('x')
plt.ylabel('PMF')
plt.gca().spines['right'].set_visible(False)
plt.gca().spines['top'].set_visible(False)
plt.gca().yaxis.set_ticks_position('left')
plt.gca().xaxis.set_ticks_position('bottom')
plt.xlim(x_array.min(),x_array.max())
plt.ylim(0,pmf_rabbits.max())
plt.xticks([0,5,10,15])
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/hua-da-chong-zhang/Book5_Essentials-of-Probability-and-Statistics.git
git@gitee.com:hua-da-chong-zhang/Book5_Essentials-of-Probability-and-Statistics.git
hua-da-chong-zhang
Book5_Essentials-of-Probability-and-Statistics
Book5_Essentials-of-Probability-and-Statistics
main

搜索帮助