0
点赞
0
评论
0
转载
收藏

基于R的Caret包的特征选择

链接:https://machinelearningmastery.com/feature-selection-with-the-caret-r-package/


基于重要性的特征排序 Rank Features By Importance

        特征的重要性可以通过构建模型来评估。比如决策树(Decision tree)就有内部机制来评估特征的重要性. 其它方法也可以根据ROC曲线分析来评估特征的重要性。

         下面给出了基于Pima Indians Diabetes数据库和Learning Vector Quantization(LVQ)模型. 这样就能够根据重要性来对特征进行排序。代码如下:

# ensure results are repeatable
set.seed(7)
# load the library
library(mlbench)
library(caret)
# load the dataset
data(PimaIndiansDiabetes)
# prepare training scheme
control <- trainControl(method="repeatedcv", number=10, repeats=3)
# train the model
model <- train(diabetes~., data=PimaIndiansDiabetes, method="lvq", preProcess="scale", trControl=control)
# estimate variable importance
importance <- varImp(model, scale=FALSE)
# summarize importance
print(importance)
# plot importance
plot(importance)        

            更进一步的,Recursive Feature Elimination (RFE)方法能够实现特征的选择。这个结果最后需要借助统计学和实际需要来判定特征选择结果的合理性分析。

# ensure the results are repeatable
set.seed(7)
# load the library
library(mlbench)
library(caret)
# load the data
data(PimaIndiansDiabetes)
# define the control using a random forest selection function
control <- rfeControl(functions=rfFuncs, method="cv", number=10)
# run the RFE algorithm
results <- rfe(PimaIndiansDiabetes[,1:8], PimaIndiansDiabetes[,9], sizes=c(1:8), rfeControl=control)
# summarize the results
print(results)
# list the chosen features
predictors(results)
# plot the results
plot(results, type=c("g", "o"))


               需要说明的是,通过相关性分析(Remove Redundant Features)部分,我不确定分析之后该如何处理这些特征呢?既没有对特征排序,又没有给出一个特征子集,所以怎么使用这个信息还不明确。

声明:本内容系学者网用户个人学术动态分享,不代表平台立场。

中国传媒大学 信息与通信工程学院/人工智能系
近期热门动态
CFP: Representation Learning in Radiology
2038 2020-04-13 12:38:58
code for papers
2003 2021-01-01 12:15:04
CFP: Advanced Technologies for Image/Video Quality Assessment
1997 2022-11-05 22:11:47
Welcome to Yu's homepage
1893 2016-07-14 14:24:39
medical concept
1223 2020-07-18 17:07:34
SCHOLAT.com 学者网
免责声明 | 关于我们 | 联系我们
联系我们:
返回顶部