cv.glmnet(x=anscombe$x1, y=anscombe$y1, family= "binomial",
type.measure = "class", alpha = 1, nlambda = 100)
发生此错误:
rep(1,N)中的错误:无效的'times'参数
答案 0 :(得分:0)
如果查看数据,则您的依赖项是连续的,因此它应该是高斯的,以mse作为度量值:
head(anscombe,3)
x1 x2 x3 x4 y1 y2 y3 y4
1 10 10 10 8 8.04 9.14 7.46 6.58
2 8 8 8 8 6.95 8.14 6.77 5.76
3 13 13 13 8 7.58 8.74 12.74 7.71
之所以发生错误,是因为您在函数需要矩阵时提供了一个向量,并且为glmnet输入1个变量没有意义,因此最好进行回归。如果我们强制执行,则会收到错误,几乎可以总结为:
cv.glmnet(x=as.matrix(anscombe$x1,ncol=1), y=anscombe$y1, family= "gaussian",
type.measure = "mse", alpha = 1, nlambda = 100)
Error in glmnet(x, y, weights = weights, offset = offset, lambda = lambda, :
x should be a matrix with 2 or more columns
如果您使用大于1,则可以使用:
cv.glmnet(x=as.matrix(anscombe[,c("x1","x2")]), y=anscombe$y1, family= "gaussian",
type.measure = "mse", alpha = 1, nlambda = 100)