expected_log_cost_loss#
- empulse.metrics.expected_log_cost_loss#
Expected log cost of a classifier.
A generic
Metricbuilt from theLogCoststrategy on a plain cost matrix, accepting class- or instance-dependenttp_cost,tn_cost,fp_cost, andfn_costparameters. Whentp_costandtn_costequal -1, andfp_costandfn_costequal 0, the expected log cost is equivalent to the log losssklearn.metrics.log_loss.See also
expected_cost_loss: Expected cost of a classifier.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 log 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 log 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 log cost.
Examples
import numpy as np from empulse.metrics import expected_log_cost_loss y_proba = [0.1, 0.9, 0.8, 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_log_cost_loss(y_true, y_proba, fp_cost=fp_cost, fn_cost=fn_cost)