This project explores a time series using Meta’s Prophet forecasting system in R. Prophet is a library within R that can be used to analyse datasets and forecast time series data.
The purpose of this project is to analyse the dataset nottem using Meta’s Prophet to produce a forecast. Doing this without the help of resources like Prophet would be incredibly complicated, Prophet is incredibly sturdy in the way it is able to deal with missing values and potential outliers that would otherwise have skewed the results.
The particular dataset that I will be using in this project is called nottem, this is a builtin time series dataset in R that contains the average air temperatures at Nottingham Castle in Fahrenheit for 20 years.
This plot shows fluctuations in temperature over time starting from 1920 to 1940, which is the period the air temperature was being observed over. There is no strong trend in either direction.
There is a clear repeating pattern within each year, where the upward spikes represent the heat in the summer and the downward representing the cold in the winter for each year, indicating strong seasonality in the time series.
The Library Prophet requires the time series to be set up as a data frame with the time column called “ds” and the data column called “y”.
## ds y
## 1 1920-01-01 40.6
## 2 1920-02-01 40.8
## 3 1920-03-01 44.4
## 4 1920-04-01 46.7
## 5 1920-05-01 54.1
## 6 1920-06-01 58.5
The “ds” column contains the dates and the “y” column contains the data that has been observed.
The next step is to fit a Prophet model to the prepared data.
## ds
## 1 1920-01-01
## 2 1920-02-01
## 3 1920-03-01
## 4 1920-04-01
## 5 1920-05-01
## 6 1920-06-01
The “make_future_dataframe()” function creates future dates for forecasting. In this project I extended the series by 24 months, allowing the Prophet model to create forecasts for the next two year, and I split it specifically by months to see the variation in the air temperature.
##Generating the forecast
The “predict()” function uses the fitted Prophet model to generate forecasts for all dates in the dataset, including the future periods that were added.
The plot here begins with the historical data that we have already seen in my The Data subsection, and then continues onto to 1942, where we can see that the seasonality that we observed in the initial plot has continued on, and the period between 1940 to 1942 played similarly to the data observed from years 1920 to 1940, hence, the seasonal cycle has been consistent.
The lighter shaded region that hovers on the line represents the uncertainty in the forecasts, the further I extended the forecast to future dates, we would see that uncertainty growing wider to reflect the lack of confidence.
The top plot shows the direction of the nottem data including the forecast I found using Prophet, where the air temperature has remained consistently around 50 degrees Fahrenheit.
The bottom plot shows the yearly seasonal trend, where the air temperature is low during the winter months and then higher during the summer ones.
In this project, I used Meta’s Prophet forecasting model to analyse the monthly air temperature data from Nottingham Castle. The analysis revealed that the time series has a strong year;y seasonality that is likely to continue from the 20 years that were initially observed.
Overall, this project demonstrates Prophet’s success as a forecasting tool.
Thank you for reading through my Analysis.