aboutsummaryrefslogtreecommitdiff
path: root/R/gensvm.accuracy.R
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2018-03-27 12:31:28 +0100
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2018-03-27 12:31:28 +0100
commit004941896bac692d354c41a3334d20ee1d4627f7 (patch)
tree2b11e42d8524843409e2bf8deb4ceb74c8b69347 /R/gensvm.accuracy.R
parentupdates to GenSVM C library (diff)
downloadrgensvm-004941896bac692d354c41a3334d20ee1d4627f7.tar.gz
rgensvm-004941896bac692d354c41a3334d20ee1d4627f7.zip
GenSVM R package
Diffstat (limited to 'R/gensvm.accuracy.R')
-rw-r--r--R/gensvm.accuracy.R37
1 files changed, 37 insertions, 0 deletions
diff --git a/R/gensvm.accuracy.R b/R/gensvm.accuracy.R
new file mode 100644
index 0000000..dbcd3cc
--- /dev/null
+++ b/R/gensvm.accuracy.R
@@ -0,0 +1,37 @@
+#' @title Compute the accuracy score
+#'
+#' @param y.true vector of true labels
+#' @param y.pred vector of predicted labels
+#'
+#' @author
+#' Gerrit J.J. van den Burg, Patrick J.F. Groenen \cr
+#' Maintainer: Gerrit J.J. van den Burg <gertjanvandenburg@gmail.com>
+#'
+#' @references
+#' Van den Burg, G.J.J. and Groenen, P.J.F. (2016). \emph{GenSVM: A Generalized
+#' Multiclass Support Vector Machine}, Journal of Machine Learning Research,
+#' 17(225):1--42. URL \url{http://jmlr.org/papers/v17/14-526.html}.
+#'
+#' @seealso
+#' \code{\link{predict.gensvm.grid}}
+#'
+#' @export
+#'
+#' @examples
+#' x <- iris[, -5]
+#' y <- iris[, 5]
+#'
+#' fit <- gensvm(x, y)
+#' gensvm.accuracy(predict(fit, x), y)
+#'
+gensvm.accuracy <- function(y.true, y.pred)
+{
+ n <- length(y.true)
+ if (n != length(y.pred)) {
+ cat("Error: Can't compute accuracy if vector don't have the ",
+ "same length\n")
+ return
+ }
+
+ return (sum(y.true == y.pred) / n)
+}