if (torch::torch_is_installed()) {
library(torch)
actual <- c(1, 1, 1, 0, 0, 0) + 1L
predicted <- c(0.9, 0.8, 0.4, 0.5, 0.3, 0.2)
predicted <- cbind(1-predicted, predicted)
y_true <- torch_tensor(as.integer(actual))
y_pred <- torch_tensor(predicted)
m <- luz_metric_multiclass_auroc(thresholds = as.numeric(predicted),
average = "micro")
m <- m$new()
m$update(y_pred[1:2,], y_true[1:2])
m$update(y_pred[3:4,], y_true[3:4])
m$update(y_pred[5:6,], y_true[5:6])
m$compute()
}
Run the code above in your browser using DataLab