Skip to content
heliaEDGE
Reference
HELIA

metric_utils

This module provides utility functions to compute metrics for classification tasks.

Functions

Name Description
compute_metrics Compute set of metrics for y_true and y_pred
confusion_matrix Compute confusion matrix using keras w/ addition to normalize

Machine-readable model

function

Compute set of metrics for ytrue and ypred.

helia_edge/metrics/metric_utils.py:21

compute_metrics(metrics: list[keras.Metric], y_true: keras.KerasTensor, y_pred: keras.KerasTensor) -> dict[str, float]

Compute set of metrics for y_true and y_pred.

Example:

import helia_edge as helia
metrics = [keras.metrics.Accuracy('acc'), keras.metrics.Precision(0.5, name='precision')]
y_true = np.array([0, 1, 1, 0])
y_pred = np.array([0, 1, 0, 1])
results = helia.metrics.compute_metrics(metrics, y_true, y_pred)
print(results)
Parameters of compute_metrics
NameTypeDefaultDescription
metricslist[keras.Metric]RequiredList of metrics
y_truekeras.KerasTensorRequiredTrue labels
y_predkeras.KerasTensorRequiredPredicted labels
Returns of compute_metrics
ValueTypeDescription
dictdict[str, float]Dictionary of metric names and values
function

Compute confusion matrix using keras w/ addition to normalize.

helia_edge/metrics/metric_utils.py:55

confusion_matrix(
labels: keras.KerasTensor,
predictions: keras.KerasTensor,
num_classes: int,
weights: keras.KerasTensor | None = None,
dtype: str = 'int32',
normalize: Literal['true', 'pred', 'all'] | None = None,
) -> keras.KerasTensor

Compute confusion matrix using keras w/ addition to normalize.

Example:

import helia_edge as helia
labels = np.array([0, 1, 1, 0])
predictions = np.array([0, 1, 0, 1])
num_classes = 2
cm = helia.metrics.confusion_matrix(labels, predictions, num_classes, normalize='true')
print(cm)
Parameters of confusion_matrix
NameTypeDefaultDescription
labelskeras.KerasTensorRequiredTrue labels
predictionskeras.KerasTensorRequiredPredicted labels
num_classesintRequiredNumber of classes
weightskeras.KerasTensorNoneWeights. Defaults to None.
dtypestr'int32'Data type. Defaults to "int32".
normalizeLiteral['true', 'pred', 'all']NoneNormalization mode. Defaults to None.
Returns of confusion_matrix
TypeDescription
keras.KerasTensorkeras.KerasTensor: Confusion matrix