> cv.ctrl <- trainControl(method = "repeatedcv", repeats = 3,
+ summaryFunction = twoClassSummary,
+ classProbs = TRUE)
>
> set.seed(35)
> glm.tune.1 <- train(y ~ bool_3,
+ data = train.batch,
+ method = "glm",
+ metric = "ROC",
+ trControl = cv.ctrl)
Error in sensitivity.default(data[, "pred"], data[, "obs"], lev[1]) :
input data must have the same two levels
In addition: Warning message:
In train.default(x, y, weights = w, ...) :
At least one of the class levels are not valid R variables names; This may cause errors if class probabilities are generated because the variables names will be converted to: X.1, X0, X1
以下是数据结构的摘录:
> str(train.batch)
'data.frame': 128046 obs. of 42 variables:
$ bool_3 : int 0 0 0 0 0 0 0 1 0 0 ...
$ bool_brand_cat : int 0 0 0 0 0 0 0 1 0 0 ...
$ bool_cat_comp : int 0 0 0 0 0 0 0 1 0 0 ...
...
$ y : Factor w/ 3 levels "-1","0","1": 2 3 2 2 2 3 3 3 3 2 ...
我需要设置灵敏度吗?或者我错过了什么?
最佳答案
y
是一个“带 3 个级别的因子
”。除非结果中有两个水平,否则您无法计算敏感性和特异性(请参阅输入数据必须具有相同的两个水平
的注释)
关于R 插入符 灵敏度错误。默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23737949/