正太分布函数相关的一些概率程序

 

 

# -*- coding:utf-8 -*-
import numpy as np
import scipy.stats as stats
import matplotlib.pyplot as plt

import sys
reload(sys)
sys.setdefaultencoding('utf8')

#第一步画分布图像
mean = 36.66
std = 5.215

# 根据均值、标准差,求指定范围的正态分布概率值
def normfun(x):
  pdf = stats.norm.cdf(x,mean,std)
  return pdf

X = np.arange(0, int(2*mean), 0.01)
Y= [normfun(x) for x in X]
# 设定 y 轴,载入刚才的正态分布函数

plt.plot(X, Y) # 这里画出理论的正态分布概率曲线
plt.show()

#分别求千分之一 万分之一 十万分之一  百万分之一的特

p= stats.norm.ppf(0.001,mean,std)
str = "qian fenzhiyi: "
print(str,round(p,3))
p= stats.norm.ppf(0.0001,mean,std)
str = "wan fenzhiyi: "
print(str,round(p,3))
p= stats.norm.ppf(0.0001,mean,std)
str = "shiwan fenzhiyi: "
print(str,round(p,3))
p= stats.norm.ppf(0.0001,mean,std)
str = "baiwan fenzhiyi: "
print(str,round(p,3))

#求置信度区间
#65%
conf_intveral = stats.norm.interval(0.65, loc=mean, scale=std)
intveral = [round(x,3)for x in conf_intveral]
print("65%: ",intveral)

conf_intveral = stats.norm.interval(0.95, loc=mean, scale=std)
intveral = [round(x,3)for x in conf_intveral]
print("95%: ",intveral)

conf_intveral = stats.norm.interval(0.99, loc=mean, scale=std)
intveral = [round(x,3)for x in conf_intveral]
print("99%: ",intveral)

conf_intveral = stats.norm.interval(0.999, loc=mean, scale=std)
intveral = [round(x,3)for x in conf_intveral]
print("99.9%: ",intveral)

  

posted @ 2023-02-15 10:57  水木清扬  阅读(28)  评论(0编辑  收藏  举报