data(ggplot2::diamonds)
library(caret)
library(dplyr)
dia.trans<-bind_cols(diamonds %>% select_if(is.numeric),
model.matrix(~cut-1,diamonds) %>% as_tibble(),
model.matrix(~color-1,diamonds) %>% as_tibble(),
model.matrix(~clarity-1,diamonds) %>% as_tibble())
lasso_expand<-expand.grid(alpha = 1, lambda = seq(0.001,0.1,by = 0.0005))
lasso_mod <- train(x=dia.trans %>% select(-price), y=dia.trans$price, method='glmnet',
tuneGrid=lasso_expand)
lasso_mod$bestTune
lasso_mod$results$RMSE
lasso_imp<-varImp(lasso_mod)
lasso_imp$importance