【发布时间】:2020-11-25 21:09:10
【问题描述】:
我试图预测糖尿病“是”或“否”。我训练了我的数据集,如下所示。之后我预测了这些值。然后我创建了一个向量并尝试使用混淆矩阵来检查 sens、spec 和accuracy。但我总是出错。
df_fold <- train(data = df_train, Outcome~., method = "glmnet",
family = "binomial",
metric = "ROC",
preProcess = c("zv", "center", "scale"),
trControl = trainControl(
method = "cv", number = 10,
summaryFunction = twoClassSummary,
classProbs = TRUE,
verboseIter = TRUE
))
p <- predict.train(df_fold, df_test, type = "prob")
y_or_no <- ifelse(p > 0.8, "yes", "no")
p_yes <- factor(y_or_no, levels = levels(df_test$Outcome))
confusionMatrix.train(p_yes, df_test$Outcome, dnn = c("prediction", "actual"))
错误:$ 运算符对原子向量无效
【问题讨论】:
-
df_test长什么样子? -
我发现 p_yes 有 477 个值。由于预测功能,这太多了。它给了我一个 243 obs 的 df。两个变量而不是 1 个变量的 243 个 obs