## S3 method for class 'numeric'
huberloss(actual, predicted, delta = 1, ...)
## S3 method for class 'numeric'
weighted.huberloss(actual, predicted, w, delta = 1, ...)
huberloss(...)
weighted.huberloss(...)
huber loss
huberloss.numeric | R Documentation |
Description
The huberloss()
-function computes the simple and weighted huber loss between the predicted and observed <numeric>
vectors. The weighted.huberloss()
function computes the weighted Huber Loss.
Usage
Arguments
actual
|
A |
predicted
|
A |
delta
|
A |
…
|
Arguments passed into other methods. |
w
|
A |
Value
A <numeric>
vector of length 1.
Calculation
The metric is calculated as follows,
\[ \frac{1}{2} (y - \upsilon)^2 ~for~ |y - \upsilon| \leq \delta \]
and
\[ \delta |y-\upsilon|-\frac{1}{2} \delta^2 ~for~ \text{otherwise} \]
where \(y\) and \(\upsilon\) are the actual
and predicted
values respectively. If w
is not NULL, then all values are aggregated using the weights.
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) calculate the metric
# with delta 0.5
huberloss(
actual = actual,
predicted = predicted,
delta = 0.5
)
# 3) caclulate weighted
# metric using arbitrary weights
<- rbeta(
w n = 1e3,
shape1 = 10,
shape2 = 2
)
huberloss(
actual = actual,
predicted = predicted,
delta = 0.5,
w = w
)