为什么我在 R 中收到这个混淆矩阵的错误?
Why am I getting error for this confusion matrix in R?
我使用的是二进制值 "Mpg01",其中 Mpg01 描述了如果里程超过数据的中位数则为 1,否则为 0:
我有 运行 逻辑回归,但是在创建混淆矩阵时:我收到以下错误:
输入:
table(carslogic$Mpg01, predict > 0.5)
Output:
> table(carslogic$Mpg01, predict > 0.5)
Error in predict > 0.5 :
comparison (6) is possible only for atomic and list types
出现此错误的原因是什么?我该如何解决?
也许你应该使用 predict() > 0.5
以此为例
data(mtcars)
fit <- glm((cyl>4) ~ mpg, data=mtcars )
table((mtcars$cyl>4), predict(fit)>0.5)
FALSE TRUE
FALSE 9 2
TRUE 0 21
我使用的是二进制值 "Mpg01",其中 Mpg01 描述了如果里程超过数据的中位数则为 1,否则为 0: 我有 运行 逻辑回归,但是在创建混淆矩阵时:我收到以下错误:
输入:
table(carslogic$Mpg01, predict > 0.5)
Output:
> table(carslogic$Mpg01, predict > 0.5)
Error in predict > 0.5 :
comparison (6) is possible only for atomic and list types
出现此错误的原因是什么?我该如何解决?
也许你应该使用 predict() > 0.5 以此为例
data(mtcars)
fit <- glm((cyl>4) ~ mpg, data=mtcars )
table((mtcars$cyl>4), predict(fit)>0.5)
FALSE TRUE
FALSE 9 2
TRUE 0 21