(R)elnet(x,is.sparse,ix,jx,y,weights,offset,type.gaussian,:(list)对象中的错误不能强制为'double'类型

时间:2019-03-16 11:49:57

标签: r regression

ISLR库中的数据集是自动的。

library(ISLR)
df <- Auto
df <- na.omit(df)
glimpse(df)
rownames(df) <- c()

train_x = train%>% dplyr::select(-horsepower)
test_x = train$horsepower
train_y = train%>% dplyr::select(-acceleration)
test_y = train$acceleration

train_ridge = train_x %>% dplyr::select(-c("cylinders","mpg","displacement"))
summary(train_ridge)

test_ridge = train_y %>% dplyr::select("cylinders","mpg","displacement")
summary(test_ridge)

ridge = glmnet(as.matrix(train_ridge),y = test_ridge,alpha=0)

尝试通过岭回归预测圆柱,mpg和位移。

此代码显示此错误:

  

“ elnet(x,is.sparse,ix,jx,y,weights,offset,   type.gaussian,:(列表)对象不能被强制键入“ double””

Train_ridge和test_ridge已成功创建。
我不知道是什么问题。

0 个答案:

没有答案