未解决:画图那里有问题
####参数定义
#全部数据ALL
#假设模型在ALL上的错误率为
e_all = 0.3
#测试集T
#T样本量 m=10
m_T = 10
#模型在T上面判断错误的数量 m'=6
m_T_error = 6
#模型在T上的错误率
e = round(m_T_error/m_T,4) #6/10,取四位小数
###二项分布
#出现这种情况的概率
from scipy.special import comb
def calculate_p(m_T,m_T_error): #comb排列组合计算
p = (comb(m_T, m_T_error)) *(e_all**m_T_error)*((1-e_all)**(m_T-m_T_error))
p =round(p,4)
return p
print(calculate_p(m_T, m_T_error)) #错6个的概率是0.0368
#0.0368
m_T_errors = m_T_errors = list(range(m_T + 1))
#出现每个情况的概率
def calculate_ps(m_T):
ps = []
for i in range(len(m_T_errors)):
m_T_error = m_T_errors[i]
p = calculate_p(m_T, m_T_error)
ps.append(p)
return m_T_errors,ps
ps = calculate_ps(m_T)
print(m_T_errors,ps)
#[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
#([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
#[0.0282, 0.1211, 0.2335, 0.2668, 0.2001, 0.1029, 0.0368, 0.009, 0.0014, 0.0001, 0.0])
#画出分布图像
import matplotlib.pyplot as plt
def plot_scatter(x,y):
plt.scatter(x, y, s =20,c='b',alpha = 0.5)#s为size,按每个点的坐标绘制,alpha为透明度
plt.show()
return
plot_scatter(m_T_errors,ps)