Does k-fold cross-validation for sparsenet, produces a plot,
and returns values for gamma, lambda
cv.sparsenet(x, y, weights, type.measure = c("mse", "mae"), ...,nfolds = 10,
foldid, keep=FALSE, trace.it=FALSE)
an object of class "cv.sparsenet"
is returned, which is a
list with the ingredients of the cross-validation fit.
the values of lambda
used in the fits. This is an
nlambda x ngamma
matrix
The mean cross-validated error - a matrix shaped like lambda
estimate of standard error of cvm
.
upper curve = cvm+cvsd
.
lower curve = cvm-cvsd
.
number of non-zero coefficients at each lambda,
gamma
pair.
a text string indicating type of measure (for plotting purposes).
a fitted sparsenet object for the full data.
The call that produced this object
values of gamma, lambda
that gives minimum
cvm
.
indices for the above
gamma, lambda
of smallest model (df) such that error is
within 1 standard error of the minimum.
indices of the above
x
matrix as in sparsenet
.
response y
as in sparsenet
.
Observation weights; defaults to 1 per observation
loss to use for cross-validation. Currently two
options:
squared-error (type.measure="mse"
) or
mean-absolute error ( type.measure="mae"
)
Other arguments that can be passed to sparsenet
.
number of folds - default is 10. Although nfolds
can be as large as the sample size (leave-one-out CV), it is not
recommended for large datasets. Smallest value allowable is nfolds=3
an optional vector of values between 1 and nfold
identifying whhat fold each observation is in. If supplied,
nfold
can be missing.
If TRUE
, we include the prevalidation array as
component fit.preval
on the returned object. Default is
keep = FALSE
.
If TRUE
, then we get a printout that shows the
progress
Rahul Mazumder, Jerome Friedman and Trevor Hastie
Maintainer: Trevor Hastie <hastie@stanford.edu>
The function runs sparsenet
nfolds
+1 times; the
first to get the lambda
sequence, and then the remainder to
compute the fit with each of the folds omitted. The error is
accumulated, and the average error and standard deviation over the
folds is computed.
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, predict
, coef
, print
and plot
methods, and the sparsenet
function.
train.data=gendata(100,1000,nonzero=30,rho=0.3,snr=3)
fit=sparsenet(train.data$x,train.data$y)
par(mfrow=c(3,3))
plot(fit)
par(mfrow=c(1,1))
fitcv=cv.sparsenet(train.data$x,train.data$y,trace.it=TRUE)
plot(fitcv)
Run the code above in your browser using DataLab