Similar to other predict methods, this functions predicts fitted values,
coefficients and more from a fitted "sparsenet"
object.
# S3 method for sparsenet
predict(object, newx, s = NULL, which.gamma = NULL,
type=c("response","coefficients","nonzero"), exact = FALSE, ...)
# S3 method for sparsenet
coef(object,s=NULL, which.gamma = NULL,exact=FALSE, ...)
The object returned depends on type.
Fitted "sparsenet"
model object.
Matrix of new values for x
at which predictions are
to be made. Must be a matrix. This argument is not used for type=c("coefficients","nonzero")
Value(s) of the penalty parameter lambda
at which
predictions are required. Default is the entire sequence used to
create the model.
Index or indices of gamma
values at which
predictions are to be made. Default is all those used in the fit
"response"
returns fitted predictions at
newx
. Type
"coefficients"
computes the coefficients at the requested
values for s
. Type "nonzero"
returns lists of the indices of the nonzero
coefficients for each value of s
.
By default (exact=FALSE
) the predict function uses linear interpolation
to make predictions for values of s
that do not coincide with
those used in the fitting algorithm. Currently exact=TRUE
is
not implemented, but prints an error message telling the user how to
achieve the exact predictions. This is done my rerunning the algorithm
with the desired values interspersed (in order) with the values used in
the original fit
Not used. Other arguments to predict.
Rahul Mazumder, Jerome Friedman and Trevor Hastie
Maintainer: Trevor Hastie <hastie@stanford.edu>
The shape of the objects returned depends on which
which.gamma
has more than one element.
If more than one element, a list of predictions is returned, one for
each gamma.
Mazumder, Rahul, Friedman, Jerome and Hastie, Trevor (2011) SparseNet: Coordinate Descent with Nonconvex Penalties. JASA, Vol 106(495), 1125-38, https://hastie.su.domains/public/Papers/Sparsenet/Mazumder-SparseNetCoordinateDescent-2011.pdf
glmnet
package, sparsenet
, cv.sparsenet
and
print
and plot
methods for both.
x=matrix(rnorm(100*20),100,20)
y=rnorm(100)
fit=sparsenet(x,y)
predict(fit, which.gamma=5,type="nonzero")
predict(fit,x)
Run the code above in your browser using DataLab