Skip to content

resampled confusion matrix is transposed #372

Closed

Description

@topepo

With conf_mat_resamped(tidy = FALSE), the matrix is transposed.

library(tidymodels)

set.seed(1)
tr <- AppliedPredictiveModeling::easyBoundaryFunc(500, intercept = 6)
te <- AppliedPredictiveModeling::easyBoundaryFunc(500, intercept = 6)

table(tr$class)
#> 
#> Class1 Class2 
#>    450     50
tr$prob <- NULL

set.seed(1)
rs <- vfold_cv(tr)

mod <- rand_forest() %>% set_engine("randomForest") %>% set_mode("classification")

set.seed(1)
res <-
  mod %>%
  fit_resamples(class ~ .,
                resamples = rs,
                control = control_resamples(save_pred = TRUE))

mod %>% 
  fit(class ~ ., data = tr) %>% 
  predict(te) %>% 
  bind_cols(te) %>% 
  conf_mat(truth = class, estimate = .pred_class)
#>           Truth
#> Prediction Class1 Class2
#>     Class1    440     17
#>     Class2      6     37

conf_mat_resampled(res)
#> # A tibble: 4 x 3
#>   Prediction Truth   Freq
#>   <fct>      <fct>  <dbl>
#> 1 Class1     Class1  44.5
#> 2 Class1     Class2   1.9
#> 3 Class2     Class1   0.5
#> 4 Class2     Class2   3.1
# Truth in columns, predictions in row
conf_mat_resampled(res, tidy = FALSE)
#>        Class1 Class2
#> Class1   44.5    0.5
#> Class2    1.9    3.1

Created on 2021-04-21 by the reprex package (v1.0.0.9000)

Activity

  1. added
    bugan unexpected problem or unintended behavior
    on Apr 21, 2021
  2. added 2 commits that reference this issue on Apr 21, 2021
  3. juliasilge commented on Apr 28, 2021

    @juliasilge
    Member

    Closed in #373

  4. github-actions commented on May 13, 2021

    @github-actions
    Contributor

    This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

  5. locked and limited conversation to collaborators on May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions