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|, wherec1is the cost of predicting positive andc2the cost of predicting negative. It is what the elastic-net penalty is scaled against, so that a givenCselects 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 isLogCost’s gradient magnitude ats = 0.5up to a factor of two (and equals1.0for plain log loss, soCthen means what it means in scikit-learn’sLogisticRegression), and forMaxProfitit 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.0when the cost matrix carries no training signal at all, so that the penalty never collapses to zero orNaN;empulse.metrics.metric.strategies._training_signal.warn_if_no_training_signalis what reports that case, from the objectives that actually differentiate the cost matrix.