๐Ÿค– AI/ML

Prophet

Meta Prophet

Meta's time-series forecasting library. Automatically handles seasonality and holiday effects.

๐Ÿ“– Detailed Explanation

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.

๐Ÿ’ป Code Example

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%}")

๐Ÿ“Š Performance & Cost

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.

๐Ÿ—ฃ๏ธ Say It Like This in Practice

๐Ÿ’ฌ In a Meeting

"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."

๐Ÿ’ฌ In an Interview

"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."

๐Ÿ’ฌ In a Technical Discussion

"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

โš ๏ธ Common Mistakes & Cautions

โŒ
Using it with insufficient data

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.

โŒ
Ignoring external factors

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.

โœ…
Validate with cross_validation

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.

๐Ÿ”— Related Terms

๐Ÿ“š Learn More