Learn R Programming

msgl (version 2.0.125.0)

predict.msgl: Predict

Description

Computes the linear predictors, the estimated probabilities and the estimated classes for a new data set.

Usage

## S3 method for class 'msgl':
predict(object, x,
    sparse.data = is(x, "sparseMatrix"), ...)

Arguments

object
an object of class msgl, produced with msgl.
x
a data matrix of size $N_\textrm{new} \times p$.
sparse.data
if TRUE x will be treated as sparse, if x is a sparse matrix it will be treated as sparse by default.
...
ignored.

Value

  • linkthe linear predictors -- a list of length length(fit$beta) one item for each model, with each item a matrix of size $K \times N_\textrm{new}$ containing the linear predictors.
  • responsethe estimated probabilities -- a list of length length(fit$beta) one item for each model, with each item a matrix of size $K \times N_\textrm{new}$ containing the probabilities.
  • classesthe estimated classes -- a matrix of size $N_\textrm{new} \times d$ with $d=$length(fit$beta).

Examples

Run this code
data(SimData)

x.1 <- sim.data$x[1:50,]
x.2 <- sim.data$x[51:100,]

classes.1 <- sim.data$classes[1:50]
classes.2 <- sim.data$classes[51:100]

lambda <- msgl.lambda.seq(x.1, classes.1, alpha = .5, d = 50, lambda.min = 0.05)
fit <- msgl(x.1, classes.1, alpha = .5, lambda = lambda)

# Predict classes of new data set x.2
res <- predict(fit, x.2)

# The error rates of the models
Err(res, classes = classes.2)

# The predicted classes for model 20
res$classes[,20]

Run the code above in your browser using DataLab