【问题标题】:one step forecast using 'glmnet' package - cv.glmnet使用“glmnet”包进行一步预测 - cv.glmnet
【发布时间】:2021-03-18 11:04:46
【问题描述】:

我正在尝试计算 glmnet 包中的一步预测。下面是一个例子:

x = matrix(rnorm(100 * 20), 100, 20)
y = rnorm(100)
cv.fit = cv.glmnet(x, y)
predict(cv.fit, newx = x[1, ])

我收到以下错误:

Error in cbind2(1, newx) %*% nbeta : 
  Cholmod error 'X and/or Y have wrong dimensions' at file ../MatrixOps/cholmod_sdmult.c, line 90

如果有人可以帮助解决这个问题,我将不胜感激。

【问题讨论】:

    标签: r forecasting glmnet


    【解决方案1】:

    当您选择矩阵/数据框的 1 行时,它会转换为向量,这不是作为预测输入的选项。只需添加newx = x[1, ,drop=F]

    【讨论】:

      猜你喜欢
      • 2022-07-22
      • 2021-02-01
      • 1970-01-01
      • 2022-01-23
      • 2019-03-18
      • 1970-01-01
      • 2017-12-25
      • 2015-11-18
      • 2014-09-28
      相关资源
      最近更新 更多