我正在R中使用mlr
包来比较一个二进制分类任务中的两个学习者,即随机森林和套索分类器。我使用嵌套的交叉验证来计算性能。然后,在这种情况下,我想计算特征对于最佳分类器(随机森林)的重要性。为此,我使用generateFeatureImportanceData()
:“通过对比预测性能来估算单个特征或一组特征的重要性。对于方法“ permutation.importance”,通过对特征值进行置换来计算性能变化(或一组特征),并将其与对未融合数据所做的预测进行比较。”正如我指定的measure = auc
一样,输出res是否为每个特征置换其值而减少了auc
?
图书馆(简易包装)
libraries("mlr","purrr","glmnet","parallelMap","parallel")
data = read.table("data_past.txt", h = T)
set.seed(123)
task = makeClassifTask(id = "past_history", data = data, target =
"DIAG", positive = "BD")
#specifying hyperparameters for random forest
ps_rf = makeParamSet(makeIntegerParam("mtry", lower = 4, upper =
16),makeDiscreteParam("ntree", values = 1000))
ctrl_rf = makeTuneControlRandom(maxit = 10L)
inner = makeResampleDesc("RepCV", fold = 10, reps = 3, stratify = TRUE)
lrn_rf = makeLearner("classif.randomForest", predict.type = "prob",
fix.factors.prediction = TRUE)
lrn_rf = makeTuneWrapper(lrn_rf, resampling = inner, par.set = ps_rf,
control = ctrl_rf, measures = auc, show.info = FALSE)
parallelStartMulticore(36)
ft_im = generateFeatureImportanceData(task = task, method =
"permutation.importance", learner = lrn_rf, measure = auc)
parallelStop()
t(ft_im$res)
auc
INC2_A 0.000000e+00
INC2_B 0.000000e+00
INC2_F 0.000000e+00
INC2_G 0.000000e+00
INC2_H 0.000000e+00
INC2_I 0.000000e+00
SEX 0.000000e+00
marital -3.211696e-07
inpatient 0.000000e+00
CMS_1 0.000000e+00
CMS_2 0.000000e+00
CMS_3 0.000000e+00
CMS_4 0.000000e+00
CMS_5 0.000000e+00
CMS_6 0.000000e+00
CMS_7 0.000000e+00
CMS_8 0.000000e+00
CMS_9 0.000000e+00
CMS_10 0.000000e+00
CMS_11 0.000000e+00
CMS_12 0.000000e+00
CMS_13 0.000000e+00
CMS_14 0.000000e+00
OCS_1 0.000000e+00
OCS_2 0.000000e+00
OCS_3 0.000000e+00
OCS_4 0.000000e+00
OCS_5 0.000000e+00
OCS_6 0.000000e+00
OCS_7 0.000000e+00
OCS_8 0.000000e+00
OCS_9 0.000000e+00
OCS_10 0.000000e+00
OCS_11 0.000000e+00
reta 0.000000e+00
MH_F1 -1.051220e-03
CP_1BA 0.000000e+00
CP_1BS 0.000000e+00
MIXCLINICAL3 0.000000e+00
MIXCLINICAL2 0.000000e+00
MIXDS52Simpt 0.000000e+00
MIXDS53Simpt 0.000000e+00
PAN 0.000000e+00
OBS 0.000000e+00
PHO 0.000000e+00
GAD 0.000000e+00
EAT_0 0.000000e+00
ADHD 0.000000e+00
BORDERLINEPERSONALITY 0.000000e+00
AlcoolProbUse 0.000000e+00
SubstanceProbUse 0.000000e+00
BMI -2.954760e-06
DEP_AGE -7.996641e-04
NBD_P -1.669455e-03
NBDEP -8.671578e-06
NBSUI -2.055485e-06
NBHOS -8.091225e-03
DURDEP -1.380869e-04
SEV_M -3.083132e-03
SEV_D 0.000000e+00
CMS_sum 0.000000e+00
TOTMIXDSM5 0.000000e+00
GAF -1.170663e-05
Age -1.172269e-06
Comorbidities_sum 0.000000e+00
绝对值最高的功能更重要吗? auc
的零值是否表示该功能与手头的分类任务无关?谢谢。
答案 0 :(得分:2)
特征得分是通过将模型的正常预测得分减去通过置换特征获得的预测得分而获得的。
因此,AUC drop = 0的特征在它们不会带来任何附加值的意义上是无关紧要的(它们就像纯随机噪声一样重要)。另一方面,具有最高绝对值的特征最为重要,因为更改它们对得分的影响最大。