Documentation for Metrics¶
Common metrics to assess performance on NARX models.
explained_variance_score(y, yhat) ¶
Calculate the Explained Variance Score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float | EVS output is non-negative values. Becoming 1.0 means your model outputs are exactly matched by true target values. Lower values means worse results. |
References
- Wikipedia entry on the Explained Variance https://en.wikipedia.org/wiki/Explained_variation
Examples:
Source code in sysidentpy/metrics/_regression.py
forecast_error(y, yhat) ¶
Calculate the forecast error in a regression model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | ndarray of floats | The difference between the true target values and the predicted or forecast value in regression or any other phenomenon. |
References
- Wikipedia entry on the Forecast error https://en.wikipedia.org/wiki/Forecast_error
Examples:
Source code in sysidentpy/metrics/_regression.py
mean_absolute_error(y, yhat) ¶
Calculate the Mean absolute error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float or ndarray of floats | MAE output is non-negative values. Becoming 0.0 means your model outputs are exactly matched by true target values. |
References
- Wikipedia entry on the Mean absolute error https://en.wikipedia.org/wiki/Mean_absolute_error
Examples:
Source code in sysidentpy/metrics/_regression.py
mean_absolute_scaled_error(y, yhat, y_train, seasonal_period=1) ¶
Calculate the Mean Absolute Scaled Error.
MASE scales the mean absolute forecast error by the in-sample mean absolute error of a seasonal naive forecast.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape (n_samples,) or (n_samples, 1) | True target values for the forecast horizon. | required |
yhat | array-like of shape (n_samples,) or (n_samples, 1) | Target values predicted by the model. | required |
y_train | array-like of shape (n_training_samples,) or (n_training_samples, 1) | In-sample target values used to scale the forecast error. | required |
seasonal_period | int | Number of samples in one seasonal period. The default uses a one-step naive forecast as the scaling baseline. | 1 |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float | Non-negative scaled error. Values below one indicate that the model's mean absolute error is lower than the in-sample seasonal-naive error. If the in-sample scale is zero, returns 0.0 for a perfect forecast and |
Raises:
| Type | Description |
|---|---|
TypeError | If |
ValueError | If |
Notes
The caller is responsible for aligning y and yhat after excluding model-specific initial conditions such as max_lag. This metric does not inspect the fitted model or alter the supplied arrays.
References
- Hyndman, R. J., and Koehler, A. B. (2006). Another look at measures of forecast accuracy. International Journal of Forecasting, 22(4), 679-688. https://doi.org/10.1016/j.ijforecast.2006.03.001
Examples:
>>> y_train = np.array([1.0, 2.0, 3.0, 4.0])
>>> y = np.array([5.0, 6.0])
>>> yhat = np.array([4.5, 5.5])
>>> mean_absolute_scaled_error(y, yhat, y_train)
0.5
Source code in sysidentpy/metrics/_regression.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |
mean_forecast_error(y, yhat) ¶
Calculate the mean of forecast error of a regression model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float | The mean value of the difference between the true target values and the predicted or forecast value in regression or any other phenomenon. |
References
- Wikipedia entry on the Forecast error https://en.wikipedia.org/wiki/Forecast_error
Examples:
Source code in sysidentpy/metrics/_regression.py
mean_squared_error(y, yhat) ¶
Calculate the Mean Squared Error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float | MSE output is non-negative values. Becoming 0.0 means your model outputs are exactly matched by true target values. |
References
- Wikipedia entry on the Mean Squared Error https://en.wikipedia.org/wiki/Mean_squared_error
Examples:
Source code in sysidentpy/metrics/_regression.py
mean_squared_log_error(y, yhat) ¶
Calculate the Mean Squared Logarithmic Error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float | MSLE output is non-negative values. Becoming 0.0 means your model outputs are exactly matched by true target values. |
Raises:
| Type | Description |
|---|---|
ValueError | If |
Examples:
Source code in sysidentpy/metrics/_regression.py
median_absolute_error(y, yhat) ¶
Calculate the Median Absolute Error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float | MdAE output is non-negative values. Becoming 0.0 means your model outputs are exactly matched by true target values. |
References
- Wikipedia entry on the Median absolute deviation https://en.wikipedia.org/wiki/Median_absolute_deviation
Examples:
Source code in sysidentpy/metrics/_regression.py
normalized_root_mean_squared_error(y, yhat) ¶
Calculate the normalized Root Mean Squared Error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float | nRMSE output is non-negative values. Becoming 0.0 means your model outputs are exactly matched by true target values. For a constant target, the normalization range is zero. In that case, this function returns 0.0 for a perfect prediction and |
References
- Wikipedia entry on the normalized Root Mean Squared Error https://en.wikipedia.org/wiki/Root-mean-square_deviation
Examples:
>>> y = [3, -0.5, 2, 7]
>>> yhat = [2.5, 0.0, 2, 8]
>>> normalized_root_mean_squared_error(y, yhat)
0.081
Source code in sysidentpy/metrics/_regression.py
r2_score(y, yhat) ¶
Calculate the R2 score. Based on sklearn solution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float | R2 output can be non-negative values or negative value. Becoming 1.0 means your model outputs are exactly matched by true target values. Lower values means worse results. |
Notes
This is not a symmetric function.
References
- Wikipedia entry on the Coefficient of determination https://en.wikipedia.org/wiki/Coefficient_of_determination
Examples:
Source code in sysidentpy/metrics/_regression.py
root_mean_squared_error(y, yhat) ¶
Calculate the Root Mean Squared Error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float | RMSE output is non-negative values. Becoming 0.0 means your model outputs are exactly matched by true target values. |
References
- Wikipedia entry on the Root Mean Squared Error https://en.wikipedia.org/wiki/Root-mean-square_deviation
Examples:
Source code in sysidentpy/metrics/_regression.py
root_relative_squared_error(y, yhat) ¶
Calculate the Root Relative Mean Squared Error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float | RRSE output is non-negative values. Becoming 0.0 means your model outputs are exactly matched by true target values. For a constant target, the denominator is zero. In that case, this function returns 0.0 for a perfect prediction and |
Examples:
>>> y = [3, -0.5, 2, 7]
>>> yhat = [2.5, 0.0, 2, 8]
>>> root_relative_mean_squared_error(y, yhat)
0.206
Source code in sysidentpy/metrics/_regression.py
symmetric_mean_absolute_percentage_error(y, yhat) ¶
Calculate the SMAPE score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | array-like of shape = number_of_outputs | Represent the target values. | required |
yhat | array-like of shape = number_of_outputs | Target values predicted by the model. | required |
Returns:
| Name | Type | Description |
|---|---|---|
loss | float | SMAPE output is a non-negative value. The results are percentages values. |
Notes
One supposed problem with SMAPE is that it is not symmetric since over-forecasts and under-forecasts are not treated equally. When both the target and prediction are zero, their contribution is defined as zero.
References
- Wikipedia entry on the Symmetric mean absolute percentage error https://en.wikipedia.org/wiki/Symmetric_mean_absolute_percentage_error
Examples:
>>> y = [3, -0.5, 2, 7]
>>> yhat = [2.5, 0.0, 2, 8]
>>> symmetric_mean_absolute_percentage_error(y, yhat)
57.87