confusion_matrixTimeSeriesWrapper
Python template · sinapsis_darts_forecasting.templates.time_series_metrics
Overview
Dynamic Template for Darts metrics computation.
This template wraps any metric from the `darts.metrics` module and makes it available as a Sinapsis template. The wrapped metric is applied to the predictions and ground truth of each time series packet in the input container, and the result is stored in the `generic_data` field of the time series packet.
IMPORTANT NOTE: Validation mode should be enabled during model fitting and prediction (e.g., in the `TimeSeriesModel` template), to ensure that the metric is computed on the correct portion of the time series (i.e., the forecast horizon). If validation mode is not enabled, forecasted values and ground truth values may not be properly aligned, which can lead to incorrect metric calculations.
confusion_matrix — inherited documentation
Confusion Matrix (CM) [1]_.
For the true series :math:`y` and predicted series :math:`\hat{y}` of length :math:`T`, it is computed per component/column and label as:
The confusion matrix :math:`C` is such that :math:`C_{i,j}` is equal to the number of observations :math:`y` known to be in group :math:`i` and predicted :math:`\hat{y}` to be in group :math:`j`.
If :math:`\hat{y}_t` are stochastic (contains several samples), it takes the label with the highest count from each time step and component. If :math:`\hat{y}_t` represent the predict class label probabilities, it takes the label with the highest probability from each time step and component.
Parameters ---------- actual_series The (sequence of) actual series. pred_series The (sequence of) predicted series. intersect For time series that are overlapping in time without having the same time index, setting `True` will consider the values only over their common time interval (intersection in time). labels Optionally, the labels and their order to compute the metric on. If `None`, will use all unique values from the actual and predicted series. component_reduction Optionally, a function to aggregate the metrics over the component/column axis. It must reduce a `np.ndarray` of shape `(t, c)` to a `np.ndarray` of shape `(t,)`. The function takes as input a ``np.ndarray`` and a parameter named `axis`, and returns the reduced array. The `axis` receives value `1` corresponding to the component axis. If `None`, will return a metric per component. series_reduction Optionally, a function to aggregate the metrics over multiple series. It must reduce a `np.ndarray` of shape `(s, t, c)` to a `np.ndarray` of shape `(t, c)` The function takes as input a ``np.ndarray`` and a parameter named `axis`, and returns the reduced array. The `axis` receives value `0` corresponding to the series axis. For example with `np.nanmean`, will return the average over all series metrics. If `None`, will return a metric per component. n_jobs The number of jobs to run in parallel. Parallel jobs are created only when a ``Sequence[TimeSeries]`` is passed as input, parallelising operations regarding different ``TimeSeries``. Defaults to `1` (sequential). Setting the parameter to `-1` means using all the available processors. verbose Optionally, whether to print operations progress.
Returns ------- np.ndarray The Confusion Matrix as a numpy array for a single series. The array has shape (n components, n labels, n labels) without component reduction, and shape (n labels, n labels) with component reduction. list[np.ndarray] Same as for type `np.ndarray` but for a sequence of series.
References ---------- .. [1] https://en.wikipedia.org/wiki/Confusion_matrix
Capabilities
Capabilities: not setInstallation
Install the published package using pip or uv.
pip install sinapsis-darts-forecasting==1.0.0uv pip install sinapsis-darts-forecasting==1.0.0uv add sinapsis-darts-forecasting==1.0.0Configuration
Effective fields from the inspector schema, including nested Pydantic model fields.
Field used to set the template instance name and agent name. Defaults to None. confusion_matrix intersect <class 'bool'>: default: True labels typing.Union[int, list[int], numpy.ndarray, NoneType]: default: None n_jobs… Read full field description
Field used to set the template instance name and agent name. Defaults to None. confusion_matrix intersect <class 'bool'>: default: True labels typing.Union[int, list[int], numpy.ndarray, NoneType]: default: None n_jobs <class 'int'>: default: 1 verbose <class 'bool'>: default: False
Optional
Default: null
Required
Default: null
Optional
Default: null
Optional
Default: 1
Optional
Default: false
Optional
Default: true
Configuration example
Generated from documented defaults. Replace any placeholders and complete required nested settings before running.
templates:
- template_name: "confusion_matrixTimeSeriesWrapper"
class_name: "confusion_matrixTimeSeriesWrapper"
attributes:
confusion_matrix:
labels: null
n_jobs: 1
verbose: false
intersect: true
Inheritance
sinapsis_darts_forecasting.templates.time_series_metrics.TimeSeriesMetricsEnvironment variables
Environment definitions belong to their canonical Python modules.