statsmodels.tsa.statespace.sarimax.SARIMAXResults.apply

SARIMAXResults.apply(endog, exog=None, refit=False, fit_kwargs=None, copy_initialization=False, **kwargs)

将拟合的参数应用于与原始数据无关的新数据

使用当前拟合的参数创建一个新的结果对象,应用于一个完全新的数据集,该数据集假设与模型的原始数据无关。然后可以使用新的结果进行分析或预测。

Parameters:
endogarray_like

来自建模时间序列过程的新观测值。

exogarray_like, optional

外生回归变量的新观测值(如适用)。

refitbool, optional

是否使用新数据重新拟合参数。默认是 False(因此使用当前结果对象中的参数来创建新的结果对象)。

copy_initializationbool, optional

是否将当前结果集的初始化复制到新模型中。默认是 False

fit_kwargsdict, optional

传递给 fit 的关键字参数(如果 refit=True)或 filter / smooth

**kwargs

关键字参数可用于在创建新模型对象时修改模型规范参数。

Returns:
results

更新后的结果对象,仅包含新数据集的结果。

注释

此方法的 endog 参数应包含与原始模型的 endog 数据集不一定相关的新观测值。对于那些直接接在原始数据集最后一个元素之后的观测值,请参见 appendextend 方法。

示例

>>> index = pd.period_range(start='2000', periods=2, freq='Y')
>>> original_observations = pd.Series([1.2, 1.5], index=index)
>>> mod = sm.tsa.SARIMAX(original_observations)
>>> res = mod.fit()
>>> print(res.params)
ar.L1     0.9756
sigma2    0.0889
dtype: float64
>>> print(res.fittedvalues)
2000    0.0000
2001    1.1707
Freq: A-DEC, dtype: float64
>>> print(res.forecast(1))
2002    1.4634
Freq: A-DEC, dtype: float64
>>> new_index = pd.period_range(start='1980', periods=3, freq='Y')
>>> new_observations = pd.Series([1.4, 0.3, 1.2], index=new_index)
>>> new_res = res.apply(new_observations)
>>> print(new_res.params)
ar.L1     0.9756
sigma2    0.0889
dtype: float64
>>> print(new_res.fittedvalues)
1980    1.1707
1981    1.3659
1982    0.2927
Freq: A-DEC, dtype: float64
Freq: A-DEC, dtype: float64
>>> print(new_res.forecast(1))
1983    1.1707
Freq: A-DEC, dtype: float64

Last update: Oct 16, 2024