Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resampled confusion matrix is transposed #372

Closed
topepo opened this issue Apr 21, 2021 · 2 comments
Closed

resampled confusion matrix is transposed #372

topepo opened this issue Apr 21, 2021 · 2 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@topepo
Copy link
Member

topepo commented Apr 21, 2021

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)

@topepo topepo added the bug an unexpected problem or unintended behavior label Apr 21, 2021
topepo added a commit that referenced this issue Apr 21, 2021
topepo added a commit that referenced this issue Apr 21, 2021
fixes for #372 (transposed confusion matrix)
@juliasilge
Copy link
Member

Closed in #373

@github-actions
Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants