Skip to main content

Prophet of The Future.         

Prophet is open source software released by Facebook’s Core Data Science team. It is available for download on CRAN and PyPI.

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. It works best with time series that have strong seasonal effects and several seasons of historical data. Prophet is robust to missing data and shifts in the trend, and typically handles outliers well.

  1.      Accurate and fast.
  2.      Fully automatic.
  3.      Tunable forecasts.
  4.      Available in R or Python.

Let’s explore this with an example.  Here we are using Air Passenger dataset and our jupyter workbook. (you can get the link to this dataset at the end)

import warnings

warnings.filterwarnings("ignore")

import numpy as np

from datetime import datetime

import pandas as pd

import os

for dirname, _, filenames in os.walk('/kaggle/input'):

    for filename in filenames:

        print(os.path.join(dirname, filename))

 

df = pd.read_csv('..//AirPassengers.csv') 

Installing Prophet using pip and import prophet

!pip install prophet

from prophet import Prophet

df.rename(columns={'Month':'ds','#Passengers':'y'},inplace=True)

df.rename(columns={'Month':'ds','#Passengers':'y'},inplace=True)
 
df.head()



Now we fit the model and instantiating new prophet object. Then you call it fit method and pass in the dataframe.

 

model = Prophet()
model.fit(df)
 

Predictions are then made on a dataframe with a column ds containing the dates for which a prediction is to be made. You can get a suitable dataframe that extends into the future a specified number of months using the helper method Prophet.make_future_dataframe. By default it will also include the dates from the history, so we will see the model fit as well.

 

future = model.make_future_dataframe(periods=0, freq='M')
future.tail()




The model will assign predicted value by the name of yhat. If you pass in historical dates, it will provide an in-sample fit. The forecast object here is a new dataframe that includes a column yhat with the forecast, as well as columns for components and uncertainty intervals.

forecast = model.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()

Now plot the forecast by calling the Prophet.plot method and passing in your forecast dataframe.

fig1 = model.plot(forecast)




fig2 = model.plot_components(forecast)



So, We can see the forecast trend and seasonality with the help of Facebook Prophet library.  That's a wrap for Prophet Library in Jupyter. For more details you can visit https://facebook.github.io/prophet/docs/quick_start.html#python-api. You can download the dataset from kaggle https://www.kaggle.com/rakannimer/air-passengers

Hope you find it useful and informative. Follow my blog for more Data related quests.

-DataDevil

Honey Saini


Comments

  1. That's some good content on Data Science... keep goin :)

    ReplyDelete

Post a Comment

Thank you.

Popular posts from this blog

Future of Real Estate in the US after the Pandemic . Real Estate has always been a fascinating investment topic to be debated by the pandits. Is the time " NOW " or " NEVER " to invest in real estate after so many obstacles have shaken our faiths in it. Well, the United States of America's real estate market doest think so. In fact, the market appears to be steady and ever raising.  A study by CoreInsights has shown that the market for real estate has increased in the top 10 states  namely  California, Hawaii, Washington, Colorado, Utah, Nevada, Oregon, Idaho, Massachusetts & Arizona. To give an example, in Nevada, house prices have more than doubled since 2010 (105.84%), while in Connecticut, the average price has increased by just 1.12% over the same period.   So then, if house prices continue to increase at this rate over the next ten years, how would the average house price look across the nation?  Then when we look at how 2030 prices could look in Ame...
COVID-19 - B e a u t y    a t    a    P r i c e    The global beauty industry (comprising skin care, color cosmetics, hair care, fragrances, and personal care) has been shocked by the COVID-19 crisis. First-quarter sales have been weak, and there have been widespread store closures. But the industry has quickly adapted to the change by changing its product line to hand sanitizers and house cleaning products also offering free beauty services to front line workers to gain positive brand positioning. The global beauty industry generated $50 billion in sale a year and accounted to millions of jobs, directly and indirectly giving people in these tough times financial capabilities. Let’s be clear we are talking about an industry which even recession couldn’t kick to the ground. In 2008 financial crises, the spending fell slightly but it was regained by 2010. Figure 1: Even though  recession didn’t had stronger economic impact compared to COVID-19....