I'm trying to compute one step forecast in glmnet
package. Below is an example:
x = matrix(rnorm(100 * 20), 100, 20)
y = rnorm(100)
cv.fit = cv.glmnet(x, y)
predict(cv.fit, newx = x[1, ])
I get the following error:
Error in cbind2(1, newx) %*% nbeta :
Cholmod error 'X and/or Y have wrong dimensions' at file ../MatrixOps/cholmod_sdmult.c, line 90
I would be grateful if someone can help to handle this issue.
When you select 1 row of a matrix/dataframe it is transformed into a vector, which is not an option as input to predict. Simply add newx = x[1, ,drop=F]
.