Time Series data is a type of data that changes over a period of time and can be represented over a timeline. Data related to stocks, depreciation of machinery, insurance premium, etc. can be considered as Time series data as it tends to change from time to time. Time series is a part of our everyday life.
Times series forecasting is a process where we try to forecast/predict what will be the future values of the time series data by studying the historical data. There are a number of models that are used to predict the time series data some of them are ARIMA, GARCH, Prophet, etc. All these models have a certain definition and the parameters are different for them.
Atspy provides a way of automating the process of Time Series Forecasting and that too in just a single line of code. Atspy contains a variety of Models such as HWAAS, HWAMS, ARIMA, Prophet, etc. which can be used to predict time series data and we can also compare the results of these models.
In this article, we will explore how we can use Atspy for automating time series forecasting and compare different models which are there in Atspy.
Implementation:
We will start by installing atspy using pip install atspy
- Importing Required Libraries
We will be loading the data using pandas so we need to import pandas and we will import different functions from atspy as and when required.
import pandas as pd
- Loading the dataset
For using atspy we need data that is strictly preprocessed i.e. there should be no missing data and no period should be missed. I have created a fake dataset which contains the closing sales of a company with the respective month. Let us load the dataset and convert it to set the date column as the index. We need to make sure that our data contains only 1 target column as supported by atspy.
import pandas as pd
df = pd.read_csv("atspy.csv")
df.Date = pd.to_datetime(df.Date) #changing datatype to datetime
df = df.set_index("Date") #Setting date as index
df.head()
- Selecting Models to be used
In this step, we will import the AutomatedModel() function and define a list of Models that we will feed our data to with their names.
from atspy import AutomatedModel
model_list = ["ARIMA", "Prophet"]
mdl = AutomatedModel(df = df , model_list=model_list, forecast_len=25 )
- Insample Model and Prediction
Now we will call the forecaste_insample function which returns the forecast on the insample data and the performance.
forecast_in, performance = mdl.forecast_insample()
Here you can see that itself splits the training and testing data, after that it runs all the models we mentioned in the list defined above for training and forecasting. Now let us print the forecasting and the performance.
forecast_in
performance
- Outsample Model and Prediction
Similar to insample prediction now we will use outsample prediction which returns the out-of-sample forecasted dataframe.
forecast_out = mdl.forecast_outsample()
forecast_out
performance
Here we created a model using ARIMA and Prophet. We can use a lot more models that are defined in atspy and compare the performance of these models.
Conclusion:
In this article, we saw how easily we can create models using atspy and compare different models. Atspy is simple and creates models in just a single line of code, which is really timesaving and efficient in terms of prediction. We can create different model predictions in a single line by defining the model list. Currently, Atspy supports around 8 to 10-time series prediction models.