Weather Forecast using Deep Learning Model Prophet

Muskaan Pirani
Geek Culture
Published in
3 min readMay 13, 2021

How many times have you tried to predict the sales, the weather, or the stocks with good accuracy? Often times we may find a good Neural model yet we fail to tune its hyper-parameters. Here’s where the deep learning model, PROPHET will be useful for beginners in developing predictive models. Let’s begin!

Prophet

What is Prophet model?

Prophet is estimating methodology executed in R and Python. It is quick and gives totally computerized gauges that can be tuned by hand by information researchers and examination.

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 arrangement that have solid occasional impacts and a few periods of authentic information. Prophet is vigorous to missing information and movements in the pattern, and ordinarily handles anomalies well. Prophet is open source programming delivered by Facebook’s Core Data Science group. It is accessible for download on CRAN and PyPI.

Advantages of Prophet:

1. Accurate and fast

  • Prophet is utilized in numerous applications across Facebook for creating reliable forecasts for planning and goal setting.
  • They’ve discovered it to perform better compared to some other methodology in most of cases.

2. Fully automatic

  • Getting a reasonable forecast on messy data with no manual effort.
  • Prophet is robust to outliers, missing data, and dramatic changes in your time series.

3. Tunable forecast

  • The Prophet procedure includes many possibilities for users to tweak and adjust forecasts.
  • You can use human-interpretable parameters to improve your forecast by adding your domain knowledge.

4. Available in R or Python

  • Use whatever language you’re comfortable with to get forecasts.

Formula

How does prophet equation works?

Breaking down the equation behind Facebook’s open-source Time Series Forecasting procedure.

The method utilizes a decomposable time arrangement model with three primary model segments: trend, seasonality and holidays.

y(t) = g(t) + s(t) + h(t) + e(t)

where:

  • g(t): Trend models non-periodic changes i.e. growth over time
  • s(t): Seasonality presents periodic changes i.e. weekly, monthly, yearly
  • h(t): Ties in effects of holidays
  • e(t): Covers errors not accommodated by the model

Understanding the code:

1. Installing packages:

pip install chart_studio
pip install fbprophet

2. Importing libraries:

import pandas as pd
import numpy as np
import chart_studio.plotly as plotly
import plotly.figure_factory as ff
from plotly import graph_objs as go
from fbprophet import Prophet
from fbprophet.plot import plot_plotly

3. Loading the dataset:

df = pd.read_csv(‘/content/weather_temperature_yilan.csv’)
df.head()

4. Plotting the original data:

fig = go.Figure()fig.add_trace(go.Scatter(x=df.Date, y=df[‘Temperature’], name=”temperature”,line_color=’green’))fig.layout.update(title_text=’Time Series data with Rangeslider’,xaxis_rangeslider_visible=True)fig

5. Dividing dataframe into X and y:

X = df[[‘Date’, ‘Temperature’]]
y = df.iloc[:,1]

6. Loading data into ‘ds’ and ‘y’:

train_df = pd.DataFrame()
train_df[‘ds’] = pd.to_datetime(X[“Date”])
train_df[‘y’]=y
train_df.head(2)

7. Applying and fitting Prophet model:

model = Prophet()
model.fit(train_df)
future = model.make_future_dataframe(periods=365)
future.tail(2)

8. Predicting the data:

forecast = model.predict(future)
fig1 = plot_plotly(model, forecast)
fig1

9. Component wise forecast:

#plot component wise forecast
fig2 = model.plot_components(forecast)

With few lines of code, you can predict very well and also, we predicted it’s trend weekly, monthly and yearly. You can access the code from my GitHub profile: Weather_Forecast

Thanks for reading!

You can reach me on LinkedIn, GitHub and Medium as well.

--

--