如何找到数据列表的最佳拟合分布函数?

发布于 2024-11-02 23:52:08 字数 159 浏览 3 评论 0原文

我知道 Python 内置了许多概率函数,带有 random 模块。

我想知道,给定一个浮点数列表,是否有可能找到最适合该列表的分布方程?

我不知道 numpy 是否这样做,但这个函数可以与 Excel 的“趋势”函数进行比较(不相等,但相似)。

我该怎么做呢?

I am aware of many probabilistic functions builted-in Python, with the random module.

I'd like to know if, given a list of floats, it would be possible to find the distribution equation that best fits the list?

I don't know if numpy does it, but this function could be compared (not equal, but similar) with the Excel's "Trend" function.

How would I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浅紫色的梦幻 2024-11-09 23:52:08

看看 numpy.polyfit

numpy.polyfit(x, y, deg, rcond=None, full=False)

最小二乘多项式拟合。

将 deg 度数的多项式 p(x) = p[0] * x**deg + ... + p[deg] 拟合到点
(x,y)。返回最小化平方误差的系数 p 向量。

Look at numpy.polyfit

numpy.polyfit(x, y, deg, rcond=None, full=False)

Least squares polynomial fit.

Fit a polynomial p(x) = p[0] * x**deg + ... + p[deg] of degree deg to points
(x, y). Returns a vector of coefficients p that minimises the squared error.

默嘫て 2024-11-09 23:52:08

还有 curve_fit

from scipy.optimize import curve_fit

there's also curve_fit

from scipy.optimize import curve_fit
自由如风 2024-11-09 23:52:08

您可能想尝试 statsmodels.tsa 中的时间序列分析。查看下面的代码:

from statsmodels.tsa.seasonal import seasonal_decompose
decomp = seasonal_decompose(df_train)

trend = decomp.trend
seasonal = decomp.seasonal
residual = decomp.resid

一个警告。我发现季节性部分不能很好地处理异质性——当你的周期函数振幅随时间增长时。它保持周期性幅度恒定(这是季节性的一部分),然后您的残差将显示周期性效应。

You may want to try the time series analysis in statsmodels.tsa. Check out the code below:

from statsmodels.tsa.seasonal import seasonal_decompose
decomp = seasonal_decompose(df_train)

trend = decomp.trend
seasonal = decomp.seasonal
residual = decomp.resid

One caveat. I found the seasonal part not to handle heterostascedy well -- this si when your periodic function amplitude grows with time. It keeps the periodic amplitude constant (that is part of seasonal) and then your residual will show a periodic effect.

女皇必胜 2024-11-09 23:52:08

看看 https:/ 的文档/erdogant.github.io/distfit/pages/html/Plots.html#plot-all-fitted-distributions

通过测试多个分布函数并对最佳模型进行排名,它们正是您所需要的

Take a look at the documentation of https://erdogant.github.io/distfit/pages/html/Plots.html#plot-all-fitted-distributions

They have exactly what you need by testing multiple distribution functions and ranking the best models

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文