概率密度函数拟合和假设检验的Python软件包。
distfit的Python项目详细描述
概率密度拟合
Star it if you like it!
背景
distfit
是一个python包,用于通过残差平方和(RSS)和假设检验,对89个单变量分布进行概率密度拟合。
概率密度拟合是将概率分布拟合到一系列与重复测量变量现象有关的数据上。distfit
根据经验分布对89个不同分布进行评分,并返回最佳得分分布。在
功能
distfit
库是用类创建的,以确保使用的简单性。在
内容
安装
从PyPI安装distfit(推荐)。distfit与python3.6+兼容,可以在Linux、macosx和Windows上运行。在
从PyPi安装
pip install distfit
直接从github源安装(beta版)
pip install git+https://github.com/erdogant/distfit#egg=master
通过克隆安装(测试版)
git clone https://github.com/erdogant/distfit.git
cd distfit
pip install -U .
检查版本号
importdistfitprint(distfit.__version__)
示例
pip install distfit
导入distfit
库
fromdistfitimportdistfit
使用默认参数创建一些随机数据和模型:
importnumpyasnpX=np.random.normal(0,2,[100,10])y=[-8,-6,0,1,2,3,4,5,6]
指定distfit
参数。在本例中,没有指定任何内容,这意味着所有参数都设置为默认值。在
dist=distfit()dist.fit_transform(X)dist.plot()# Prints the screen:# [distfit] >fit..# [distfit] >transform..# [distfit] >[norm ] [RSS: 0.0133619] [loc=-0.059 scale=2.031] # [distfit] >[expon ] [RSS: 0.3911576] [loc=-6.213 scale=6.154] # [distfit] >[pareto ] [RSS: 0.6755185] [loc=-7.965 scale=1.752] # [distfit] >[dweibull ] [RSS: 0.0183543] [loc=-0.053 scale=1.726] # [distfit] >[t ] [RSS: 0.0133619] [loc=-0.059 scale=2.031] # [distfit] >[genextreme] [RSS: 0.0115116] [loc=-0.830 scale=1.964] # [distfit] >[gamma ] [RSS: 0.0111372] [loc=-19.843 scale=0.209] # [distfit] >[lognorm ] [RSS: 0.0111236] [loc=-29.689 scale=29.561] # [distfit] >[beta ] [RSS: 0.0113012] [loc=-12.340 scale=41.781] # [distfit] >[uniform ] [RSS: 0.2481737] [loc=-6.213 scale=12.281]
^{1}$ 在
注意,最佳拟合应该是[normal],因为这也是输入数据。 然而,许多其他分布可能与特定的loc/scale参数非常相似。 然而,伽马分布和β分布并不罕见,因为它们是分布中的“barba pappas”。 让我们用残差平方和打印检测到的分布的摘要。在
# All scores of the tested distributionsprint(dist.summary)# Distribution parameters for best fitdist.model# Make plotdist.plot_summary()
在
在我们有了一个拟合模型之后,我们可以利用理论分布进行一些预测。 在做出一些预测之后,我们可以再次绘制,但现在预测会自动包含在内。在
dist.predict(y)dist.plot()# # Prints to screen:# [distfit] >predict..# [distfit] >Multiple test correction..[fdr_bh]
在
预测结果存储在y_proba
和{
# Show the predictions for yprint(dist.y_pred)# ['down' 'down' 'none' 'none' 'none' 'none' 'up' 'up' 'up']# Show the probabilities for y that belong with the predictionsprint(dist.y_proba)# [2.75338375e-05 2.74664877e-03 4.74739680e-01 3.28636879e-01 1.99195071e-01 1.06316132e-01 5.05914722e-02 2.18922761e-02 8.89349927e-03]# All predicted information is also stored in a structured dataframeprint(dist.df)# y y_proba y_pred P# 0 -8 0.000028 down 0.000003# 1 -6 0.002747 down 0.000610# 2 0 0.474740 none 0.474740# 3 1 0.328637 none 0.292122# 4 2 0.199195 none 0.154929# 5 3 0.106316 none 0.070877# 6 4 0.050591 up 0.028106# 7 5 0.021892 up 0.009730# 8 6 0.008893 up 0.002964
示例:如果要测试一个特定的分布,例如正态分布:
dist=distfit(distr='norm')dist.fit_transform(X)# [distfit] >fit..# [distfit] >transform..# [distfit] >[norm] [RSS: 0.0151267] [loc=0.103 scale=2.028]dist.plot()
引文
如果这对你的研究有用,请在你的出版物中引用distfit。以下是BibTeX条目示例:
@misc{erdogant2019distfit,title={distfit},author={Erdogan Taskesen},year={2019},howpublished={\url{https://github.com/erdogant/distfit}},}
维护人员
Erdogan Taskesen, github: [erdogant](https://github.com/erdogant)
Contributions are welcome.
- 项目
标签: