预测 statsmodel 参数错误

编程入门 行业动态 更新时间:2024-10-28 02:29:43
本文介绍了预测 statsmodel 参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试预测数组的样本外值.Python代码:

I am trying to predict outofsample values for an array. Python code:

import pandas as pd import numpy as np from statsmodels.tsa.arima_model import ARIMA dates = pd.date_range('2012-07-09','2012-07-30') series = [43.,32.,63.,98.,65.,78.,23.,35.,78.,56.,45.,45.,56.,6.,63.,45.,64.,34.,76.,34.,14.,54.] res = pd.Series(series, index=dates) r = ARIMA(res,(1,2,0)) pred = r.predict(start='2012-07-31', end='2012-08-31')

我收到此错误.我看到我给出了两个参数,但编译器返回我给出了 3 个.

I am getting this error.I see I have given two argument but compiler return I have given 3.

Traceback (most recent call last): File "XXXXXXXXX/testfile.py", line 12, in <module> pred = r.predict(start='2012-07-31', end='2012-08-31') TypeError: predict() takes at least 2 arguments (3 given)

请帮忙

推荐答案

ARIMA.predict 的调用签名是

predict(self, params, start=None, end=None, exog=None, dynamic=False)

因此,当您调用 r.predict(start='2012-07-31', end='2012-08-31') 时,self 被绑定到 r,并且值绑定到 start 和 end 但所需的位置参数 params 没有绑定.这就是为什么你得到错误

Thus, when you call r.predict(start='2012-07-31', end='2012-08-31'), self gets bound to r, and values are bound to start and end but the required positional arument params does not get bound. That is why you get the error

TypeError: predict() takes at least 2 arguments (3 given)

不幸的是,错误消息具有误导性.3给定"指的是r、start和end.2 个参数"是指两个必需的参数,self 和 params.问题是没有给出必需的位置参数params.

Unfortunately the error message is misleading. The "3 given" refer to r, start and end. The "2 arguments" refer to the two required arguments, self and params. The problem is that the required positional argument params was not given.

要解决问题,您需要参数.通常你通过拟合找到这些参数:

To fix the problem, you need parameters. Usually you find those parameters by fitting:

r = r.fit()

在调用之前

pred = r.predict(start='2012-07-31', end='2012-08-31')

r.fit() 返回一个 statsmodels.tsa.arima_model.ARIMAResultsWrapper有参数烘焙"所以调用 ARIMAResultWrapper.fit 不需要传递 params.

r.fit() returns a statsmodels.tsa.arima_model.ARIMAResultsWrapper which have the parameters "baked in" so calling ARIMAResultWrapper.fit does not require passing params.

import pandas as pd import numpy as np from statsmodels.tsa.arima_model import ARIMA dates = pd.date_range('2012-07-09','2012-07-30') series = [43.,32.,63.,98.,65.,78.,23.,35.,78.,56.,45.,45.,56.,6.,63.,45.,64.,34.,76.,34.,14.,54.] res = pd.Series(series, index=dates) r = ARIMA(res,(1,2,0)) r = r.fit() pred = r.predict(start='2012-07-31', end='2012-08-31') print(pred)

收益

2012-07-31 -39.067222 2012-08-01 26.902571 2012-08-02 -17.027333 ... 2012-08-29 0.532946 2012-08-30 0.532447 2012-08-31 0.532780 Freq: D, dtype: float64

更多推荐

预测 statsmodel 参数错误

本文发布于:2023-10-17 22:21:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1502243.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   参数   statsmodel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!