diff options
Diffstat (limited to 'R/gensvm.accuracy.R')
| -rw-r--r-- | R/gensvm.accuracy.R | 37 |
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) +} |
