Freedom Sale
Independence Day Special — Unlock the AI Path 70% off our most popular AI course · Limited time offer
--Days
--Hrs
--Min
--Sec
Claim Your Discount
✦ Intermediate ⏱ 45 min

🔮 Build a Sales Forecasting Model with Prophet

🎯 What You'll Build

A 90-day sales forecast with confidence intervals using Meta's Prophet library, applied to a real retail dataset.

📋 What You'll Need

1

Prepare the time series

Prophet expects columns named ds (date) and y (value).

import pandas as pd

df = pd.read_csv('Superstore.csv', encoding='latin-1', parse_dates=['Order Date'])
daily = df.groupby('Order Date')['Sales'].sum().reset_index()
daily.columns = ['ds', 'y']
print(daily.tail())
ds          y
1826  2018-12-30   1238.45
1827  2018-12-31    956.20
2

Fit the model

Prophet automatically detects weekly and yearly seasonality.

from prophet import Prophet

m = Prophet(
    yearly_seasonality=True,
    weekly_seasonality=True,
    daily_seasonality=False,
    changepoint_prior_scale=0.1
)
m.fit(daily)
print("Model fitted.")
Model fitted.
3

Forecast and plot

Predict the next 90 days and plot with uncertainty bands.

future = m.make_future_dataframe(periods=90)
forecast = m.predict(future)

fig = m.plot(forecast)
fig.savefig('sales_forecast.png', dpi=150)
print(forecast[['ds','yhat','yhat_lower','yhat_upper']].tail())

# Component plot (trend + seasonality)
fig2 = m.plot_components(forecast)
fig2.savefig('forecast_components.png', dpi=150)
print("Charts saved.")
ds        yhat  yhat_lower  yhat_upper
1916  2019-03-30   1854.32     1102.11     2623.78
Charts saved.
💡 Tip: Add holiday effects with m.add_country_holidays(country_name="US") — this boosts accuracy on retail data with Black Friday and Christmas spikes.

🎉 You Did It!

You have a production-ready forecasting pipeline. Prophet handles the complex maths so you can focus on business context — swap in any time series you care about.

Found something wrong?

Spotted a bug, broken code, or something that doesn't look right? Tell us what's off and we'll fix it.