Learn R Programming

msgl (version 2.3.9)

predict.msgl: Predict

Description

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

Usage

# S3 method for 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

link

the 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.

response

the 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.

classes

the estimated classes -- a matrix of size \(N_\textrm{new} \times d\) with \(d=\)length(fit$beta).

Examples

Run this code
# NOT RUN {
data(SimData)

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

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

lambda <- msgl::lambda(x.1, classes.1, alpha = .5, d = 50, lambda.min = 0.05)
fit <- msgl::fit(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