diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2018-03-27 12:31:28 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2018-03-27 12:31:28 +0100 |
| commit | 004941896bac692d354c41a3334d20ee1d4627f7 (patch) | |
| tree | 2b11e42d8524843409e2bf8deb4ceb74c8b69347 /R/predict.gensvm.grid.R | |
| parent | updates to GenSVM C library (diff) | |
| download | rgensvm-004941896bac692d354c41a3334d20ee1d4627f7.tar.gz rgensvm-004941896bac692d354c41a3334d20ee1d4627f7.zip | |
GenSVM R package
Diffstat (limited to 'R/predict.gensvm.grid.R')
| -rw-r--r-- | R/predict.gensvm.grid.R | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/R/predict.gensvm.grid.R b/R/predict.gensvm.grid.R new file mode 100644 index 0000000..81a0207 --- /dev/null +++ b/R/predict.gensvm.grid.R @@ -0,0 +1,47 @@ +#' @title Predict class labels from the GenSVMGrid class +#' +#' @description Predict class labels using the best model from a grid search. +#' After doing a grid search with the \code{\link{gensvm.grid}} function, this +#' function can be used to make predictions of class labels. It uses the best +#' GenSVM model found during the grid search to do the predictions. Note that +#' this model is only available if \code{refit=TRUE} was specified in the +#' \code{\link{gensvm.grid}} call (the default). +#' +#' @param grid A \code{gensvm.grid} object trained with \code{refit=TRUE} +#' @param newx Matrix of new values for \code{x} for which predictions need to +#' be computed. +#' @param \dots further arguments are passed to predict.gensvm() +#' +#' @return a vector of class labels, with the same type as the original class +#' labels provided to gensvm.grid() +#' +#' @export +#' +#' @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}. +#' +#' @examples +#' x <- iris[, -5] +#' y <- iris[, 5] +#' +#' # run a grid search +#' grid <- gensvm.grid(x, y) +#' +#' # predict training sample +#' y.hat <- predict(grid, x) +#' +predict.gensvm.grid <- function(grid, newx, ...) +{ + if (is.null(grid$best.estimator)) { + cat("Error: Can't predict, the best.estimator element is NULL\n") + return + } + + return(predict(grid$best.estimator, newx, ...)) +} |
