objective_scale_from_costs#

empulse.metrics.objective_scale_from_costs(y_true, tp_benefit, tn_benefit, fp_cost, fn_cost)[source]#

Compute the natural magnitude of a cost matrix’s per-sample training signal.

This is the mean absolute derivative of the expected cost with respect to the predicted probability, mean_i |c1_i - c2_i|, where c1 is the cost of predicting positive and c2 the cost of predicting negative. It is what the elastic-net penalty is scaled against, so that a given C selects the same model whether costs are expressed in euros or in cents.

The same quantity is the right scale for all three logit strategies: it is exactly Cost’s per-sample gradient factor, it is LogCost’s gradient magnitude at s = 0.5 up to a factor of two (and equals 1.0 for plain log loss, so C then means what it means in scikit-learn’s LogisticRegression), and for MaxProfit it equals |coeff_tpr| + |coeff_fpr|.

Parameters:
y_truendarray

Binary labels, recoded to 0/1.

tp_benefitfloat or ndarray

Benefit of true positives (the negation of their cost).

tn_benefitfloat or ndarray

Benefit of true negatives (the negation of their cost).

fp_costfloat or ndarray

Cost of false positives.

fn_costfloat or ndarray

Cost of false negatives.

Returns:
scalefloat

A strictly positive, finite scale. Falls back to 1.0 when the cost matrix carries no training signal at all, so that the penalty never collapses to zero or NaN; empulse.metrics.metric.strategies._training_signal.warn_if_no_training_signal is what reports that case, from the objectives that actually differentiate the cost matrix.