Metrics Utilities
The metrics utilities module provides functions for evaluating the performance of normative models. This includes functions for computing various error metrics, such as mean squared error (MSE), mean absolute error (MAE), and R-squared (R²) scores, among others. These metrics are essential for assessing the fit of the model to the data and for comparing different models.
spectranorm.utils.metrics
utils/metrics.py
Utility functions for computing various model metrics in the Spectranorm package.
compute_bic(model_log_likelihoods: npt.NDArray[np.floating[Any]], n_params: int, n_samples: int) -> npt.NDArray[np.floating[Any]]
Compute Bayesian Information Criterion (BIC) for model evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_log_likelihoods
|
NDArray[floating[Any]]
|
np.ndarray Log likelihoods from the model. (n_samples) or (n_samples, n_outputs) if multiple outputs are being assessed. |
required |
n_params
|
int
|
int Number of parameters in the model. |
required |
n_samples
|
int
|
int Number of samples used in the model. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
np.ndarray Bayesian Information Criterion. (n_outputs,) if multiple outputs are assessed, otherwise a scalar. |
Source code in src/spectranorm/utils/metrics.py
compute_expv(y: npt.NDArray[np.floating[Any]], y_pred: npt.NDArray[np.floating[Any]]) -> npt.NDArray[np.floating[Any]]
Compute Explained Variance (EXPV) between true and predicted values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
NDArray[floating[Any]]
|
np.ndarray True values. (n_samples) or (n_samples, n_outputs) if multiple outputs are being assessed. |
required |
y_pred
|
NDArray[floating[Any]]
|
np.ndarray Predicted values. (n_samples) or (n_samples, n_outputs) same shape as y. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
np.ndarray Explained Variance. (n_outputs,) if multiple outputs are assessed, otherwise a scalar. |
Source code in src/spectranorm/utils/metrics.py
compute_mae(y: npt.NDArray[np.floating[Any]], y_pred: npt.NDArray[np.floating[Any]]) -> npt.NDArray[np.floating[Any]]
Compute Mean Absolute Error (MAE) between true and predicted values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
NDArray[floating[Any]]
|
np.ndarray True values. (n_samples) or (n_samples, n_outputs) if multiple outputs are being assessed. |
required |
y_pred
|
NDArray[floating[Any]]
|
np.ndarray Predicted values. (n_samples) or (n_samples, n_outputs) same shape as y. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
np.ndarray Mean Absolute Error. (n_outputs,) if multiple outputs are assessed, otherwise a scalar. |
Source code in src/spectranorm/utils/metrics.py
compute_mape(y: npt.NDArray[np.floating[Any]], y_pred: npt.NDArray[np.floating[Any]]) -> npt.NDArray[np.floating[Any]]
Compute Mean Absolute Percentage Error (MAPE) between true and predicted values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
NDArray[floating[Any]]
|
np.ndarray True values. (n_samples) or (n_samples, n_outputs) if multiple outputs are being assessed. |
required |
y_pred
|
NDArray[floating[Any]]
|
np.ndarray Predicted values. (n_samples) or (n_samples, n_outputs) same shape as y. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
np.ndarray Mean Absolute Percentage Error. (n_outputs,) if multiple outputs are assessed, otherwise a scalar. |
Source code in src/spectranorm/utils/metrics.py
compute_mse(y: npt.NDArray[np.floating[Any]], y_pred: npt.NDArray[np.floating[Any]]) -> npt.NDArray[np.floating[Any]]
Compute Mean Squared Error (MSE) between true and predicted values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
NDArray[floating[Any]]
|
np.ndarray True values. (n_samples) or (n_samples, n_outputs) if multiple outputs are being assessed. |
required |
y_pred
|
NDArray[floating[Any]]
|
np.ndarray Predicted values. (n_samples) or (n_samples, n_outputs) same shape as y. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
np.ndarray Mean Squared Error. (n_outputs,) if multiple outputs are assessed, otherwise a scalar. |
Source code in src/spectranorm/utils/metrics.py
compute_msll(model_log_likelihoods: npt.NDArray[np.floating[Any]], baseline_log_likelihoods: npt.NDArray[np.floating[Any]]) -> npt.NDArray[np.floating[Any]]
Compute Mean Standardized Log Loss (MSLL) based on model and baseline log likelihoods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_log_likelihoods
|
NDArray[floating[Any]]
|
np.ndarray Log likelihoods from the model. (n_samples) or (n_samples, n_outputs) if multiple outputs are being assessed. |
required |
baseline_log_likelihoods
|
NDArray[floating[Any]]
|
np.ndarray Log likelihoods from the baseline model (a trivial model). Same shape as model_log_likelihoods. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
np.ndarray Mean Standardized Log Loss. (n_outputs,) if multiple outputs are assessed, otherwise a scalar. |
Source code in src/spectranorm/utils/metrics.py
compute_r2(y: npt.NDArray[np.floating[Any]], y_pred: npt.NDArray[np.floating[Any]]) -> npt.NDArray[np.floating[Any]]
Compute R-squared (coefficient of determination) between true and predicted values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
NDArray[floating[Any]]
|
np.ndarray True values. (n_samples) or (n_samples, n_outputs) if multiple outputs are being assessed. |
required |
y_pred
|
NDArray[floating[Any]]
|
np.ndarray Predicted values. (n_samples) or (n_samples, n_outputs) same shape as y. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
np.ndarray R-squared value. (n_outputs,) if multiple outputs are assessed, otherwise a scalar. |
Source code in src/spectranorm/utils/metrics.py
compute_rmse(y: npt.NDArray[np.floating[Any]], y_pred: npt.NDArray[np.floating[Any]]) -> npt.NDArray[np.floating[Any]]
Compute Root Mean Squared Error (RMSE) between true and predicted values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
NDArray[floating[Any]]
|
np.ndarray True values. (n_samples) or (n_samples, n_outputs) if multiple outputs are being assessed. |
required |
y_pred
|
NDArray[floating[Any]]
|
np.ndarray Predicted values. (n_samples) or (n_samples, n_outputs) same shape as y. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
np.ndarray Root Mean Squared Error. (n_outputs,) if multiple outputs are assessed, otherwise a scalar. |