ML Models for LTV Prediction: BG/NBD, Early Predictor, and Integration
Marketing budget flows to channels with high CAC, while customer retention drops — a classic scenario when there is no objective LTV assessment. Without an accurate model, you either underpay for valuable customers or overpay for those who will leave in a month. For example, an online store spends 40% of its budget on contextual ads, but the LTV from this channel is 30% lower than from organic traffic. Saving can reach 40% of the marketing budget with proper segmentation.
We solve this with custom ML solutions under a turnkey model: from data collection to integration with CRM and ad platforms. Our ML models for LTV prediction, including early predictors at days 7–30 after registration, achieve MAPE 25–40% and reduce CAC by 20–30%. Our track record includes 50+ implementations for e-commerce and SaaS with revenues from $10M.
How Mathematical Models Predict LTV
Contractual models (SaaS, subscriptions): a customer is either active or churned. The problem breaks down into:
- Churn prediction: probability of leaving each period
- Revenue prediction: payment amount if active
- LTV = Σ P(alive at t) × Expected_Revenue(t) × Discount_Factor(t)
Non-contractual models (e-commerce, retail): the customer does not announce churn. The classic approach is the BG/NBD model (Beta Geometric/Negative Binomial Distribution):
- Frequency model: transaction frequency = NBD
- Dropout model: probability of customer 'death' = Beta-Geometric
- Monetary value model: gamma-gamma model for average order value
The lifetimes library (Python) implements BG/NBD + gamma-gamma out of the box. Data required: customer_id, frequency, recency, T (customer age), monetary_value.
Step-by-Step BG/NBD Implementation
- Prepare data: for each customer, calculate frequency (number of repeat purchases), recency (time from last purchase to end of period), T (time from first purchase to end of period).
- Train the model:
from lifetimes import BetaGeoFitter; bgf = BetaGeoFitter(); bgf.fit(frequency, recency, T).
- Estimate monetary value: use GammaGammaFitter for average order value.
- Predict LTV:
bgf.conditional_expected_number_of_purchases_up_to_time(t) * expected_monetary_value.
Fader, P. S., & Hardie, B. G. S. (2005). "A Note on Deriving the Pareto/NBD Model".
ML Approach: Direct Prediction
An alternative to probabilistic models is direct prediction of 12-month LTV via regression.
Features:
- RFM for first 30/60/90 days after onboarding
- Acquisition channel (paid search, organic, referral)
- Cohort characteristics (season of acquisition)
- Behavioral: feature usage, session depth
- Segment: B2B vs. B2C, geography, company size
Algorithm: LightGBM Regressor with quantile loss for uncertainty. Metric: MAPE on holdout cohort (customers whose onboarding was 12+ months ago). Typical accuracy: MAPE 25–40% for 12-month forecast — sufficient for segmentation but not for precise CAC calculation. LightGBM regressor is 25–40% more accurate than probabilistic models.
Comparison of approaches:
| Criterion |
BG/NBD + gamma-gamma |
ML Regressor |
| Data |
Only transactions |
Any features |
| Interpretability |
High |
Medium (SHAP) |
| Accuracy (MAPE) |
40–60% |
25–40% |
| Flexibility |
Low |
High (early signals, external data) |
Example code for BG/NBD
from lifetimes import BetaGeoFitter
bgf = BetaGeoFitter(penalizer_coef=0.0)
bgf.fit(data['frequency'], data['recency'], data['T'])
Why Early LTV Prediction Matters for Business
A key nuance: predicting LTV within the first 7–30 days after registration, when data is scarce. The early predictor uses:
- Onboarding completion rate
- Number of key actions in the first week (product activation)
- NPS score from the first survey
- Usage depth: number of modules/features
Random Forest with these features can classify 'whales' (high LTV) with Precision 60–70% as early as 7 days after registration. This is twice as fast as the standard approach based on 30-day data. Early segmentation enables Customer Success to focus on the right customers from day one.
Segmentation by LTV
LTV prediction → customer base segmentation:
| Segment |
LTV percentile |
Strategy |
| Champions |
> 90th |
VIP support, reference programs |
| High Potential |
70–90th |
Proactive CS, upsell |
| Core |
30–70th |
Automated nurturing |
| At Risk |
< 30th |
Watchlist, fit assessment |
Segments are reviewed quarterly or upon significant behavioral changes.
Marketing Spend Optimization
The primary use of LTV models is CAC optimization. In paid channels (Google Ads, Meta Ads), predicted LTV is passed as conversion value. Smart Bidding optimizes bids to maximize LTV, shifting budget to channels with the best LTV/CAC ratio. Cohort analysis by month and campaign shows which sources truly bring valuable customers, not just cheap ones. Savings on inefficient channels can reach 40%.
Model Monitoring
LTV is a long-term prediction, making fast validation difficult. Approaches:
- Shortened horizon validation: train on a 24-month cohort, predict 12-month LTV, compare with actuals after 12 months
- Relative ranking accuracy: absolute accuracy is less important than correctly ordering customers by LTV
- Early vs. final LTV correlation: how well 7-day LTV correlates with 12-month actuals
For segmentation, MAPE 30–40% is sufficient — the key is to rank customers correctly. For precise CAC calculation, aim for MAPE <25%.
What's Included
- Data audit (CRM, transactions, behavior)
- Model selection and calibration (BG/NBD, ML, or ensemble)
- Early predictor development
- Integration with CRM and ad platforms (Google Ads, Meta Ads)
- Documentation, dashboards, team training
- Post-deployment support (monitoring, retraining)
Timeline
- BG/NBD + gamma-gamma model from lifetimes: 2–3 weeks
- ML system with early predictor, monitoring, and integration: 10–14 weeks
Cost is calculated individually, based on data volume and integration complexity. Get a consultation — we will evaluate your project and propose a solution. Request LTV model development for your business. Contact us to select the optimal model for your data.
When does a time series forecasting model fail in production?
The CFO requests a quarterly sales forecast. An analyst builds SARIMA on three years of data, achieves MAPE 8.3% on the test set, and deploys. Two months later, the metric in production jumps to 23%. The root cause: the model was trained on pre‑COVID data, tested on a stable period, but production hit a promotion and supply chain disruption. Data leakage plus distribution shift—perfect notebook numbers, a broken forecast in reality. We have seen this pattern dozens of times across retail, fintech, and IoT. Our team has delivered more than 50 forecasting projects over 5+ years.
Incorrect cross-validation. Standard train_test_split for time series creates data leakage: the model sees future values during training. The correct approach is TimeSeriesSplit or walk‑forward validation with an expanding window.
Multiple seasonality. Hourly electricity consumption has three seasonalities: daily (24h), weekly (168h), yearly (8760h). SARIMA handles only one. Prophet can handle multiple but scales poorly to thousands of series.
Missing values and anomalies. A missing sensor reading is information (the sensor turned off), not NaN. Linear interpolation destroys this signal. Proper handling depends on the missingness mechanism.
Cold start. A new SKU in a 50,000‑item assortment has no history, yet a forecast is needed. Standard approaches fail; cross‑learning or feature‑based methods are required.
Why is model selection critical for your data?
Prophet (Meta) – a solid start for business data with clear seasonality and holidays. Fast setup, interpretable, built‑in outlier detection. Fails on irregular patterns and does not scale beyond ~10k series without parallelization.
Gradient boosting on features (LightGBM, XGBoost) – often underestimated. Engineer lags (t‑1, t‑7, t‑28), rolling means, day‑of‑week, holidays. The model trains on all series simultaneously, solving cold start via transfer learning. MAPE in retail often beats neural nets with proper feature engineering.
TFT (Temporal Fusion Transformer) – a transformer designed for interpretable forecasting with covariates. Built‑in variable selection, temporal attention, quantile outputs. Available in pytorch‑forecasting. Requires ~10,000+ records per series for stable training.
PatchTST – splits the series into patches (like ViT for images), capturing local patterns better than classic transformers. Excellent for long‑horizon forecasting (96–720 steps ahead).
N‑HiTS, N‑BEATS – attention‑free neural architectures, faster than TFT, competitive accuracy. N‑BEATS won the M4/M5 benchmarks for tasks without covariates.
| Method |
Covariates |
Scale (series) |
Interpretability |
Complexity |
| Prophet |
Yes (regressors) |
Up to 10k |
High |
Low |
| LightGBM + features |
Yes |
100k+ |
Medium |
Medium |
| TFT |
Yes |
1k–100k |
High |
High |
| PatchTST |
No/limited |
Any |
Low |
Medium |
| N‑HiTS |
No |
Any |
Low |
Low |
How do we deploy TFT in production?
A typical pipeline via pytorch‑forecasting:
training = TimeSeriesDataSet(
data,
time_idx="time_idx",
target="sales",
group_ids=["store", "sku"],
min_encoder_length=max_encoder_length // 2,
max_encoder_length=max_encoder_length, # 120 days
min_prediction_length=1,
max_prediction_length=max_prediction_length, # 28 days
static_categoricals=["store_type", "category"],
time_varying_known_reals=["price", "promo_flag"],
time_varying_unknown_reals=["sales"],
target_normalizer=GroupNormalizer(groups=["store", "sku"], transformation="softplus"),
)
A common mistake: the default target_normalizer (StandardScaler) breaks predictions for series with zero values (no sales on weekends). GroupNormalizer with transformation="softplus" is the correct choice for count data.
Case study: retail demand forecasting
A chain of 120 stores, 8,000 SKUs, 28‑day forecast horizon. The original system: SARIMA per series, MAPE 18.4%, retraining cycle – 6 hours. We replaced it with TFT on PyTorch + pytorch‑forecasting: a single model for all series, MAPE 11.2%, retraining – 40 minutes on an A10G. Feature importance via variable selection revealed that day_before_holiday influences more than the holiday date itself. Annual savings on inference alone exceeded $50,000.
Step‑by‑step configuration
-
Data collection and preparation. Handle missing values (mark NaN, interpolate only for technical failures), aggregate to required frequency, engineer covariates (holidays, promotions, prices).
-
Create
TimeSeriesDataSet. Set group_ids (store + SKU), time index, forecast horizon. Choose target_normalizer based on target distribution.
-
Train a baseline. Prophet or LightGBM first – to understand complexity.
-
Train TFT. Use
TemporalFusionTransformer with loss=QuantileLoss(), tune learning rate and hidden layer sizes.
-
Validate and interpret. Walk‑forward test, analyze variable selection, build attention heatmaps.
How to properly evaluate forecast quality?
RMSE alone is misleading – it over‑penalizes large values. Our standard set:
-
MAPE – interpretable, unstable near zero.
-
sMAPE – symmetric, avoids division by small numbers.
-
MASE (Mean Absolute Scaled Error) – normalized relative to a naive seasonal forecast, ideal for comparing series of different scales.
-
Pinball loss – for probabilistic forecasting, inventory management.
| Metric |
When to use |
Drawback |
| MAPE |
Business reporting, series without zeros |
Unstable for small values |
| sMAPE |
Model comparison |
Asymmetric interpretation |
| MASE |
Multi‑scale series, benchmarks |
Needs seasonal naive baseline |
| Pinball loss |
Probabilistic models |
Multiple values for different quantiles |
We guarantee a model card with these metrics on the validation set and walk‑forward results on at least 6 months of history.
What deliverables do you receive?
- Documentation of chosen architecture and hyperparameter rationale.
- Reproducible training and inference pipeline (Docker + CI/CD + Airflow/Prefect).
- Committed code with unit tests for key components.
- Team training: retraining, output interpretation, deployment of new versions.
- 3 months of post‑delivery support (consultations, bug fixes, fine‑tuning).
The model is deployed via FastAPI or Triton Inference Server. Retraining is scheduled (e.g., weekly) via Airflow with drift validation and automatic rollback if metrics deteriorate.
Process and timeline
We start with EDA: visualization, ADF test, STL decomposition, analysis of missing values and outliers. This takes 2–3 days but often reveals systemic data issues that block forecasting. Then we build a baseline (naive seasonal, Prophet), engineer features for LightGBM, and select a neural architecture if needed. Walk‑forward validation with a realistic horizon. Deployment via API with automatic retraining scheduled via Airflow or Prefect.
Timeline: MVP forecast on one data type – 3–6 weeks. Hierarchical forecasting system with automation – 2–5 months. Cost is calculated individually based on data volume, number of series, and required accuracy.
Our team consists of certified ML engineers (AWS ML Specialty, GCP Professional ML Engineer) with 5+ years on the market and over 50 completed forecasting projects. Contact us for a free analysis of your data – we will assess the task and provide initial recommendations within 1–2 days. Request a consultation to ensure your forecasts work in production, not just in a notebook.