gpt4 book ai didi

Python 将分布拟合为钟形曲线

转载 作者:行者123 更新时间:2023-12-01 03:05:07 24 4
gpt4 key购买 nike

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

例如,我的发行版如下:

enter image description here

请注意,分布有些偏斜,并且不完全标准/形状像钟形曲线。

这与我希望的分布接近:

enter image description here

注意:这也不是完美的分布,只是更接近

注意:我并不是试图标准化这些值,只是拟合分布。请注意,目标分布未标准化。

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

最佳答案

您可能会考虑的一个工具是 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

关于Python 将分布拟合为钟形曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43506980/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com