Created
October 17, 2023 02:37
-
-
Save saimadhu-polamuri/c9dcaf165445a53198b72379b79df492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from statsmodels.tsa.arima.model import ARIMA | |
from sklearn.metrics import mean_squared_error | |
from sklearn.model_selection import train_test_split | |
# Load the data | |
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date']) | |
df = df.set_index('date') | |
# Split the data into training and testing sets | |
train_data, test_data = train_test_split(df, shuffle=False, test_size=0.25) | |
# Build the model | |
model = ARIMA(train_data, order=(2, 1, 2)) | |
model_fit = model.fit() | |
# Predict the test set | |
predictions = model_fit.forecast(steps=len(test_data)) | |
# Evaluate the model using RMSE | |
rmse = np.sqrt(mean_squared_error(test_data, predictions)) | |
print(f'RMSE: {rmse:.2f}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment