R package caret confusionMatrix with missing categories

前端 未结 3 2032
一生所求
一生所求 2021-01-04 16:35

I am using the function confusionMatrix in the R package caret to calculate some statistics for some data I have. I have been put

3条回答
  •  盖世英雄少女心
    2021-01-04 16:44

    You can use union to ensure similar levels:

    library(caret)
    
    # Sample Data
    predicted <- c(1,2,1,2,1,2,1,2,3,4,3,4,6,5) # Levels 1,2,3,4,5,6
    reference <- c(1,2,1,2,1,2,1,2,1,2,1,3,3,4) # Levels 1,2,3,4
    
    u <- union(predicted, reference)
    t <- table(factor(predicted, u), factor(reference, u))
    confusionMatrix(t)
    

提交回复
热议问题