-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pandas as pd | ||
from statsmodels.tsa.arima.model import ARIMA | ||
import matplotlib.pyplot as plt | ||
|
||
class TimeSeriesForecasting: | ||
def __init__(self, data): | ||
self.data = data | ||
|
||
def fit_model(self, order=(1, 1, 1)): | ||
"""Fit the ARIMA model to the data.""" | ||
self model = ARIMA(self.data, order=order) | ||
self.model_fit = self.model.fit() | ||
|
||
def forecast(self, steps=5): | ||
"""Forecast future values.""" | ||
forecasted_values = self.model_fit.forecast(steps=steps) | ||
return forecasted_values | ||
|
||
def plot_forecast(self, steps=5): | ||
"""Plot the forecasted values along with the original data.""" | ||
forecasted_values = self.forecast(steps) | ||
plt.figure(figsize=(12, 6)) | ||
plt.plot(self.data, label='Historical Data') | ||
plt.plot(range(len(self.data), len(self.data) + steps), forecasted_values, label='Forecasted Values', color='red') | ||
plt.title('Time Series Forecasting') | ||
plt.xlabel('Time') | ||
plt.ylabel('Values') | ||
plt.legend() | ||
plt.show() |