Focal loss for two or more labels
Usage
focal_loss_multiclass(y_true, y_pred, gamma = 2.5, alpha = c(1))
Arguments
- y_true
Vector of true values.
- y_pred
Vector of predicted values.
- gamma
Focusing parameter.
- alpha
Vector of weighting factors.
Value
A function implementing focal loss.
Examples
if (FALSE) { # reticulate::py_module_available("tensorflow")
y_true <- matrix(c(0, 1, 0, 0, 0, 1), nrow = 2, byrow = TRUE)
y_pred <- matrix(c(0.15, 0.8, 0.05,
0.08, 0.02, 0.9), nrow = 2, byrow = TRUE)
fl <- focal_loss_multiclass(y_true, y_pred)
fl$numpy()
}