[1c0e03]: / man / balanced_acc_wrapper.Rd

Download this file

41 lines (37 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/metrics.R
\name{balanced_acc_wrapper}
\alias{balanced_acc_wrapper}
\title{Balanced accuracy metric}
\usage{
balanced_acc_wrapper(num_targets, cm_dir)
}
\arguments{
\item{num_targets}{Number of targets.}
\item{cm_dir}{Directory of confusion matrix used to compute balanced accuracy.}
}
\value{
A keras metric.
}
\description{
Compute balanced accuracy as additional score. Useful for imbalanced data. Only implemented for
model with mutually exclusive targets.
}
\examples{
\dontshow{if (reticulate::py_module_available("tensorflow")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
y_true <- c(1,0,0,1,
0,1,0,0,
0,0,1,0) \%>\% matrix(ncol = 3)
y_pred <- c(0.9,0.1,0.2,0.1,
0.05,0.7,0.2,0.0,
0.05,0.2,0.6,0.9) \%>\% matrix(ncol = 3)
cm_dir <- tempfile()
dir.create(cm_dir)
\donttest{
bal_acc_metric <- balanced_acc_wrapper(num_targets = 3L, cm_dir = cm_dir)
bal_acc_metric$update_state(y_true, y_pred)
bal_acc_metric$result()
as.array(bal_acc_metric$cm)
}
\dontshow{\}) # examplesIf}
}