pip install prophet★PyPI name since v1.0 (wasfbprophet).conda install -c conda-forge prophetOften the smoothest install (bundles the compiler).from prophet import Prophet★The estimator — sklearn-stylefit/predict.from prophet.plot import add_changepoints_to_plotPlot helpers: alsoplot_plotly.from prophet.diagnostics import cross_validationAndperformance_metricsfor evaluation.
df.columns = ['ds', 'y']★The only two columns Prophet requires.df['ds'] = pd.to_datetime(df.ds)★ds= date/timestamp;YYYY-MM-DDor with time.# y must be numericThe measurement to forecast (univariate).df.loc[outliers, 'y'] = NoneSet outliers toNaN— Prophet still fits.df['y'] = np.log(df.y)Log-transform tames exponential growth.
m = Prophet()★Defaults auto-detect yearly/weekly seasonality.m.fit(df)★Fit on history — takes a second or two.future = m.make_future_dataframe(periods=365)★Ads-only frame extended N days ahead.m.make_future_dataframe(24, freq='MS')Month-start / any pandas freq for non-daily data.forecast = m.predict(future)★Fillsyhat+ interval for every row.Prophet().fit(df).predict(future)Chainable — the sklearn one-liner.
forecast['yhat']★The point prediction.yhat_lower · yhat_upper★Uncertainty interval (default 80%).trendTheg(t)trend component.yearly · weekly · dailyEach seasonality's contribution.holidays · <regressor>Event & regressor effects, per column.additive_terms · multiplicative_termsSummed non-trend pieces.forecast[['ds','yhat','yhat_lower','yhat_upper']].tail()The slice you actually report.
m.plot(forecast)★History dots + forecast line + interval band.m.plot_components(forecast)★Trend + each seasonality broken out.add_changepoints_to_plot(fig.gca(), m, forecast)Overlay where the trend bends.from prophet.plot import plot_plotlyInteractive, zoomable version.plot_yearly(m) · plot_weekly(m)Inspect one seasonality alone.
Prophet(seasonality_mode='multiplicative')★When swings grow with the trend (defaultadditive).Prophet(yearly_seasonality=True)'auto'/True/False/ int order.m.add_seasonality(name='monthly', period=30.5, fourier_order=5)★Add a custom cycle (period in days).Prophet(yearly_seasonality=20)Raise Fourier order (default 10 yearly / 3 weekly).Prophet(seasonality_prior_scale=10)Flexibility — lower dampens / smooths.add_seasonality(..., condition_name='is_on')Conditional season — needs a boolean column.# more Fourier terms = overfittingcareN terms ⇒ 2N variables per cycle.
Prophet(changepoint_prior_scale=0.05)★↑ = flexible (overfit) · ↓ = smooth (underfit).Prophet(n_changepoints=25)Candidate points — rarely worth changing.Prophet(changepoint_range=0.8)Place them in the first 80% of history.Prophet(changepoints=['2020-03-01'])Specify bend dates by hand.Prophet(growth='flat')No trend at all — seasonality only.# sparse L1 priorhowMany candidates, few actually used.
Prophet(growth='logistic')★S-curve toward a carrying capacity.df['cap'] = 8.5★Required upper limit — can vary per row.df['floor'] = 0Optional lower saturating bound.# cap on BOTH history & futuremustMissingcapwith logistic ⇒ error.
m.add_country_holidays(country_name='IN')★Built-in sets:US,IN,UK,BR…pd.DataFrame({'holiday':…, 'ds':…})★Custom events need columnsholiday+ds.lower_window · upper_windowSpread the effect ±days around the date.Prophet(holidays=holidays_df)Pass your event frame at construction.from prophet.make_holidays import make_holidays_dfGenerate a frame per country / province.Prophet(holidays_prior_scale=10)Lower it if holiday spikes overfit.
m.add_regressor('temperature')★Fold in a known external variable.# column in fit AND future dfmustProphet won't invent future regressor values.add_regressor('x', mode='multiplicative')Additive (default) or scales with trend.add_regressor('x', standardize='auto')Z-scores unless the column is binary.add_regressor('x', prior_scale=0.5)Regularize the coefficient.regressor_coefficients(m)Inspect the fitted betas.
Prophet(interval_width=0.80)★Default is 80%, not 95% — widen if needed.Prophet(uncertainty_samples=1000)MC draws for the band; set0to skip & speed up.Prophet(mcmc_samples=300)Full Bayes → uncertainty in seasonality too.# band = trend + noisenoteSeasonality is treated as certain unless MCMC.
df_cv = cross_validation(m, horizon='365 days',initial='730 days', period='180 days')performance_metrics(df_cv)★rmse · mae · mape · mdape · smape · coverage.plot_cross_validation_metric(df_cv, metric='mape')Error vs. horizon, rolling-averaged.cross_validation(m, ..., parallel='processes')Fit each cutoff in parallel.# never k-fold a time seriestimeCutoffs move forward — don't shuffle.
changepoint_prior_scale ∈ [.001, .5]★Most impactful — sweep on a log scale.seasonality_prior_scale ∈ [.01, 10]How hard seasonality fits.holidays_prior_scale ∈ [.01, 10]Magnitude of holiday effects.seasonality_mode ∈ {add, mult}Try both when unsure.# grid → cross_validation → min RMSELoop params, evaluate, pick the winner.# usually NOT tunedskipgrowth,changepoints,n_changepoints.
from prophet.serialize import model_to_json★Alsomodel_from_json.json.dump(model_to_json(m), open('m.json','w'))Save the fitted model as JSON.m = model_from_json(open('m.json').read())Reload without refitting.# don't pickle Prophet modelsavoidPickle breaks across versions — use JSON.
growth='linear'linear·logistic·flatchangepoint_prior_scale=0.05Trend flexibility.n_changepoints=25 · changepoint_range=0.8Candidate count & placement.yearly / weekly / daily_seasonality='auto'Enabled by data span & frequency.seasonality_mode='additive'additive·multiplicativeseasonality_prior_scale=10.0Seasonal flexibility.holidays_prior_scale=10.0Holiday magnitude.interval_width=0.80Uncertainty coverage.mcmc_samples=0 · uncertainty_samples=1000MAP by default; >0 ⇒ full Bayes.