Multivariate Time Series Forecasting using FBProphet

Soubhik Khankary
4 min readJan 30, 2022

Hello Everyone, Hope you all are doing good. Today I have come up with a post which would help us to do multivariate variable time series forecasting using FBProphet. It is an extensive library provided by Facebook which would help us to do forecasting for the labelled output based on multiple features. The process is quite easy and I guess this post might help you out in creating the model when you try to do so for your personal project.

Let’s start the coding stuff by importing the basic modules.

Basic modules imported

Let’s try to visualize the dataset along with the column names and explain you the scenario. In the dataset below, we are trying to predict the Open prices for Stock which not only depends on the previous values of itself but there are other features which influences it quite well. In the below case columns like High, Low and Close are playing an important role in determining the same.

Data Training Visualization

We also have a similar dataset on which we would test our model and try to predict the forecasted values.

Visualization of test Dataset

Verify whether all the columns are having the datatypes that is desired before applying the FBProphet model.

Training set Datatypes
Testing set datatypes

Let’s try to visualize the dataset for all individual columns w.r.t dates using our bare eyes and intelligence ;-). We are trying to identify trends, seasonality and pattern for the same.

I was able to make sure using exploratory data analysis that Stock Open price is dependent or having the save trend as that of High price and Low price features. Though the Closing stock feature trend seems to be quite different when compared to Open price. Before applying the model be sure to transform the date column name to ‘ds’ and column name to be predicted to ‘y’. Rest all could remain as it is. If you are having any doubt please refer to the below link where I have tried using FBProphet for univariate time series problem. It will be easy for you to understand.

LINK: https://medium.com/mlearning-ai/univariate-time-series-forecasting-using-fbprophet-ad9ad68e59bc

Renamed Columns

Let us try to create an instance of FBProphet model and try to fit our training dataset. In this case it is slightly varying from univariate time series where we have not used add_regressor functions. We are trying to use multiple features to determine our labelled output(‘Open’).

NOTE: If you are not sure about seasonality please don’t mention anything because FBProphet is intelligent enough to do so.

Parameters for my model

Let’s try to create another test data frame where I could remove the actual values for Open. It will help us to predict the desired output.

Trying to predict the ‘Open’ value for my test dataset.

yhat-Forecasted Open Value

Let’s try to keep forecasted and actual values side by side and then try to see the difference between them visually. If you want to compare the same with other models you could always use the metrics like MAE, MSE & RMSE.

As I already have the actual values I will try to compare them with forecasted values. Here is the thing tantaataaa!!!!

y-Actual_value, y_hat — Forecasted value

Final Visualisation:

I feel this model has worked so well and it was far better than Recurrent neural Network and Arima model as well. In that case I feel the RNN could be trained in a much more better way. I would request you to play more with the hyper parameter tuning on LSTM models which in turn could help you with bright results.

Thank You !!! If you have any concerns please do post a comment. It would not only help me improve and rectify but I will also be able to build my models in better way. Thanks Again!!!

--

--

Soubhik Khankary

Data Engineer by job , Teaching computers by stats and love to learn never endless math.