In this article, I will use the algorithm provided by Facebook, popularly known as Facebook Prophet Model. I will use the Facebook Prophet Model for Daily Births Forecasting using Machine Learning. The Data I will use here is a very famous dataset among the Machine Learning Practitioner known as daily female births in California.
Before getting started with the task of Daily Births Forecasting with Machine Learning, let me introduce to the Facebook Prophet Model, as I will use the Facebook Prophet model in this article.
What is Facebook Prophet Model?
Facebook Prophet is an algorithm developed by Facebook’s Core Data Science team. It is used in the applications of time series forecasting. It is very much used when there is a possibility of seasonal effects. In this article, I will take you through the application of Facebook Prophet model for Daily Births Forecasting with Machine Learning.
Daily Births Forecasting
Let’s get started with the task of daily births forecasting with machine learning by using the Facebook Prophet Model. I will start with this task by importing all the necessary packages that we need for this task:
import pandas as pd import numpy as np import fbprophet from fbprophet.plot import add_changepoints_to_plot import warnings import matplotlib.pyplot as plt
Now, as I have imported all the necessary packages, I will move forward by reading dataset that we need for Daily Births Forecasting:
df = pd.read_csv("daily-total-female-births.csv", parse_dates=['Date'], date_parser=pd.to_datetime) df.columns = ['ds', 'y'] df.head()
ds y 0 1959-01-01 35 1 1959-01-02 32 2 1959-01-03 30 3 1959-01-04 31 4 1959-01-05 44
I have used “ds” and “y” as the names of the columns as it is the preformatted way that we are required to fit our data in the Facebook Prophet Model. So I hope you don’t get confused about this. Now, before using the FB prophet algorithm on our data let’s visualize the data to have a quick look at what we are working with:
plt.plot(df['ds'], df['y']); plt.title('Daily Female Births in 1959')
Now, I will create a Prophet instance to apply the seasonality effects for the task of daily births forecast with Machine Learning:
with warnings.catch_warnings(): warnings.simplefilter("ignore") m = fbprophet.Prophet(yearly_seasonality=True, daily_seasonality=False, changepoint_range=0.9, changepoint_prior_scale=0.5, seasonality_mode='multiplicative') m.fit(df) future = m.make_future_dataframe(periods=50, freq='d') forecast = m.predict(future)
Now, let’s visualize the seasonality effects we got after applying the model:
Now, let’s visualize the predictions made by the Facebook prophet model for daily births prediction:
I hope you liked this article on Daily Births Prediction with Machine Learning by using the Facebook Prophet model. Feel free to ask your valuable questions in the comments section below. You can also follow me on Medium to learn every topic of Machine Learning.