Time Series Forecasting using FbProphet

Time Series Forecasting using FbProphet

Introduction:-

Fbprophet or simply prophet is an open source package developed and released by Facebook's Core Data Science team. It is used for univariate time series forecasting.

Traditional time series model such as ARIMA(Autoregressive Integrated Moving Average) is a temporal dependence model(which places heavy weights to recent data than older data points).ARIMA also requires data to have constant mean and variance with no seasonality. So, if a dataset is not stationary we have to make it stationary before feeding it to ARIMA.

Whereas Prophet is based on an additive model where non-linear trends are fit with yearly, weekly, and daily seasonality, plus yearly holiday effects. Whenever our dataset has strong seasonal effects and several seasons of data, Prophet is a good model to use for forecasting.

Installing FbProphet:-

!pip install fbprophet

from fbprophet import Prophet        


Importing our dataset:-

import pandas as pd
df1 = pd.read_csv('daily-minimum-temperature.csv')
df1.info()        
No alt text provided for this image





This is a dataset for daily temperature for 10 years ranging from year 1981 to 1990.


#Changing Date column from object to datetime

df1.Date?=?pd.to_datetime(df1.Date)        


Next we have to change the name of the of the columns to 'ds' and 'y' as required by the prophet model.

df1.columns=['ds',?'y']
df1.head()        
No alt text provided for this image






Let's look at the plot of our dataset:

plt.figure(figsize=(12,8))
plt.plot(df1.set_index(['ds']))        
No alt text provided for this image


Initializing the model:

#initialize the model
model = Prophet()        


We are keeping the default values of Prophet and then training the data:

model.fit(df1)        
No alt text provided for this image

We can see here, automatically Prophet is disabling the daily seasonality and keeping the weekly and yearly according to the data. We can manually override this if we need to. Let's leave it automatic for now and move on.


# Checking the components used by the model

model.component_modes        
No alt text provided for this image


Let's create the dataset for next 365 future dates and then predict the values for that:

future?=?model.make_future_dataframe(periods=365)
forecast?=?model.predict(future)        


Let's see the projection of our prediction:

fig?=?model.plot(forecast)        
No alt text provided for this image

Let's understand the image above. Prophet is not only showing the prediction data but also the training data. The black dots are the real datapoints from year 1981 to end of 1990, the blue line is the fitted model, and the blue space is the trend projection. From the year 1991 we can see only the blue line and the blue space which is the 365 days prediction.


Let's look at the actual predicted values:

forecast.tail()        
No alt text provided for this image

There are a total of 19 columns in the forecast dataframe ranging from 'ds' to all the model components like weekly seasonality, yearly seasonality etc. and all their lower limits and upper limits.'ythat' is the predicted values.


Lastly, we can also look at the projection for the components of forecast dataframe:

fig?=?model.plot_components(forecast)        
No alt text provided for this image

This is the trend, weekly and yearly seasonality of our dataset considered by our model.


This concludes the guide to FbProphet.


If you have any question or doubt you can ask me on LinkedIn, will be happy to help. For reference I am adding the github link to download my notebook and the dataset if you need it: Link to the repo

Sadam Hussain

PhD in Industrial Economics | Researching Industrial Economic and Sustainability | Interested in Ecological Economics, ESG, and Green Innovation.

1 年

i have price data and i want to put lower and upper bounds on forecasting. how can we deal with it and i have daily price data2021 to 2023 ?

回复
Prajakta Shete

Senior Associate Devops Engineer | 4x GCP Certified | AWS | Hybrid/Multi Cloud | Terraform certified | CKA | Docker | Devops | CICD | Automation | Gitops | Devsecops

2 年

Awesome one Rishabh Singh, Thanks for sharing ??

Anand Deshpande

Co-Founder and CEO at Atgeir Solutions

2 年

Good one Rishabh. Keep sharing

要查看或添加评论,请登录

Rishabh Singh的更多文章

社区洞察

其他会员也浏览了