概率密度函数拟合和假设检验的Python软件包。

distfit的Python项目详细描述


概率密度拟合

PythonPyPI VersionLicenseGithub ForksGitHub Open IssuesProject StatusDownloadsDownloadsSphinxOpen In Colab

Star it if you like it!

背景

distfit是一个python包,用于通过残差平方和(RSS)和假设检验,对89个单变量分布进行概率密度拟合。 概率密度拟合是将概率分布拟合到一系列与重复测量变量现象有关的数据上。distfit根据经验分布对89个不同分布进行评分,并返回最佳得分分布。在

功能

distfit库是用类创建的,以确保使用的简单性。在

^{pr2}$

内容

安装

从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__)

示例

导入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.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java查询,该查询应返回特定相关实体的实体   java创建了两个可运行的JAR,它们使用相同的库而不需要两次   java swing应用程序如何设置面板中组件的高度(和宽度)   在fat jar中找不到java JasperReport文件错误   kotlin在java中如何称呼这个构造函数?   java为什么被零除是一个不可恢复的问题?   java为SUTime添加用于解析季度的自定义规则   java merge 2带所有元素的排序列表   从字符串StringUtils Java中提取数字   java ForLoops最大和最小数   java我可以为嵌入式tomcat 8定义始终保持活动状态的最小executer线程数吗?   java当metod返回ResponseEntry<Resource>抛出错误时,如何返回ModelandView?   java片段翻译和电话定位错误   javagwt:如何让regex(模式和匹配器)在客户端工作   java EAR文件和“WebSphere增强的EAR”之间有什么区别?