2017-04-19 79 views
1

我正在研究预测模型。我的模型预测并不总是以标准分布的形式出现。我想转换或拟合分布值,以便分布符合钟形曲线。这就像我想要一种转换函数,将我的分布转换为钟形曲线(不一定是标准化的)。Python适合于钟形曲线的分布

例如,这里是我的分布是这样的:

enter image description here

注意的分布是有点歪斜,而不是完美标准/形如钟形曲线。

这是接近我想要的东西的分布看起来像:

enter image description here

注意:这不是完美的分布或者,只是接近

注:我并不想规范化值,只适合分布。注意目标分布没有被标准化。

我以为我可以使用scipy.normnumpy的东西,但我似乎无法找到我想要的东西。

+0

为适合您的数据正态分布看到[计算器答案](http://stackoverflow.com/questions/20011122/fitting-a-正常分布至1D-数据)。 – qbzenker

+0

我不认为*拟合*是正确的术语,在这里(它表明您想要从数据中确定钟形曲线的参数 - mu和sigma)。这个问题本身听起来更像是你想改变分布。 – kazemakase

回答

1

您可能会考虑的一种工具是Box-Cox transformation。在scipy中的实现是scipy.stats.boxcox

下面是一个例子:

import numpy as np 
from scipy.stats import boxcox, gamma 
import matplotlib.pyplot as plt 


# Generate a random sample that is not from a normal distribution. 
np.random.seed(1234) 
x = gamma.rvs(1.5, size=250) 

# Transform the data. 
y, lam = boxcox(x) 

# Plot the histograms. 
plt.subplot(2, 1, 1) 
plt.hist(x, bins=21, rwidth=0.9) 
plt.title('Histogram of Original Data') 
plt.subplot(2, 1, 2) 
plt.hist(y, bins=21, rwidth=0.9) 
plt.title('Histogram After Box-Cox Transformation\n($\\lambda$ = %.4g)' % lam) 
plt.tight_layout() 
plt.show() 

plot