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已成功创建。
我不知道是什么问题。