Weather Predictions Comparing Facebook Prophet and LSTM
How is the weather there ?

The weather plays an important role in our lives. It influences how we interactive with the environment. Many of our daily routines and way of life are a direct response to the weather. In winter we tend to stay indoors and hibernate, while in summer we spend of our time outside trying cool off. If an intelligent extraterrestrial life were you to make first contact, I think the first question they would ask is how is the weather there?
Predicting the weather is extremely difficult the equations that govern the weather system are fairly complex. There are known as the Lorenz equations. The differential equations have what we call chaos embedded in them. This is the so-called butterfly effect, a small change in the system can have a huge impact on the entire system. We are not going to look at the dynamics of the Lorenz equations, however they were worth mentioning to emphasize the complexity of weather forecasting.
In this blog we are going to predict the weather using Facebook prophet and Long Short Term Memory also known as LSTM. We are going to compare the two frameworks and see which performs better. Our focus will mainly be forecasting the monthly average temperature. We will look at the city of Johannesburg, a South African city located in Gauteng. We will study the historical data from 1857 to 2013.
Exploratory Data Analysis:
Advancements in space technology and aviation has allowed meteorologists to gather atmospheric data faster and more accurately ever than before. They are now able to build sophisticated models that predict the weather to a near perfect precision. Before we build a model of our own to predict the weather are going to do some data analysis and exploration.
One way to study the weather is to look at the different seasons throughout the year. The diagram below shows the variation in temperature on a yearly basis.

We can see that at the beginning of the year the temperature gradient is positive and at a maximum. It starts to decrease around March, from there it falls sharply until it reaches a global minimum around June. The temperature gradient starts to increase around August. It easy to that after September the temperature gradient is on an upward trend and reaches a maximum around December.
The above cyclic trend is characteristic to regions located in the Southern Hemisphere. In the southern hemisphere we experience our summer between December 21 and March 21, while our winter is between June 21 and September 21. This trend was expected since are looking at data from the southern hemisphere. Seasonality is one way to validate time series data.
Another area to study when working with weather data is the climate. To study the climate, we calculate the moving average throughout the years.

We see that the moving average is relatively warm. This is expected South Africa has a warm climate. The gradient of the curve seems to increasing overtime. Does this increase have to do with global warming? Well that’s a question for another day at the moment we only interested in the change of temperature over the years.
Additional information that we can look at, is the summary statistics of the temperature data, but we are not going to study it. The temperature data has been averaged out it has lost most of its key features.
Model:
Weather data is time series, meaning traditional machine learning algorithms won’t be able to handle the rapid changes in temperature over time. Which why we will be using LSTM from keras a deep learning framework and comparing it to Facebook Prophet. Facebook Prophet is a procedure for forecasting time series data based on an additive model where non-linear trends are fit with yearly, weekly, and daily seasonality, plus holiday effects. To read more about Facebook Prophet click on the link,
The weather data is from Kaggle. The data contains average temperatures from different countries around the world. For this blog we are only looking at Johannesburg. The data can be downloaded from this link
Climate Change: Earth Surface Temperature Data
Exploring global temperatures since 1750
www.kaggle.com
Screenprint showing the filtering process from kaggle,

An overview of the data, the following screen-prints displays the importing of the data and shows a view of the temperature data

The data has some missing values where the temperature is not available. To work around that we interpolate the data. Next step is to index the date and isolate the average temperature.
Now we move on to modeling, we begin with LSTM. For the LSTM model we use the 1857 temperature data till 2012 as the training data. The remainder of the temperature data which is the year 2013 we are going use it to validate the prediction. Since we are working with time series data, we have to represent the temperature data in the time space. We achieve this by scaling the data.

LSTM is a deep learning framework; we implement it using the following parameters. We are only using one layer to train the model and one epoch. The temperature data is not abundant hence we are only using a few parameters to avoid overfitting. Our measure for accuracy is the mean squared error and we are using the Adam optimizer. Once have defined those parameters we train the model and make predictions.

The training and predicting on LSTM is done, we now move on to Facebook Prophet.
To use Facebook Prophet, we need to rename our date as ‘dt’ and the average temperature as ‘y’. Then we just call ‘Prophet’. We use the’ fit’ function to train the data and then make forecasts.

Prophet is a statistical model, it makes the training and forecasting relatively easy to config. It removes a lot of complexity and variable defining.
Results:
In this section, we are going to compare results from both models. The two models have different implementations. LSTM requires a number of parameters and definitions to get it started while Prophet is already configured you just need call the model.
LSTM vs Facebook Prophet
For LSTM we have the following plot, it shows the predicted temperature against the real temperature for the year 2013.

The predictions from LSTM are interesting and closely correlated to the real average temperature. Remember for the LSTM model we are only predicting average temperature for 2013. We used the rest of the years prior to 2013 for training.
We could have extended the prediction to years preceding 2013 or even the current year that we are in but we won’t be able to validate the results. The temperature data is not available and to access it you have to pay for it.
Facebook Prophet:
For LSTM we have the following plot, it shows the forecasted temperature against the real temperature. The forecasted results are forward in time, the model forecasted for 3 years into the future. Meaning we have forecasted into 2016.

Facebook Prophet is specifically designed to deal with timeseries data. It for this reason we are able to forecast further into the future with ease. Prophet also offers multiple layers to visualize the temperature data results.

The model produces results similar to LSTM but produces more detail as mentioned above. Prophet is able to decompose the seasons and trend with the associated bounds.
Conclusion:
LSTM performed better than Facebook Prophet. But Facebook Prophet gave us more insights. One advantage about Facebook Prophet it is easy to use and provides more granularity. LSTM only gave us the future value of the temperature while Facebook gave us the seasonality and trend in the data. Depending on the objective or end goal, Facebook Prophet is more suited than LSTM to deal with time series data. Deep learning algorithms tend to be computationally expensive.
You can use access my notebook on GitHub on the following link,
You can contact me on the following platforms,
Twitter :@blessing3ke