[英]Variable Importance for caret loclda method
I am trying to compute the variable importance out of a caret 'loclda' model. 我试图从插入符号“ loclda”模型中计算出变量的重要性。
My training dataset contains 20 numeric predictors and 4 discrete outcome classes (2500 samples). 我的训练数据集包含20个数字预测变量和4个离散结果类(2500个样本)。
I built the model and computed the variable importance with the following commands: 我建立了模型,并使用以下命令计算了变量的重要性:
# fit the model
control <- trainControl(
method="repeatedcv",
number=10,
repeats=3,
savePredictions='final',
summaryFunction=multiClassSummary,
returnData=F,
trim=T,
allowParallel=F
)
my_loclda_model <- train(MyClass ~ ., data=trainData, method='loclda', trControl=control, importance=T)
# compute variable importance
varImp(my_loclda_model)
Error : is.list(x) is not TRUE
traceback()
7: stop(msg, call. = FALSE, domain = NA)
6: stopifnot(is.list(x), is.list(val))
5: modifyList(data, lapply(data[, fc], as.numeric))
4: asNumeric(x)
3: filterVarImp(x_dat, y_dat, nonpara = nonpara, ...)
2: varImp.train(model_name)
1: varImp(model_name)
From caret user manual we can read the following: 从插入符号的用户手册中,我们可以阅读以下内容:
For models that do not have corresponding varImp methods, see filterVarImp 对于没有相应的varImp方法的模型,请参见filterVarImp
Assuming loclda
model does not have a varImp
method, I tried to use the filterVarImp
function directly from the final model: 假设loclda
模型没有varImp
方法,我尝试直接从最终模型中使用filterVarImp
函数:
str(my_loclda_model$finalModel)
List of 12
$ learn : num [1:2500, 1:20] -0.404 -0.336 -0.655 -0.618 -0.151 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:2500] "X2" "X3" "X5" "X6" ...
.. ..$ : chr [1:20] "indexA1" "indexF1" "index4" "index5" ...
$ grouping : Factor w/ 4 levels "group1","group2","group3",..: 1 5 2 5 1 1 3 4 3 1 ...
..- attr(*, "names")= chr [1:2500] "2" "3" "5" "6" ...
$ lev : chr [1:4] "group1" "group2" "group3" ...
$ weight.func :function (x)
$ k : num 3401
$ weighted.apriori: logi TRUE
$ call : language loclda(x = x, grouping = y, k = floor(param$k), importance = ..1)
$ xNames : chr [1:20] "indexA1" "indexF1" "index4" "index5" ...
$ problemType : chr "Classification"
$ tuneValue :'data.frame': 1 obs. of 1 variable:
..$ k: num 3401
$ obsLevels : atomic [1:4] group1 group2 group3 ...
..- attr(*, "ordered")= logi FALSE
$ param :List of 1
..$ importance: logi TRUE
- attr(*, "class")= chr "loclda"
imp_out <- filterVarImp(x=my_loclda_model$finalModel$learn, y=my_loclda_model$finalModel$grouping)
Error in data[, fc] : (subscript) logical subscript too long
traceback()
5: lapply(data[, fc], as.numeric)
4: stopifnot(is.list(x), is.list(val))
3: modifyList(data, lapply(data[, fc], as.numeric))
2: asNumeric(x)
1: filterVarImp(x = model_name$finalModel$learn, y = model_name$finalModel$grouping)
I don't understand. 我不明白 What x
and y
arguments should I pass to filterVarImp
? 我应该将哪些x
和y
参数传递给filterVarImp
?
Thanks ! 谢谢 !
Note: the same problem also happened when using other methods (eg svmRadial, svmPoly, LogitBoost, regLogistic, ...). 注意:使用其他方法(例如svmRadial,svmPoly,LogitBoost,regLogistic等)时,也会发生相同的问题。
指定x=as.data.frame(my_loclda_model$finalModel$learn)
而不是矩阵似乎可以解决问题,尽管手册中提到可以同时使用矩阵和数据帧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.