Trying to perform feature selection in R. I am using the glmnet package to do this. Here is my code so far:
lasso_model = glmnet(as.matrix(x = lasso, y = lasso_target,
standardize=TRUE, alpha=1))
lasso is a dataframe full of numeric and categoric predictors. The first column is the target variable which I have dropped.
lasso_target is the target variable that I dropped stored as its own dataframe.
Error:
Error in drop(y) : argument "y" is missing, with no default
My goal is to remove uninformative features from my dataframe before feeding it into my model. Any help would be greatly appreciated!
Your close! But the input and response variables need to be defined separately. What your doing is combining them both into one matrix (in addition to other args for glmnet) and passing the whole thing to the function. As x is the first argument by default, it assumes that is the input matrix and then cannot find the responsible variable because the y argument has not been defined. Thus, you receive an error that tells you so.
This should do the trick:
lasso_model <- glmnet(x = as.matrix(lasso),
y = as.matrix(lasso_target),
standardize=TRUE,
alpha=1)