Prophet
Meta Prophet
Meta's time-series forecasting library. Automatically handles seasonality and holiday effects.
Meta Prophet
Meta's time-series forecasting library. Automatically handles seasonality and holiday effects.
Prophet is a time series forecasting library that Meta (formerly Facebook) released as open source in 2017. It is specialized for forecasting business time series data (sales, traffic, inventory, etc.) and is designed to be easy to use without a statistics background.
Prophet uses a decomposable time series model. In the form y(t) = g(t) + s(t) + h(t) + e(t), it decomposes a time series into trend, seasonality, holiday effects, and error. Each component is modeled independently, which makes the model highly interpretable.
Its key strength is robustness to missing values, outliers, and trend changes. Real business data often contains gaps and abrupt changes, and Prophet handles these automatically. It can also explicitly model the effects of holidays and events, so the impact of promotions and public holidays can be reflected.
In practice, Prophet is widely used for demand forecasting, capacity planning, and marketing effectiveness analysis. It provides Python and R interfaces, and forecasting and visualization are possible with just a few lines of code. However, deep learning-based alternatives such as NeuralProphet and TimeGPT have recently been attracting attention as well.
from prophet import Prophet
import pandas as pd
import matplotlib.pyplot as plt
# ๋ฐ์ดํฐ ์ค๋น (ds: ๋ ์ง, y: ๊ฐ)
df = pd.DataFrame({
'ds': pd.date_range(start='2023-01-01', periods=365, freq='D'),
'y': [100 + i*0.5 + 20*np.sin(i*2*np.pi/7) + np.random.randn()*5
for i in range(365)]
})
# ๊ธฐ๋ณธ ๋ชจ๋ธ ํ์ต
model = Prophet()
model.fit(df)
# ๋ฏธ๋ ์์ธก (30์ผ)
future = model.make_future_dataframe(periods=30)
forecast = model.predict(future)
# ์์ธก ๊ฒฐ๊ณผ ์๊ฐํ
fig1 = model.plot(forecast)
plt.title('Prophet ์์ธก ๊ฒฐ๊ณผ')
plt.show()
# ์ปดํฌ๋ํธ ๋ถํด ์๊ฐํ (์ถ์ธ, ์ฃผ๊ฐ ๊ณ์ ์ฑ)
fig2 = model.plot_components(forecast)
plt.show()
# === ๊ณ ๊ธ ์ค์ ===
# ํด์ผ ํจ๊ณผ ์ถ๊ฐ (ํ๊ตญ ๊ณตํด์ผ)
korean_holidays = pd.DataFrame({
'holiday': 'korean_holiday',
'ds': pd.to_datetime(['2024-01-01', '2024-02-09', '2024-02-10',
'2024-02-11', '2024-03-01', '2024-05-05',
'2024-05-15', '2024-06-06', '2024-08-15',
'2024-09-16', '2024-09-17', '2024-09-18',
'2024-10-03', '2024-10-09', '2024-12-25']),
'lower_window': 0, # ํด์ผ ์ ์ํฅ ๋ฒ์
'upper_window': 1 # ํด์ผ ํ ์ํฅ ๋ฒ์
})
model_with_holidays = Prophet(holidays=korean_holidays)
model_with_holidays.fit(df)
# ๊ณ์ ์ฑ ์ปค์คํฐ๋ง์ด์ง
model_custom = Prophet(
yearly_seasonality=True,
weekly_seasonality=True,
daily_seasonality=False,
seasonality_mode='multiplicative' # ๊ณฑ์
์ ๊ณ์ ์ฑ
)
# ์ถ๊ฐ ๊ณ์ ์ฑ (์๊ฐ)
model_custom.add_seasonality(
name='monthly',
period=30.5,
fourier_order=5
)
# ์ธ๋ถ ๋ณ์(regressor) ์ถ๊ฐ
df['promotion'] = [1 if i % 7 == 5 else 0 for i in range(365)] # ํ ์์ผ ํ๋ก๋ชจ์
model_with_regressor = Prophet()
model_with_regressor.add_regressor('promotion')
model_with_regressor.fit(df)
# ๋ฏธ๋ ๋ฐ์ดํฐ์๋ regressor ํ์
future_with_promo = model_with_regressor.make_future_dataframe(periods=30)
future_with_promo['promotion'] = [1 if d.weekday() == 5 else 0
for d in future_with_promo['ds']]
forecast = model_with_regressor.predict(future_with_promo)
# ํฌ๋ก์ค ๋ฐธ๋ฆฌ๋ฐ์ด์
from prophet.diagnostics import cross_validation, performance_metrics
cv_results = cross_validation(
model,
initial='180 days', # ์ด๊ธฐ ํ์ต ๊ธฐ๊ฐ
period='30 days', # ์์ธก ๊ฐ๊ฒฉ
horizon='30 days' # ์์ธก ๊ธฐ๊ฐ
)
metrics = performance_metrics(cv_results)
print(f"MAPE: {metrics['mape'].mean():.2%}")
Prophet is a free open-source library. Training and inference times vary depending on data size and settings.
| Item | Typical values | Notes |
|---|---|---|
| License | MIT (free) | Commercial use allowed |
| Training time (1 year of daily data) | 1-5 seconds | Based on the Stan backend |
| Training time (5 years of daily data) | 5-30 seconds | Increases with seasonality complexity |
| Prediction time (1 year ahead) | ~1 second | Includes uncertainty intervals |
| Recommended minimum data | 1-2 years | To learn annual seasonality |
Alternatives compared: NeuralProphet is based on deep learning and is strong on complex patterns, but its training is slow. TimeGPT (Nixtla) is an API-based service starting at $0.99/1000 rows. ARIMA requires complex parameter tuning, but its computation is fast.
"We need to plan server capacity for next quarter, and I've built a traffic forecasting model with Prophet. It reflects holiday effects, so it can also predict the peaks during Seollal and Chuseok. I think we can set a buffer while also looking at the uncertainty intervals."
"What's the difference between Prophet and ARIMA?" - "ARIMA has strict statistical assumptions and complex parameter tuning. Prophet is designed so that non-experts can use it, and it is robust to missing values and outliers. However, for high-frequency data (minute-level) or complex multivariate relationships, deep learning models may be better."
"After I changed Prophet's seasonality_mode to multiplicative, the forecasts got much better. In our sales data, seasonal fluctuations grow in proportion to the overall scale. If a 10% fluctuation at 1 million won in January, then at 5 million won in December it's a 500,000 won fluctuation."
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free
Prophet needs at least 1-2 years of data to learn annual seasonality. If data is insufficient, set yearly_seasonality=False or use a simpler model.
Prophet cannot automatically learn special circumstances such as COVID, competitor events, or policy changes. You need to add such external variables explicitly with add_regressor, or train excluding those periods.
Be sure to validate the model with Prophet's built-in cross_validation function. Check metrics such as MAPE and MAE, and analyze whether errors are large in specific periods. An overfitted model deviates greatly in future predictions.