混淆矩阵 prediction/actual
ConfusionMatrix prediction/actual
我试图预测“是”或“不是”糖尿病。我训练了我的数据集,如下所示。之后我预测了这些值。然后我创建了一个向量并尝试使用混淆矩阵来检查灵敏度、规格和准确性。但是我总是出错。
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"))
Error: $ operator is invalid for atomic vectors
我认为你是在 confusionMatrix
之后而不是 confusionMatrix.train
confusionMatrix(p_yes, df_test$Outcome, dnn = c("prediction", "actual"))
根据插入符号文档,confusionMatrix.train
用于
Using a train, rfe, sbf object, determine a confusion matrix based on
the resampling procedure
confusionMatrix.train(fitted_model)
我试图预测“是”或“不是”糖尿病。我训练了我的数据集,如下所示。之后我预测了这些值。然后我创建了一个向量并尝试使用混淆矩阵来检查灵敏度、规格和准确性。但是我总是出错。
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"))
Error: $ operator is invalid for atomic vectors
我认为你是在 confusionMatrix
之后而不是 confusionMatrix.train
confusionMatrix(p_yes, df_test$Outcome, dnn = c("prediction", "actual"))
根据插入符号文档,confusionMatrix.train
用于
Using a train, rfe, sbf object, determine a confusion matrix based on the resampling procedure
confusionMatrix.train(fitted_model)