arima模型python代码
时间: 2023-07-23 22:00:01 浏览: 85
基于ARIMA模型预测租车业务收入python源码+详细代码注释.zip
Sure! Here's an example of ARIMA model implementation in Python:
```python
import pandas as pd
from statsmodels.tsa.arima.model import ARIMA
# Load the dataset
data = pd.read_csv('data.csv')
# Convert the date column to datetime format
data['Date'] = pd.to_datetime(data['Date'])
data.set_index('Date', inplace=True)
# Split the data into training and testing sets
train_data = data['2000-01-01':'2019-12-31']
test_data = data['2020-01-01':]
# Create and fit the ARIMA model
model = ARIMA(train_data, order=(1, 1, 1))
model_fit = model.fit()
# Make predictions on the test set
predictions = model_fit.predict(start=test_data.index[0], end=test_data.index[-1])
# Print the predicted values
print(predictions)
```
Make sure to replace `'data.csv'` with the path to your own dataset. Also, adjust the date range for the training and testing sets according to your data.
This code uses the `ARIMA` class from the `statsmodels` library to create and fit the ARIMA model. The `order=(1, 1, 1)` parameter specifies the order of the AR, I, and MA components of the model.
The `predict` method is used to make predictions on the test set. Finally, the predicted values are printed.
阅读全文