confusion_matrix#
- openstef_beam.metrics.confusion_matrix(y_true: ndarray[tuple[Any, ...], dtype[floating]], y_pred: ndarray[tuple[Any, ...], dtype[floating]], *, limit_pos: float, limit_neg: float) ConfusionMatrix[source]#
Calculate confusion matrix for peak detection in energy load.
A peak is defined as a value that exceeds the positive limit or falls below the negative limit. This function evaluates both the accuracy of peak detection and the effectiveness of predictions based on error direction.
- Parameters:
y_true (ndarray[tuple[Any, ...], dtype[floating]]) – Ground truth energy load values with shape (num_samples,).
y_pred (ndarray[tuple[Any, ...], dtype[floating]]) – Predicted energy load values with shape (num_samples,).
limit_pos (float) – Positive threshold defining high load peaks. Values >= limit_pos are considered positive peaks.
limit_neg (float) – Negative threshold defining low load peaks. Values <= limit_neg are considered negative peaks.
- Returns:
ConfusionMatrix containing boolean arrays for all classification outcomes and effectiveness metrics.
- Return type:
Example
Peak detection for energy load data:
>>> import numpy as np >>> y_true = np.array([100, 150, 80, 200, 90]) # 150 and 200 are peaks >>> y_pred = np.array([105, 145, 85, 195, 95]) >>> cm = confusion_matrix(y_true, y_pred, limit_pos=120, limit_neg=85) >>> int(cm.true_positives.sum()) # Successfully detected peaks 3 >>> int(cm.false_positives.sum()) # Incorrectly predicted peaks 0
Note
Effective true positives require that high peaks are predicted even higher (positive error) and low peaks are predicted even lower (negative error). This captures whether the forecast provides actionable information for energy system operators.
- Parameters:
y_true (
ndarray[tuple[Any,...],dtype[floating]])y_pred (
ndarray[tuple[Any,...],dtype[floating]])limit_pos (
float)limit_neg (
float)
- Return type: