expected_cost_loss#
- empulse.metrics.expected_cost_loss#
Expected cost of a classifier.
A generic
Metricbuilt from theCoststrategy on a plain cost matrix, accepting class- or instance-dependenttp_cost,tn_cost,fp_cost, andfn_costparameters.See also
cost_loss: Cost of a classifier using hard (thresholded) labels.expected_savings_score: Expected savings of a classifier compared to using a baseline.Methods
__call__(y_true, y_proba, *, tp_cost=0.0, tn_cost=0.0, fp_cost=0.0, fn_cost=0.0)Compute the expected cost of a classifier.
optimal_threshold(y_true, y_proba, *, tp_cost=0.0, tn_cost=0.0, fp_cost=0.0, fn_cost=0.0)Compute the classification threshold(s) that minimize(s) the expected cost.
optimal_rate(y_true, y_proba, *, tp_cost=0.0, tn_cost=0.0, fp_cost=0.0, fn_cost=0.0)Compute the predicted positive rate that minimizes the expected cost.
Examples
import numpy as np from empulse.metrics import expected_cost_loss y_proba = [0.2, 0.9, 0.1, 0.2] y_true = [0, 1, 1, 0] fp_cost = np.array([4, 1, 2, 2]) fn_cost = np.array([1, 3, 3, 1]) expected_cost_loss(y_true, y_proba, fp_cost=fp_cost, fn_cost=fn_cost)