flightrisk.eval¶
- class flightrisk.eval.metrics.RiskMetrics(auc, pr_auc, brier, ece, decile_lift)[source]¶
Bases:
objectMetrics emitted by the risk track.
- Parameters:
- flightrisk.eval.metrics.expected_calibration_error(y_true, y_prob, *, n_bins=20)[source]¶
Compute the expected calibration error with equal-width probability bins.
- Parameters:
- Returns:
ECE in
[0, 1].- Raises:
ValueError – If shapes mismatch or
n_bins < 1.- Return type:
- flightrisk.eval.metrics.lift_at_decile(y_true, y_prob, *, decile=1)[source]¶
Compute the lift in the top
decile(1 = top 10%) versus base rate.- Parameters:
- Returns:
Ratio of in-decile churn rate to overall churn rate.
- Raises:
ValueError – If
decilefalls outside[1, 10].- Return type:
- flightrisk.eval.metrics.risk_metrics(y_true, y_prob, *, n_calibration_bins=20)[source]¶
Compute the standard suite of risk metrics in one call.
- Parameters:
- Returns:
A
RiskMetricsbundle.- Return type:
- flightrisk.eval.metrics.calibration_table(y_true, y_prob, *, n_bins=20)[source]¶
Return a per-bin calibration table for plotting reliability diagrams.
- class flightrisk.eval.survival_metrics.SurvivalMetrics(c_index, time_dependent_auc_mean, integrated_brier)[source]¶
Bases:
objectMetrics emitted by the survival track.
- Parameters:
- flightrisk.eval.survival_metrics.survival_metrics(*, train_durations, train_events, test_durations, test_events, risk_scores, survival_at_horizons, horizons)[source]¶
Compute the survival metric suite.
- Parameters:
train_durations (ndarray) – Train follow-up times.
train_events (ndarray) – Train 0/1 event indicators.
test_durations (ndarray) – Test follow-up times.
test_events (ndarray) – Test 0/1 event indicators.
risk_scores (ndarray) – Per-row risk score on test (higher = earlier event).
survival_at_horizons (ndarray) –
(n_samples, len(horizons))matrix of S(t).horizons (ndarray) – 1-D array of horizons matching
survival_at_horizons.
- Returns:
A
SurvivalMetricsbundle.- Return type:
- class flightrisk.eval.uplift_metrics.UpliftMetrics(qini, auuc, uplift_at_k)[source]¶
Bases:
objectMetrics emitted by the uplift track.
- Parameters:
- flightrisk.eval.uplift_metrics.qini_curve(uplift, treatment, outcome)[source]¶
Build the Qini curve in cumulative form.
- flightrisk.eval.uplift_metrics.qini_coefficient(uplift, treatment, outcome)[source]¶
Return the Qini coefficient against the random-targeting baseline.
- flightrisk.eval.uplift_metrics.auuc(uplift, treatment, outcome)[source]¶
Compute the area under the uplift curve.
- flightrisk.eval.uplift_metrics.uplift_at_k(uplift, treatment, outcome, *, k_percent)[source]¶
Estimate the uplift in the top-
k%ranked slice.- Parameters:
- Returns:
Difference between treated outcome rate and control outcome rate within the top slice;
nanif either arm is empty in the slice.- Raises:
ValueError – If
k_percentis outside(0, 100].- Return type:
- flightrisk.eval.uplift_metrics.uplift_metrics(*, uplift, treatment, outcome, k_percentiles=(10, 20, 30))[source]¶
Compute the standard uplift metric suite in one call.
- Parameters:
- Returns:
An
UpliftMetricsbundle.- Return type:
- class flightrisk.eval.simulator.SimulatorConfig(cost_per_treated=5.0, revenue_per_retained=50.0, bootstrap_iters=1000, alpha=0.05, random_state=1337)[source]¶
Bases:
objectConfiguration for the campaign ROI simulator.
- Parameters:
cost_per_treated (float) – Marginal cost of treating one customer.
revenue_per_retained (float) – Revenue captured by retaining one customer.
bootstrap_iters (int) – Number of bootstrap resamples for confidence bands.
alpha (float) – Two-sided significance level for the confidence interval.
random_state (int) – Seed used by the bootstrap resampler.
- class flightrisk.eval.simulator.SimulationResult(budget, n_targeted, expected_retained, expected_revenue, ci_lower, ci_upper, policy)[source]¶
Bases:
objectOutcome of a budgeted targeting policy simulation.
- Parameters:
budget (float) – Budget cap in dollars.
n_targeted (int) – Number of customers actually treated under the policy.
expected_retained (float) – Mean retained customers across bootstrap samples.
expected_revenue (float) – Mean retained revenue net of treatment cost.
ci_lower (float) – Lower bound of the bootstrap CI for revenue.
ci_upper (float) – Upper bound of the bootstrap CI for revenue.
policy (str) – Identifier (
"risk","uplift","random").
- flightrisk.eval.simulator.simulate_risk_policy(*, risk_scores, treatment_lift, base_outcome, budget, config=None)[source]¶
Simulate a top-by-P(churn) campaign at the given
budget.The policy treats the top-
kcustomers byrisk_scoreswherekis determined bybudget / cost_per_treated. Each treated customer’s retention probability is increased bytreatment_lift(clipped to[0, 1 - base_outcome]); each untreated customer is assumed to retain atbase_outcome.- Parameters:
risk_scores (ndarray) – Per-row predicted churn probability (Track A output).
treatment_lift (ndarray) – Per-row uplift in retention if treated (e.g. RCT average lift; can be a constant repeated).
base_outcome (ndarray) – Baseline retention probability per customer.
budget (float) – Total dollars available.
config (SimulatorConfig | None) – Optional simulator configuration.
- Returns:
A
SimulationResultwith bootstrapped CI bands.- Return type:
- flightrisk.eval.simulator.simulate_uplift_policy(*, uplift_scores, treatment_lift, base_outcome, budget, config=None)[source]¶
Simulate a top-by-uplift campaign at the given
budget.The policy treats the top-
kcustomers byuplift_scores(Track C output).- Parameters:
uplift_scores (ndarray) – Per-row uplift estimate.
treatment_lift (ndarray) – Per-row uplift in retention if treated.
base_outcome (ndarray) – Baseline retention probability per customer.
budget (float) – Total dollars available.
config (SimulatorConfig | None) – Optional simulator configuration.
- Returns:
A
SimulationResultwith bootstrapped CI bands.- Return type:
- flightrisk.eval.simulator.simulate_random_policy(*, n, treatment_lift, base_outcome, budget, config=None)[source]¶
Simulate a uniformly random targeting policy at the given
budget.- Parameters:
n (int) – Population size.
treatment_lift (ndarray) – Per-row uplift in retention if treated.
base_outcome (ndarray) – Baseline retention probability per customer.
budget (float) – Total dollars available.
config (SimulatorConfig | None) – Optional simulator configuration.
- Returns:
A
SimulationResultwith bootstrapped CI bands.- Return type:
- flightrisk.eval.simulator.compare_policies(*, risk_scores, uplift_scores, treatment_lift, base_outcome, budgets, config=None)[source]¶
Simulate risk, uplift, and random policies across multiple budgets.
- Parameters:
risk_scores (ndarray) – Per-row Track A scores.
uplift_scores (ndarray) – Per-row Track C scores.
treatment_lift (ndarray) – Per-row retention lift if treated.
base_outcome (ndarray) – Baseline retention probability per customer.
config (SimulatorConfig | None) – Optional simulator configuration.
- Returns:
Tidy frame ready for plotting.
- Return type:
DataFrame
- flightrisk.eval.plots.save_roi_chart(comparison, *, output)[source]¶
Render the headline ROI chart comparing policies across budgets.
- Parameters:
comparison (DataFrame) – Output of
flightrisk.eval.simulator.compare_policies().output (Path) – Destination PNG path.
- Returns:
The path written.
- Return type: