Я хочу применить confusionMatrix
к объекту xtabs
с помощью оператора вертикальной черты. Я использовал следующий код
library(tidyverse)
df %>%
xtabs( ~ Observed + Forecasted + Station, data =.) %>%
caret::confusionMatrix(.)
Это дает мне следующую ошибку:
Ошибка в confusionMatrix.table (.): Таблица должна иметь два измерения
Я мог бы применить его для отдельных станций, например
df %>% subset(Station == "Aizawl") %>%
xtabs( ~ Observed + Forecasted, data =.) %>%
caret::confusionMatrix(.)
Теперь, как вычислить confusionMatrix
для всех станций одновременно?
Данные
df = structure(list(Station = c("Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl", "Aizawl",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip",
"Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip", "Serchhip"
), Observed = c(1, 1, 1, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1,
1, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 3, 3, 4, 1, 1, 4, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1,
4, 4, 4, 3, 4, 1, 1, 1, 1, 1, 3, 5, 5, 5, 3, 1, 1, 3, 1, 1, 1,
1, 1, 5, 3, 4, 1, 1, 1, 1, 1, 3, 1, 4, 1, 1, 1, 1, 1, 4, 4, 5,
1, 5, 4, 5, 5, 5, 5, 1, 5, 1, 4, 5, 4, 4, 5, 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