R在RFE(递归特征消除)中使用我自己的模型来选择重要特征 [英] R using my own model in RFE(recursive feature elimination) to pick important feature

查看:1136
本文介绍了R在RFE(递归特征消除)中使用我自己的模型来选择重要特征的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用RFE,您可以获得功能的重要性等级,但是现在我只能在包内部使用模型和参数,例如:lmFuncs(linear model),rfFuncs(random forest) 似乎

Using RFE, you can get a importance rank of the features, but right now I can only use the model and parameter inner the package like: lmFuncs(linear model),rfFuncs(random forest) it seems that

caretFuncs

可以为您自己的模型和参数做一些自定义设置,但是我不知道详细信息,而正式文档也没有提供详细信息,我想将svm和gbm应用于此RFE流程,因为这是当前的我以前训练的模型,有人有什么主意吗?

can do some custom settings for your own model and parameter,but I don't know the details and the formal document didn't give detail, I want to apply svm and gbm to this RFE process,because this is the current model I used to train, anyone has any idea?

推荐答案

我试图根据文档重新创建工作示例.您正确识别了caretFuncs的使用,然后可以在rfe调用中设置模型参数(也可以定义trainControl对象等).

I tried to recreate working example based on the documentation. You correctly identified use of caretFuncs, you can then set your model parameters in rfe call (you can also define trainControl object etc).

# load caret
library(caret)

# load data, get target and feature column labels
data(iris)
col_names = names(iris);target = "Species"
feature_names = col_names[col_names!=target]

# construct rfeControl object
rfe_control = rfeControl(functions = caretFuncs, #caretFuncs here
                     method="cv",
                     number=5)

# construct trainControl object for your train method 
fit_control = trainControl(classProbs=T,
                        search="random")

# get results
rfe_fit = rfe(iris[,feature_names], iris[,target],
             sizes = 1:4,
             rfeControl = rfe_control,
             method="svmLinear",
             # additional arguments to train method here
             trControl=fit_control)

如果您想更深入地研究此事,则可能需要访问下面的链接.

If you want to dive deeper into the matter you might want to visit links below.

rfe文档,其中包含基本代码段:
https://www.rdocumentation.org/packages/caret/版本/6.0-80/topics/rfe

rfe documentation with basic code snippets:
https://www.rdocumentation.org/packages/caret/versions/6.0-80/topics/rfe

caret文档:
https://topepo.github.io/caret/recursive-feature-elimination. html

希望这会有所帮助!

这篇关于R在RFE(递归特征消除)中使用我自己的模型来选择重要特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆