首页 > 解决方案 > 使用 Caret 查找重要的特征

问题描述

我在使用时遇到问题Caret

我使用以下代码在 nnet 方法中构建模型,它可以工作。

model_nnet<-train(trainSetSmall[,predictors],trainSetSmall[,outcomeName],method='nnet')
importance <- varImp(model_nnet, scale=FALSE)
plot(importance)

然后,我想尝试其他模型。我试过“gbm”,但它不起作用。

model_gbm<-train(trainSetSmall[,predictors],trainSetSmall[,outcomeName],method='gbm')
importance2 <- varImp(model_gbm, scale=FALSE)

Error Message:  > importance2 <- varImp(model_gbm, scale=FALSE)
Error in relative.influence(object, n.trees = numTrees) : 
could not find function "relative.influence"

我也尝试了其他模型,但除了 nnet,我找不到另一个有效的模型。我的数据样本(所有列都是数字):

structure(list(x_NMI = c(6347, 6347), EstimateReadBitmaskInd = c(0, 
0), MeterRegActiveReadingDt = c("15-01-2013", "18-01-2013"), 
    MtrRegActNetEngyDailyKwh = c(16.736, 18.093), MtrRgActNetEngyMaxdlyKwh = c(0.831, 
    0.65), RegisterId = c(2, 2), RegisterType = c(2, 2), Building = c(6, 
    6), numberofpeople = c(5, 5), pool = c(2, 2), typeofAC = c(1, 
    1), NoOfAc = c(1, 1)), row.names = 1:2, class = "data.frame")

标签: rr-caret

解决方案


看起来relative.influence是包中的一个函数,gbm如下所示:

relative.influence 文档

我安装了插入符号并尝试使用 gbm 在一些琐碎的数据上训练模型。此消息提示我安装gbm软件包。

在此处输入图像描述

一旦我安装了这个gbm包,我就可以在插入符号中使用 gbm 来训练模型。


推荐阅读