whylogs.core.metrics.confusion_matrix

Module Contents

Classes

ConfusionMatrix

Confusion Matrix Class to hold labels and matrix data.

Functions

_merge_CM(old_conf_matrix: ConfusionMatrix, new_conf_matrix: ConfusionMatrix)

Merges two confusion_matrix since distinc or overlaping labels

encode_to_integers(values, uniques)

Attributes

SUPPORTED_TYPES

whylogs.core.metrics.confusion_matrix.SUPPORTED_TYPES = ['binary', 'multiclass']
class whylogs.core.metrics.confusion_matrix.ConfusionMatrix(labels: List[str] = None, prediction_field: str = None, target_field: str = None, score_field: str = None)

Confusion Matrix Class to hold labels and matrix data.

labels

list of labels in a sorted order

prediction_field

name of the prediction field

target_field

name of the target field

score_field

name of the score field

confusion_matrix

Confusion Matrix kept as matrix of NumberTrackers

Type

nd.array

labels

list of labels for the confusion_matrix axes

Type

List[str]

add(self, predictions: List[Union[str, int, bool]], targets: List[Union[str, int, bool]], scores: List[float])

Function adds predictions and targets to confusion matrix with scores.

Parameters
  • predictions (List[Union[str, int, bool]]) –

  • targets (List[Union[str, int, bool]]) –

  • scores (List[float]) –

Raises
  • NotImplementedError – in case targets do not fall into binary or

  • multiclass suport

  • ValueError – incase missing validation or predictions

merge(self, other_cm)

Merge two seperate confusion matrix which may or may not overlap in labels.

Parameters

other_cm (Optional[ConfusionMatrix]) – confusion_matrix to merge with self

Returns

merged confusion_matrix

Return type

ConfusionMatrix

to_protobuf(self)

Convert to protobuf

Returns

Description

Return type

TYPE

classmethod from_protobuf(cls, message: whylogs.proto.ScoreMatrixMessage)
whylogs.core.metrics.confusion_matrix._merge_CM(old_conf_matrix: ConfusionMatrix, new_conf_matrix: ConfusionMatrix)

Merges two confusion_matrix since distinc or overlaping labels

Parameters
whylogs.core.metrics.confusion_matrix.encode_to_integers(values, uniques)