In this notebook, we will create an AI and time serie driven forecasting engine based on a set of 5 AI models and 5 time series models and employ several algorithms to perform feature engennering and selection on a multivaraite time series dataset. We are trying to find the best drivers of the HK flat price using various macro economics data.The dataset we are using is the 'HK macroeconomics data' from Kaggle. It is a daily dataset starting from 2nd January 2003 and goes on till 26th November 2019. The target variable is 'Private Domestic (Price Index)' and there 12 features which can help us forecast HK flat price. The dataset can be found here.
We will first do exploratory data analysis on the data and then move on to data cleaning where we do the following:
- Check if any dates are missing and add the missing dates
- Use linear interpolation to fill the nulls (we will also provide the code for forward and backward fill
- Perform outlier detection
- Perform outlier treatment
- Check time series components, ACF and PACF plots of target variable
Once the data has been cleaned up, we will create the following additional features:
- 3 lags for each feature
- Daily change for each feature
- A flag for holidays
- Flag for S&P 500 index
- Calculate First hand sales price and drop the sales amount variable
The next step is to perform featue selection using the following techniques:
- Select the top n features based on feature importance from random forest
- Select the top n features based on absolute correlation with target variable
- Select the features identified by Lasso regression
- Select features by recursively considering smaller and smaller sets of features
- Select the top n features based on absolute value of beta coefficients of features
The final features are the ones selected in at least 3 out of 5 models.
After feature selection, we train a set of 10 models (and perform hyper parameter tuning wherever required):
- SARIMA (Univariate Time Series)
- Holt Winters (Univariate Time Series)
- SARIMAX(Multi-variate Time Series)
- VAR(Multi-variate Time Series)
- VECM(Multi-variate Time Series)
- LSTM (Univariate Time Series)
- Random Forest (Multi-variate AI)
- XGBoost (Multi-variate AI)
- Linear Regression (Multi-variate AI)
- SVR (Multi-variate AI)
We make predictions for the next year using all the models and then take their average as the final predictions.