expected_log_cost_loss#

empulse.metrics.expected_log_cost_loss#

Expected log cost of a classifier.

A generic Metric built from the LogCost strategy on a plain cost matrix, accepting class- or instance-dependent tp_cost, tn_cost, fp_cost, and fn_cost parameters. When tp_cost and tn_cost equal -1, and fp_cost and fn_cost equal 0, the expected log cost is equivalent to the log loss sklearn.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)