"predict"(object, newx, s = NULL,
type=c("link","response","coefficients","nonzero","class"), exact = FALSE, offset, ...)
"coef"(object,s=NULL, exact=FALSE, ...)
"glmnet" model object.
Matrix of new values for
x at which predictions are
to be made. Must be a matrix; can be sparse as in
package. This argument is not used for
Value(s) of the penalty parameter
lambda at which
predictions are required. Default is the entire sequence used to
create the model.
Type of prediction required. Type
"link" gives the
linear predictors for
"cox" models; for
models it gives the fitted
"response" gives the fitted probabilities for
"multinomial", fitted mean for
"poisson" and the fitted relative-risk for
"response" is equivalent to type
"coefficients" computes the coefficients at the requested
s. Note that for
"binomial" models, results are returned only for the class
corresponding to the second level of the factor response.
"class" applies only to
"multinomial" models, and produces the
class label corresponding to the maximum probability. Type
"nonzero" returns a list of the indices of the nonzero
coefficients for each value of
This argument is relevant only when predictions are made at
s (lambda) different from those used in the fitting
of the original model. If
exact=FALSE (default), then the predict function uses linear interpolation
to make predictions for values of
s (lambda) that do not coincide with
those used in the fitting algorithm. While this is often a good
approximation, it can sometimes be a bit coarse.
exact=TRUE, these different values of
s are merged
(and sorted) with
object$lambda, and the model is refit before predictions are
made. In this case, it is strongly advisable to supply the original
y= as additional
named arguments to
predict.glmnet() needs to
update the model,
and expects the data used to create it to be around.
Although it will often work fine without supplying these additional arguments, it will likely break when
used inside a nested sequence of function calls.
If additional arguments such as
offset were used, these should be included by name as well.
If an offset is used in the fit, then one must be
supplied for making predictions (except for
This is the mechanism for passing arguments like