tempor.metrics.metric module

Module containing the base class for metrics.

class tempor.metrics.metric.Metric[source]

Bases: Plugin, ABC

Metric abstract base class, defines the required methods.

The base class that all plugins must inherit from.

abstract property direction : Literal[minimize] | Literal[maximize]

The direction of the metric

evaluate(actual: Any, predicted: Any, *args: Any, **kwargs: Any) Any[source]

The metric evaluation call.

Parameters:
actual : Any

Actual value(s).

predicted : Any

Predicted value(s).

*args : Any

Additional positional arguments.

**kwargs : Any

Additional keyword arguments.

Returns:

Evaluated metric value(s)

Return type:

Any

class tempor.metrics.metric.OneOffPredictionMetric[source]

Bases: Metric

Metric abstract base class for the one-off prediction task.

The base class that all plugins must inherit from.

class tempor.metrics.metric.OneOffClassificationMetric[source]

Bases: OneOffPredictionMetric

Metric abstract base class for the one-off prediction task, classification case.

The base class that all plugins must inherit from.

evaluate(actual: ndarray, predicted: ndarray, *args: Any, **kwargs: Any) float[source]

The metric evaluation call.

actual and predicted are expected to be numpy arrays (sample in the 0th dimension).

predicted must be the probabilities in this case.

Parameters:
actual : np.ndarray

Actual value(s).

predicted : np.ndarray

Predicted value(s).

*args : Any

Additional positional arguments.

**kwargs : Any

Additional keyword arguments.

Returns:

Evaluated metric value.

Return type:

float

class tempor.metrics.metric.OneOffRegressionMetric[source]

Bases: OneOffPredictionMetric

Metric abstract base class for the one-off prediction task, regression case.

The base class that all plugins must inherit from.

evaluate(actual: ndarray, predicted: ndarray, *args: Any, **kwargs: Any) float[source]

The metric evaluation call.

actual and predicted are expected to be numpy arrays (sample in the 0th dimension).

Parameters:
actual : np.ndarray

Actual value(s).

predicted : np.ndarray

Predicted value(s).

*args : Any

Additional positional arguments.

**kwargs : Any

Additional keyword arguments.

Returns:

Evaluated metric value.

Return type:

float

class tempor.metrics.metric.TimeToEventMetric[source]

Bases: Metric

Metric abstract base class for the time-to-event (survival) task.

The base class that all plugins must inherit from.

evaluate(actual: tuple[ndarray, ndarray], predicted: ndarray, horizons: list[float] | list[int] | list[Timestamp], *args: Any, **kwargs: Any) list[float][source]

The metric evaluation call.

Parameters:
actual : metric_typing.EventArrayTimeArray

A tuple of two numpy arrays: the event values array and the event times array, for the actual event vales.

predicted : np.ndarray

A numpy array of shape (n_samples, n_horizons_timesteps, n_features) with the predicted risk estimates.

horizons : data_typing.TimeIndex

List of horizons time points.

*args : Any

Additional positional arguments.

**kwargs : Any

Additional keyword arguments.

Returns:

The metric values for each horizon time point.

Return type:

List[float]