Pandas本身并不提供ARIMA模型的实现,但可以使用statsmodels库来进行ARIMA模型的拟合。下面是一个简单的示例代码:
import pandas as pdimport numpy as npimport matplotlib.pyplot as pltfrom statsmodels.tsa.arima.model import ARIMA# 生成时间序列数据np.random.seed(0)data = np.random.randn(100)ts = pd.Series(data, index=pd.date_range('20210101', periods=100))# 拟合ARIMA模型model = ARIMA(ts, order=(1, 1, 1))result = model.fit()# 绘制原始数据和拟合结果plt.figure(figsize=(12, 6))plt.plot(ts, label='Original Data')plt.plot(result.fittedvalues, color='red', label='ARIMA Fit')plt.legend()plt.show()在上面的代码中,我们首先生成了一个随机的时间序列数据,然后使用statsmodels库中的ARIMA模型进行拟合,并将拟合结果和原始数据进行对比绘图展示。您可以根据自己的数据和需求来调整ARIMA模型的参数和拟合方法。


