weighted_confusion_error()¶
- audmetric.weighted_confusion_error(truth, prediction, weights, labels=None)[source]¶
Weighted confusion error.
Computes the normalized confusion matrix, applies given weights to each cell and sums them up. Weights are expected as positive numbers and will be normalized by the sum of all weights. The higher the weight, the more costly will be the error. A weight of 0 means that the cell is not taken into account for the error, this is usually the case for the diagonal as it holds correctly classified samples.
- Parameters
truth (
Sequence
[Any
]) – ground truth values/classesprediction (
Sequence
[Any
]) – predicted values/classesweights (
Sequence
[Sequence
[Union
[int
,float
]]]) – weights applied to the confusion matrix. Expected as a list of lists in the following form (r=row, c=column):[[w_r0_c0, ..., w_r0_cN], ..., [w_rN_c0, ..., w_rN_cN]]
labels (
Optional
[Sequence
[Any
]]) – included labels in preferred ordering. If no labels are supplied, they will be inferred from and ordered alphabetically.
- Return type
float
- Returns
weighted confusion error
Examples
>>> truth = [0, 1, 2] >>> prediction = [0, 2, 0] >>> # penalize only errors > 1 >>> weights = [[0, 0, 1], [0, 0, 0], [1, 0, 0]] >>> weighted_confusion_error(truth, prediction, weights) 0.5