attribute
logger
Pythonlogger = logging.getLogger(__name__)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 |
loggerattributecompute_metricsfunctionCompute set of metrics for ytrue and ypred.confusion_matrixfunctionCompute confusion matrix using keras w/ addition to normalize.logger = logging.getLogger(__name__)Compute set of metrics for ytrue and ypred.
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
| Name | Type | Default | Description |
|---|---|---|---|
metrics | list[keras.Metric] | Required | List of metrics |
y_true | keras.KerasTensor | Required | True labels |
y_pred | keras.KerasTensor | Required | Predicted labels |
Returns
| Value | Type | Description |
|---|---|---|
dict | dict[str, float] | Dictionary of metric names and values |
Compute confusion matrix using keras w/ addition to normalize.
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.KerasTensorCompute 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 = 2cm = helia.metrics.confusion_matrix(labels, predictions, num_classes, normalize='true')print(cm)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
labels | keras.KerasTensor | Required | True labels |
predictions | keras.KerasTensor | Required | Predicted labels |
num_classes | int | Required | Number of classes |
weights | keras.KerasTensor | None | Weights. Defaults to None. |
dtype | str | 'int32' | Data type. Defaults to "int32". |
normalize | Literal['true', 'pred', 'all'] | None | Normalization mode. Defaults to None. |
Returns
| Type | Description |
|---|---|
keras.KerasTensor | keras.KerasTensor: Confusion matrix |