获取 scipy.stats 分布的参数名称 [英] Getting the parameter names of scipy.stats distributions

查看:70
本文介绍了获取 scipy.stats 分布的参数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本来使用 scipy.stats 在数据集上找到最合适的分布.我首先有一个分发名称列表,我对其进行迭代:

dists = ['alpha', 'anglit', 'arcsine', 'beta', 'betaprime', 'bradford', 'norm']对于在 dist 中的 d:dist = getattr(scipy.stats, d)ps = dist.fit(selected_data)errors.loc[d,['D-Value','P-Value']] = kstest(selected.tolist(), d, args=ps)errors.loc[d,'Params'] = ps

现在,在此循环之后,我选择最小 D 值以获得最佳拟合分布.现在,每个分布都在 ps 中返回一组特定的参数,每个参数都有它们的名称等等(例如,对于alpha",它将是 alpha,而对于norm",它们将是 mean 和 std).

有没有办法在 scipy.stats 中获取估计参数的名称?

提前致谢

解决方案

这段代码演示了ev-br 给出他的回答,以防其他人来到这里.

<预><代码>>>>来自 scipy 导入统计>>>diss = ['alpha', 'anglit', 'arcsine', 'beta', 'betaprime', 'bradford', 'norm']>>>对于 d 在 diss... dist = getattr(scipy.stats, d)... dist.name, dist.shapes...('阿尔法', 'a')('anglit', 无)('反正弦',无)('beta', 'a, b')('betaprime', 'a, b')('布拉德福德','c')('规范',无)

我要指出的是,shapes 参数会为分布(例如按位置和尺度参数化的正态分布)生成 None 值.

I am writing a script to find the best-fitting distribution over a dataset using scipy.stats. I first have a list of distribution names, over which I iterate:

dists = ['alpha', 'anglit', 'arcsine', 'beta', 'betaprime', 'bradford', 'norm']
for d in dists:
    dist = getattr(scipy.stats, d)
    ps = dist.fit(selected_data)
    errors.loc[d,['D-Value','P-Value']] = kstest(selected.tolist(), d, args=ps)
    errors.loc[d,'Params'] = ps

Now, after this loop, I select the minimum D-Value in order to get the best fitting distribution. Now, each distribution returns a specific set of parameters in ps, each with their names and so on (for instance, for 'alpha' it would be alpha, whereas for 'norm' they would be mean and std).

Is there a way to get the names of the estimated parameters in scipy.stats?

Thank you in advance

解决方案

This code demonstrates the information that ev-br gave in his answer in case anyone else lands here.

>>> from scipy import stats
>>> dists = ['alpha', 'anglit', 'arcsine', 'beta', 'betaprime', 'bradford', 'norm']
>>> for d in dists:
...     dist = getattr(scipy.stats, d)
...     dist.name, dist.shapes
... 
('alpha', 'a')
('anglit', None)
('arcsine', None)
('beta', 'a, b')
('betaprime', 'a, b')
('bradford', 'c')
('norm', None)

I would point out that the shapes parameter yields a value of None for distributions such as the normal which are parameterised by location and scale.

这篇关于获取 scipy.stats 分布的参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆