【发布时间】:2016-07-27 07:27:40
【问题描述】:
目前,我正在根据 Fitting empirical distribution to theoretical ones with Scipy (Python)? 中解释的理论分布拟合经验分布
使用scipy.stats 分布,结果显示与hyperbolic secant 分布非常吻合。
这是我目前使用一些 scipys 发行版的方法:
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
import scipy.stats
import matplotlib.pyplot as plt
# Sample data with random numbers of hypsecant distribution
data = scipy.stats.hypsecant.rvs(size=8760, loc=1.93, scale=7.19)
# Distributions to check
dist_names = ['gausshyper', 'norm', 'gamma', 'hypsecant']
for dist_name in dist_names:
dist = getattr(scipy.stats, dist_name)
# Fit a distribution to the data
param = dist.fit(data)
# Plot the histogram
plt.hist(data, bins=100, normed=True, alpha=0.8, color='g')
# Plot and save the PDF
xmin, xmax = plt.xlim()
x = np.linspace(xmin, xmax, 100)
p = dist.pdf(x, *param[:-2], loc=param[-2], scale=param[-1])
plt.plot(x, p, 'k', linewidth=2)
title = 'Distribution: ' + dist_name
plt.title(title)
plt.savefig('fit_' + dist_name + '.png')
plt.close()
提供如下图:
但我也想针对(广义的)hyperbolic distribution 测试拟合度,因为我假设它可能会提供更好的拟合度。
我可以使用 scipy.stats 中的双曲线分布吗?或者有什么解决办法?
使用其他软件包也是一种选择。
提前致谢!
【问题讨论】:
-
为什么投反对票?当然有一些关系,但我的问题是关于 scipy.stats 明确。
-
在这里的评论中,有些人问了同样的问题(scipy.stats 中双曲分布的实现)但没有得到答案:stackoverflow.com/questions/24011209/…
-
啊,好吧..我不想创建冗余。但是我现在添加了我的代码和一个情节,以便问题变得更加清晰!
标签: python scipy statistics statsmodels scientific-computing