Error resulting in using cv.glmnet

2019-06-28 01:08发布

问题:

I am attempting to use cv.glmnet to decide the best lambda for a lasso regression. However, I keep getting the following error

"Error in elnet(x, is.sparse, ix, jx, y, weights, offset, type.gaussian,: y is constant; gaussian glmnet fails at standardization step"

I imagine it has something to do with how I set up my x matrix but not sure what a better solution is

set.seed(20)
train = sample(nrow(stocks), nrow(stocks)/3)
x=model.matrix(PNC~.,stocks)
y=PNC
grid = exp(1)^seq(10, -5, length=100)
cv.out = cv.glmnet(x[train,], y[train], alpha = 1)
标签: r glmnet