Metric¶
- class pytorch_forecasting.metrics.Metric(name: Optional[str] = None, quantiles: Optional[List[float]] = None, reduction='mean')[source]¶
Bases:
torchmetrics.metric.Metric
Base metric class that has basic functions that can handle predicting quantiles and operate in log space. See the Lightning documentation for details of how to implement a new metric
Other metrics should inherit from this base class
Initialize metric
- Parameters
name (str) – metric name. Defaults to class name.
quantiles (List[float], optional) – quantiles for probability range. Defaults to None.
reduction (str, optional) – Reduction, “none”, “mean” or “sqrt-mean”. Defaults to “mean”.
Methods
compute
()Abstract method that calcualtes metric
rescale_parameters
(parameters, target_scale, ...)Rescale normalized parameters into the scale required for the output.
to_prediction
(y_pred)Convert network prediction into a point prediction.
to_quantiles
(y_pred[, quantiles])Convert network prediction into a quantile prediction.
update
(y_pred, y_actual)Override this method to update the state variables of your metric class.
- compute() torch.Tensor [source]¶
Abstract method that calcualtes metric
Should be overriden in derived classes
- Parameters
y_pred – network output
y_actual – actual values
- Returns
metric value on which backpropagation can be applied
- Return type
torch.Tensor
- rescale_parameters(parameters: torch.Tensor, target_scale: torch.Tensor, encoder: sklearn.base.BaseEstimator) torch.Tensor [source]¶
Rescale normalized parameters into the scale required for the output.
- Parameters
parameters (torch.Tensor) – normalized parameters (indexed by last dimension)
target_scale (torch.Tensor) – scale of parameters (n_batch_samples x (center, scale))
encoder (BaseEstimator) – original encoder that normalized the target in the first place
- Returns
parameters in real/not normalized space
- Return type
torch.Tensor
- to_prediction(y_pred: torch.Tensor) torch.Tensor [source]¶
Convert network prediction into a point prediction.
- Parameters
y_pred – prediction output of network
- Returns
point prediction
- Return type
torch.Tensor
- to_quantiles(y_pred: torch.Tensor, quantiles: Optional[List[float]] = None) torch.Tensor [source]¶
Convert network prediction into a quantile prediction.
- Parameters
y_pred – prediction output of network
quantiles (List[float], optional) – quantiles for probability range. Defaults to quantiles as as defined in the class initialization.
- Returns
prediction quantiles
- Return type
torch.Tensor