## S3 method for class 'numeric'
pinball(actual, predicted, alpha = 0.5, deviance = FALSE, ...)
## S3 method for class 'numeric'
weighted.pinball(actual, predicted, w, alpha = 0.5, deviance = FALSE, ...)
pinball(...)
weighted.pinball(...)
pinball loss
pinball.numeric | R Documentation |
Description
The pinball()
-function computes the pinball loss between the observed and predicted <numeric>
vectors. The weighted.pinball()
function computes the weighted Pinball Loss.
Usage
Arguments
actual
|
A |
predicted
|
A |
alpha
|
A |
deviance
|
A |
…
|
Arguments passed into other methods. |
w
|
A |
Value
A <numeric>
vector of length 1.
Calculation
The metric is calculated as,
\[\text{PinballLoss}_{\text{unweighted}} = \frac{1}{n} \sum_{i=1}^{n} \left[ \alpha \cdot \max(0, y_i - \hat{y}_i) - (1 - \alpha) \cdot \max(0, \hat{y}_i - y_i) \right]\]
where \(y_i\) is the actual value, \(\hat{y}_i\) is the predicted value and \(\alpha\) is the quantile level.
Examples
# 1) fit a linear
# regression
<- lm(
model ~ .,
mpg data = mtcars
)
# 1.1) define actual
# and predicted values
# to measure performance
<- mtcars$mpg
actual <- fitted(model)
predicted
# 2) evaluate in-sample model
# performance using Pinball Loss
cat(
"Pinball Loss", pinball(
actual = actual,
predicted = predicted,
),"Pinball Loss (weighted)", weighted.pinball(
actual = actual,
predicted = predicted,
w = mtcars$mpg/mean(mtcars$mpg)
),sep = "\n"
)