A 90-day sales forecast with confidence intervals using Meta's Prophet library, applied to a real retail dataset.
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
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.
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.
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.
Spotted a bug, broken code, or something that doesn't look right? Tell us what's off and we'll fix it.