Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saimadhu-polamuri/c9dcaf165445a53198b72379b79df492 to your computer and use it in GitHub Desktop.
Save saimadhu-polamuri/c9dcaf165445a53198b72379b79df492 to your computer and use it in GitHub Desktop.
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