OptimaAI Logo

Models

Revenue, churn, growth and Prophet model documentation

Models

OptimaAi trains four models per run. Each is tailored to a specific business question.


Revenue Regressor

Algorithm: XGBoost / Gradient Boosting Regressor Task: Predict net revenue for a single order line

Target variable: net_revenue (USD)

Key features:

FeatureImportanceDescription
quantity_sold~0.61Units sold — dominant driver
price~0.22Unit price before discount
discount_percent~0.08Discount applied
seasonal_index~0.05Monthly seasonality factor
gross_margin_pct~0.03Margin as a ratio

Evaluation metrics:

MetricBenchmarkWhat it means
MAPE< 10% = excellentMean Absolute Percentage Error
R²> 0.95 = strongVariance explained
MAElower = betterMean Absolute Error in USD
Forecast Bias~0 = idealSigned average error (+ = overforecast)

12-period forecast: The model generates a 12-step revenue projection used in the KPI dashboard chart.


Churn Classifier

Algorithm: XGBoost Classifier Task: Predict whether a customer will churn (binary classification)

Target variable: churned (0 = active, 1 = churned)

Key features:

FeatureImportanceDescription
days_since_last_order~0.45Inactivity signal
churn_risk_score~0.30Pre-computed CRM score
total_orders~0.12Order history volume
avg_days_between_orders~0.08Ordering cadence
avg_order_value~0.05Customer value

Evaluation metrics:

MetricBenchmarkWhat it means
ROC-AUC> 0.8 = strongDiscrimination ability
F1 Score> 0.75 = goodBalance of precision and recall
Churn RateDataset statisticBaseline churn % in training data

Risk classification at inference:

prob = churn_model.predict_proba(features)[0][1]
risk = "high" if prob >= 0.7 else "medium" if prob >= 0.4 else "low"

Growth Regressor

Algorithm: XGBoost / GBM Regressor Task: Predict 3-month forward revenue

Target variable: revenue_growth_3m (USD)

This model uses period-level aggregates (monthly or quarterly) rather than individual orders. It captures macroeconomic trends, new customer acquisition, and order volume changes over time.

Evaluation metrics: MAPE, R²


Prophet (Time-Series)

Algorithm: Facebook Prophet Task: Univariate time-series revenue forecasting

Prophet is trained on the historical total_revenue time series and produces a probabilistic forecast with trend, weekly, and yearly seasonality components.

It serves as a cross-validation baseline — if the XGBoost growth model and Prophet agree on the forecast direction, confidence is higher.

Evaluation metric: MAPE on the holdout period

Output: 12-month forecast used alongside the growth model in dashboard charts.


Model Loading (Lazy Singleton)

Models are loaded once at first request and kept in memory:

# inference_service.py
_inference = None
 
def get_inference():
    global _inference
    if _inference is None:
        _inference = OptimaAiInferenceV3(artefact_dir=ARTEFACT_DIR)
    return _inference

The artefact directory is scanned for the latest timestamped .pkl files on each initialisation.

On this page