import pandas as pd
import numpy as np
import holidays
import matplotlib.pyplot as plt
import statsmodels.api as sm
from datetime import datetime, timedelta
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
from sklearn.metrics import mean_absolute_error
np.random.seed(0)
start_date = datetime(2022, 1, 1)
end_date = start_date + timedelta(days=730)
dates = pd.date_range(start_date, end_date, freq='MS')
sales = np.random.randint(50, 200, size=len(dates))
sales_data = pd.DataFrame({'Date': dates, 'Sales': sales})
sales_data.index = sales_data['Date']
sales_data = sales_data.drop(['Date'], axis=1)
sales_data['Month'] = sales_data.index.month
sales_data['Quarter'] = sales_data.index.quarter
sales_data['Lag1'] = sales_data['Sales'].shift(1)
sales_data['Lag3'] = sales_data['Sales'].shift(3)
sales_data['Lag6'] = sales_data['Sales'].shift(6)
sales_data['Rolling_Mean_2'] = sales_data['Sales'].rolling(window=2).mean()
sales_data['Rolling_Mean_3'] = sales_data['Sales'].rolling(window=3).mean()
sales_data['Rolling_Mean_6'] = sales_data['Sales'].rolling(window=6).mean()
sales_data = sales_data.dropna()
I am trying to learn time series modeling. This is my code with dummy data. Now I want to train this data using traditional models like linear regression, random forest, and gradient boost. So, now how can we train the model that will predict 90 days from the date the model was run?
For example, right now minimum date in this dataset is 2022-07-01
and the maximum date is 2024-01-01
.
So, how can we prepare a dataset that will train the machine learning model for 90 days/3 months of forecasting? Even when the model is run on 2024-04-01
, we should know or be confident that the prediction that it made was for 2024-07-01
.
And I am trying to learn single forecasting that will be made for 2024-07-01
instead of multiple stepwise forecasting.