ZKX's LAB

python 正态性检验 Python 如何做t检验

2021-04-26知识13

Python怎么检验数据分布? 我有几百M的数据,数据属于有性别,工资,地域,年龄,工作年限,行业等信息。怎么用Python检验数据到底…

Python 如何做t检验,T检验,亦称tudett检验,主要用于样本含量较小(例如lt30),总体标准差σ未知的正态分布。

Python怎么检验数据分布 import matplotlib.pyplot as pltimport matplotlib.mlab as mlabimport numpy as npimport pydotplusimport csvimport scipy.stats as ssgame=[]#game是一个列表,你自己弄一个自己的数据列表即可x=np.array(game)#x要处理成这个样子:N=30counts,bins=np.histogram(x,bins=N)bin_width=bins[1]-bins[0]total_count=float(sum(counts))f,ax=plt.subplots(1,1)f.suptitle('query_uri')ax.bar(bins[:-1]+bin_width/2.,counts,align='center',width=.85*bin_width)ax.grid('on')def fit_pdf(x,name='lognorm',color='r'):dist=getattr(ss,name)#params=shape,loc,scaledist=ss.gamma#3 paramsparams=dist.fit(x,loc=0)#1-day lag minimum for shippingy=dist.pdf(bins,*params)*total_count*bin_widthsqerror_sum=np.log(sum(ci*(yi-ci)*2.for(ci,yi)in zip(counts,y)))ax.plot(bins,y,color,lw=3,alpha=0.6,label='%s err=3.2f'%(name,sqerror_sum))return ycolors=['r-','g-','r:','g:']for name,color in zip(['exponweib','t','gamma'],colors):#'lognorm','erlang','chi2','weibull_min',分号后面的分布也可以打进去 线条颜色自己加y=。

随机阅读

qrcode
访问手机版