我正在使用jupyter笔记本将R中的前一个时间序列分析项目转换为python,我遇到SARIMAX函数和预测问题。我有以下代码:
def cvMSE(ts, order_totry = (0,0,0), seasorder_totry = (0,0,0),
d = 104, num_seas = 5, transformation = 'log'):
"""Computes MSE for a particular choice of transformation for the dataset 'ts'."""
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
return [l[i:(i + n)] for i in range(0, len(l), n)]
len_fold = round(len(q1train_log)/num_seas)
MSE = ['NA' for i in range(num_seas)]; seas = seasorder_totry + (d,)
partitions = chunks(ts, len_fold)
for k in range(len(partitions)):
train_dt, test_dt = pd.concat([partitions[p] for p in range(len(partitions)) if p != k]), partitions[k]
mod = SARIMAX(train_dt, order = order_totry, seasonal_order = seas,
enforce_invertibility=False, enforce_stationarity=False).fit(disp=-1)
fcst = mod.predict(start= len(train_dt), end= len(train_dt) + len_fold, dynamic=True)
if transformation == 'log':
MSE[k] = np.mean(np.array(fcst) - np.array(test_dt))**2 # reverses our previous log transformation
return mean(MSE)
cvMSE(q1train_log,order_totry =(0,0,1),seasorder_totry =(0,0,1))
我正在尝试对其进行交叉验证,每次折叠为104个数据点,为5倍。数据集的长度是525.但是每当我运行它时,我都会收到此错误:
ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
"检查mle_retvals",ConvergenceWarning)
在错误消息的几行之后,最后一行说明:
TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'
有谁知道为什么会这样?我试过切换参数,但我不熟悉。