r - How to use LASSO with categorical and continuous variables to predict a continuous variable? -


i have data base witch has 5000 observations (rows) , 40 variables (columns). number of categorical variables 25 , number of continuous variables 15. want use regression model predict continuous variable using categorical , continuous predictors (variables). besides consider kind of feature selection using lasso algorithm (glmnet() package glmnet) prevent using of variables predictors , use of them determined lasso (important ones).

my question how lasso can work categorical variables? should convert data frame matrix because glmnet() data in matrix type. when convert matrix columns's class change character. know need columns categorical , continuous.how should fix problem?

in other words, how can regression model , lasso feature selection on data has categorical , continuous variables predict continuous variable?

i create database toy data:

a <- sample(1000:1000000 , 60 , replace = t) b <- sample(50000:100000000 , 60 , replace = t ) c <- sample(1:90 , 60 , replace = t) d <- c("accident" , "injury" , "surgical" , "poison") d <- rep(d , 15 ) e <- paste(letters[1:6] , "#" , sep="") e <- rep(e, 10) x <- cbind(a,b,c,d,e) data.toy <- as.data.frame(x)  head(data.toy) data.toy$a <- as.numeric(data.toy$a) data.toy$b <- as.numeric(data.toy$b) data.toy$c <- as.numeric(data.toy$c) 

variables a, b continuous , d, e categorical. these 4 predictors , response column b continuous. use toy data me problem.

any little appreciated.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -