[英]one step forecast using 'glmnet' package - cv.glmnet
I'm trying to compute one step forecast in glmnet
package.我正在尝试在
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.当您 select 1 行矩阵/数据帧时,它被转换为向量,这不是作为预测输入的选项。 Simply add
newx = x[1, ,drop=F]
.只需添加
newx = x[1, ,drop=F]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.