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

Switch to unified view

a b/man/auc_wrapper.Rd
1
% Generated by roxygen2: do not edit by hand
2
% Please edit documentation in R/metrics.R
3
\name{auc_wrapper}
4
\alias{auc_wrapper}
5
\title{Mean AUC score}
6
\usage{
7
auc_wrapper(model_output_size, loss = "binary_crossentropy")
8
}
9
\arguments{
10
\item{model_output_size}{Number of neurons in model output layer.}
11
12
\item{loss}{Loss function of model, for which metric will be applied to; must be \code{"binary_crossentropy"}
13
or \code{"categorical_crossentropy"}.}
14
}
15
\value{
16
A keras metric.
17
}
18
\description{
19
Compute AUC score as additional metric. If model has several output neurons with binary crossentropy loss, will use the average score.
20
}
21
\examples{
22
\dontshow{if (reticulate::py_module_available("tensorflow")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
23
24
y_true <- c(1,0,0,1,1,0,1,0,0) \%>\% matrix(ncol = 3)
25
y_pred <- c(0.9,0.05,0.05,0.9,0.05,0.05,0.9,0.05,0.05) \%>\% matrix(ncol = 3)
26
27
\donttest{
28
library(keras)
29
auc_metric <- auc_wrapper(3L, "binary_crossentropy")
30
31
auc_metric$update_state(y_true, y_pred)
32
auc_metric$result()  
33
34
# add metric to a model
35
num_targets <- 4
36
model <- create_model_lstm_cnn(maxlen = 20,
37
                               layer_lstm = 8,
38
                               bal_acc = FALSE,
39
                               last_layer_activation = "sigmoid",
40
                               loss_fn = "binary_crossentropy",
41
                               layer_dense = c(8, num_targets))
42
43
auc_metric <- auc_wrapper(num_targets, loss = model$loss)
44
model \%>\% keras::compile(loss = model$loss, 
45
                         optimizer = model$optimizer,
46
                         metrics = c(model$metrics, auc_metric))
47
}
48
\dontshow{\}) # examplesIf}
49
}