predict.cv.glintnet | R Documentation |
This function makes predictions from a cross-validated glintnet
model, using
the stored "glintnet.fit"
object, and the optimal value chosen for
lambda
.
## S3 method for class 'cv.glintnet'
predict(object, newx, lambda = c("lambda.1se", "lambda.min"), ...)
object |
Fitted |
newx |
Matrix of new values for |
lambda |
Value(s) of the penalty parameter |
... |
Other arguments that can be passed to |
This function makes it easier to use the results of cross-validation to make a prediction.
set.seed(0)
n=500
d_cont = 5 # number of continuous features
d_disc = 5 # number of categorical features
Z_cont = matrix(rnorm(n*d_cont), n, d_cont)
levels = sample(2:5,d_disc, replace = TRUE)
Z_disc = matrix(0,n,d_disc)
for(i in seq(d_disc))Z_disc[,i] = sample(0:(levels[i]-1),n,replace=TRUE)
Z = cbind(Z_cont,Z_disc)
levels = c(rep(1,d_cont),levels)
xmat = model.matrix(~Z_cont[,1]*factor(Z_disc[,2]))
nc=ncol(xmat)
beta = rnorm(nc)
y = xmat%*%beta+rnorm(n)*1.5
cvfit <- cv.glintnet(Z, glm.gaussian(y), levels=levels, intr_keys = 1)
plot(cvfit)
predict(cvfit, newx=Z[1:5,])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.