计算混淆矩阵:

# 预测结果和真实结果
predicted <- c(0, 1, 1, 0, 1, 1, 0, 0, 1, 1)
actual <- c(1, 1, 0, 0, 1, 0, 1, 1, 0, 1)

# 计算混淆矩阵
confusion_matrix <- table(predicted, actual)
confusion_matrix

输出结果:

actual
predicted 0 1
        0 2 2
        1 2 4

准确度代码:

# 计算准确度
accuracy <- sum(diag(confusion_matrix)) / sum(confusion_matrix)
accuracy

输出结果:

[1] 0.6
R语言 计算混淆矩阵以及准确度代码

原文地址: https://www.cveoy.top/t/topic/bkvQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录