Diff of /man/auc_wrapper.Rd [000000] .. [409433]

Switch to side-by-side view

--- a
+++ b/man/auc_wrapper.Rd
@@ -0,0 +1,49 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/metrics.R
+\name{auc_wrapper}
+\alias{auc_wrapper}
+\title{Mean AUC score}
+\usage{
+auc_wrapper(model_output_size, loss = "binary_crossentropy")
+}
+\arguments{
+\item{model_output_size}{Number of neurons in model output layer.}
+
+\item{loss}{Loss function of model, for which metric will be applied to; must be \code{"binary_crossentropy"}
+or \code{"categorical_crossentropy"}.}
+}
+\value{
+A keras metric.
+}
+\description{
+Compute AUC score as additional metric. If model has several output neurons with binary crossentropy loss, will use the average score.
+}
+\examples{
+\dontshow{if (reticulate::py_module_available("tensorflow")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
+
+y_true <- c(1,0,0,1,1,0,1,0,0) \%>\% matrix(ncol = 3)
+y_pred <- c(0.9,0.05,0.05,0.9,0.05,0.05,0.9,0.05,0.05) \%>\% matrix(ncol = 3)
+
+\donttest{
+library(keras)
+auc_metric <- auc_wrapper(3L, "binary_crossentropy")
+
+auc_metric$update_state(y_true, y_pred)
+auc_metric$result()  
+
+# add metric to a model
+num_targets <- 4
+model <- create_model_lstm_cnn(maxlen = 20,
+                               layer_lstm = 8,
+                               bal_acc = FALSE,
+                               last_layer_activation = "sigmoid",
+                               loss_fn = "binary_crossentropy",
+                               layer_dense = c(8, num_targets))
+
+auc_metric <- auc_wrapper(num_targets, loss = model$loss)
+model \%>\% keras::compile(loss = model$loss, 
+                         optimizer = model$optimizer,
+                         metrics = c(model$metrics, auc_metric))
+}
+\dontshow{\}) # examplesIf}
+}