如何停用插入符号包中的嵌入式功能选择?

时间:2019-07-13 16:42:10

标签: r feature-selection

我正在使用R中的caret包编写机器学习代码。代码示例可能是

weighted_fit <- train(outcome,
                          data = train,
                          method = 'glmnet',
                          trControl = ctrl)

您知道,插入符号包中的某些方法具有内置功能选择,例如弹性网。我的问题是,有什么方法可以停用此代码中的内置功能选择吗?

谢谢您的任何评论。

1 个答案:

答案 0 :(得分:0)

#I will try to answer this question to the best of my ability:
#The train function in caret package comes with a parameter tuneGrid which can be used to create a data-frame of tuning parameters.

#The tuning parameter of elastic net regularization in glmnet() is alpha, so create the following:
glmgrid <- expand.grid(alpha = 0) will give ridge regularization.
glmgrid <- expand.grid(alpha = 1) will give lasso regularization.

#and then use 

weighted_fit <- train(outcome,
                          data = train,
                          method = 'glmnet',
                          trControl = ctrl,
                          tuneGrid = glmgrid)

#In glmnet in r , the alpha values can be in the range [0,1] i.e. 0 to 1 including 0 and 1.


# GLMNET - https://www.rdocumentation.org/packages/glmnet/versions/2.0-18/topics/glmnet
# CARET - https://topepo.github.io/caret/index.html