是否可以计算Sklearn中线性和多项式回归模型的置信区间?

发布于 2025-02-11 17:12:59 字数 629 浏览 1 评论 0原文

我正在使用Sklearn -linear和多项式回归模型进行一些基本的预测。我能够使我的模型启动并很快运行以做出预测,但是我也想计算80%的置信区间,以获得上下界限以及预测。

是否有一种简单的方法可以使用内置的Sklearn功能来计算这些数字?

这是我的数据df的样子:

+------------+------+
|    date    | cost |
+------------+------+
| 01/01/2022 |  100 |
| 02/01/2022 |  104 |
| 03/01/2022 |  107 |
| 04/01/2022 |  108 |
| 05/01/2022 |  111 |
| 06/01/2022 |  117 |
| 07/01/2022 |  120 |
| 08/01/2022 |  122 |
| 09/01/2022 |  128 |
| 10/01/2022 |  133 |
+------------+------+

对于这两个模型和接下来的10天,我想计算yhatyhat_lower,和yhat_upper,但我不确定这样做的最佳方法。任何帮助将不胜感激!

I am doing some basic forecasting using the sklearn linear and polynomial regression models. I am able to get my model up and running pretty quickly to make predictions, but I also would like to calculate the 80% confidence intervals to get the upper and lower bounds along with the predictions.

Is there an easy way to calculate those numbers using inbuilt sklearn features?

here is what my data df looks like:

+------------+------+
|    date    | cost |
+------------+------+
| 01/01/2022 |  100 |
| 02/01/2022 |  104 |
| 03/01/2022 |  107 |
| 04/01/2022 |  108 |
| 05/01/2022 |  111 |
| 06/01/2022 |  117 |
| 07/01/2022 |  120 |
| 08/01/2022 |  122 |
| 09/01/2022 |  128 |
| 10/01/2022 |  133 |
+------------+------+

For both models and for the next 10 days for example, I want to calculate yhat, yhat_lower, and yhat_upper, but I am not sure on the best way to do this. Any help would be appreciated!

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

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

发布评论

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

评论(1

稀香 2025-02-18 17:13:00
import numpy as np
import matplotlib.pyplot as plt

# confidence level
confidence = .2

# your predictions
y_pred = np.array([100,104,107,108,111,117,120,122,128,133])

y_l, y_h = y_pred * (1 - confidence), y_pred * (1 + confidence)

fig, ax = plt.subplots()
ax.plot(range(len(y_pred)), y_pred, color="green")
ax.fill_between(range(len(y_pred)), y_l, y_h, color='b', alpha=.1)
plt.show()

import numpy as np
import matplotlib.pyplot as plt

# confidence level
confidence = .2

# your predictions
y_pred = np.array([100,104,107,108,111,117,120,122,128,133])

y_l, y_h = y_pred * (1 - confidence), y_pred * (1 + confidence)

fig, ax = plt.subplots()
ax.plot(range(len(y_pred)), y_pred, color="green")
ax.fill_between(range(len(y_pred)), y_l, y_h, color='b', alpha=.1)
plt.show()

enter image description here

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