Classification Measures#

class ConfusionMatrix(method_name: str, description: str)[source]#

Bases: MeasureEvaluator

Calculate a confusion matrix for a classification model.

This evaluator generates confusion matrices for classification models, providing detailed information about the model’s performance across different classes. The confusion matrix shows the count of true positives, false positives, true negatives, and false negatives for each class.

Parameters:
method_namestr

The name of the evaluator

descriptionstr

The description of the evaluator output

Attributes:
method_namestr

The name of the evaluator

descriptionstr

The description of the evaluator output

servicesServiceBundle or None

The global services bundle

metric_configMetricManager or None

The metric configuration manager

Notes

The confusion matrix is a fundamental tool for evaluating classification model performance. It provides a detailed breakdown of prediction accuracy across all classes, making it easy to identify which classes the model predicts well and which it struggles with.

The evaluator automatically determines the unique labels from the true target values and creates a square matrix where rows represent true classes and columns represent predicted classes.

Examples

Use the confusion matrix evaluator:
>>> from brisk.evaluation.evaluators import registry
>>> evaluator = registry.get("brisk_confusion_matrix")
>>> evaluator.evaluate(model, X, y, "confusion_matrix_results")
evaluate(model: Any, X: ndarray, y: ndarray, filename: str) None[source]#

Generate and save a confusion matrix.

Executes the complete evaluation workflow for generating a confusion matrix. This includes generating predictions, calculating the confusion matrix, and saving the results with metadata.

Parameters:
modelAny

Trained classification model with predict method

Xnp.ndarray

The input features for evaluation

ynp.ndarray

The true target values

filenamestr

The name of the output file (without extension)

Returns:
None

Notes

This method overrides the base evaluate method to provide classification-specific evaluation workflow. It generates predictions using the model and calculates the confusion matrix with appropriate class labels.

The results are saved as JSON with metadata for later analysis and reporting.