r - 使用 caret::varImp 时如何修复错误?
问题描述
我正在尝试为以下模型找到 varImp,
线性判别分析
50 个样本 25 个预测变量 2 个类别:“L”、“Lpo”
无预处理 重采样:留一法交叉验证 样本量总结:49、49、49、49、49、49,... 使用 SMOTE 进行额外采样
重采样结果:
ROC Sens 规格
0.9433345 0.9439082 0.8942777
caret::varImp(result$models[[2]], scale = TRUE)
是否有一个简单的修复此错误:
Error in y - mean(y, rm.na = TRUE): non-numeric argument to binary operator
Traceback:
1. caret::varImp(result$models[[2]], scale = TRUE)
2. varImp.train(result$models[[2]], scale = TRUE)
3. filterVarImp(x_dat, y_dat, nonpara = nonpara, ...)
4. apply(x, 2, testFunc, y = y)
5. FUN(newX[, i], ...)
解决方案
正如@Zyad Shehadeh 和@missuse 在评论中所说,您必须使用dput
一些数据或使用内置数据集重现您的错误。当我尝试使用数据集重现您的情况(您没有很好地解释)时iris
,一切正常:我假设您正在使用method="lda"
不平衡数据集(由于 )运行分类(由于additional sampling SMOTE
)。我用以下方法模拟这种数据iris
:
library(caret)
data("iris")
#eliminate a level in the Species column and reduce the observation for Species="versicolor" from 50 to 10 to imbalance the outcome
iris <- iris[-c(1:90),]
iris$Species <- factor(iris$Species,levels = unique(iris$Species))
cn <- trainControl(method = "LOOCV",sampling="smote",classProbs = T,summaryFunction =
twoClassSummary)
fit <- train(Species~.,data = iris,trControl=cn,method="lda",metric="ROC")
caret::varImp(fit, scale = TRUE)
一切正常,所以问题与您的数据有关,而不是与代码有关
推荐阅读
- python - div 元素内的文本没有被 Beautifulsoup 和请求打印出来
- c# - 无法跟踪实体类型“Unidad”的实例,因为另一个实例具有相同的键值 EF
- javascript - 过滤数组中的对象值
- java - AWS SDK 1.11.844 在连接到 Kinesis Stream 时连续抛出错误
- javascript - React中的setTimeout,无法清除
- android - Aspose Cell FileNotFoundException:EROFS(只读文件系统)
- azure - 通过 REST API 执行 AppInsight 查询
- reactjs - Redux 存储和本地存储有什么区别?
- python - 如何从 SQL Server 执行 Python 文件?
- c# - 无法通过 Xamarin C# 上的 LocalOnlyHotspot 广播 UDP 数据包