I have been using R and caret to produce many machine learning models. I have been producing many Confusion Matrices and results tables.
R does a great job calculating all sorts of measures for outcomes:
- Sensitivity, Specificity, Pos. Pred. Value, Neg. Pred. Value, Prevalence, Detection Rate, Detection Prevalence, Balanced Accuracy
I know the formula for MCC and could calculate it from the original confusion matrix BUT is there another method using the results above?
Is there a conversion or trick given (any one of the results above) that would allow me to get the value of MCC?
My alternative is to go through the confusion matrices by hand.
Thanks
Haven't used it myself but there's a single function package for that
Max
3
yardstick
can do that
library(tidymodels)
#> Registered S3 methods overwritten by 'ggplot2':
#> method from
#> [.quosures rlang
#> c.quosures rlang
#> print.quosures rlang
#> Registered S3 method overwritten by 'xts':
#> method from
#> as.zoo.xts zoo
#> ── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────────────────── tidymodels 0.0.2 ──
#> ✔ broom 0.5.1 ✔ purrr 0.3.2
#> ✔ dials 0.0.2 ✔ recipes 0.1.6
#> ✔ dplyr 0.8.0.1 ✔ rsample 0.0.4.9000
#> ✔ ggplot2 3.1.1 ✔ tibble 2.1.3
#> ✔ infer 0.4.0 ✔ yardstick 0.0.2
#> ✔ parsnip 0.0.2.9000
#> ── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────────────────── tidymodels_conflicts() ──
#> ✖ purrr::discard() masks scales::discard()
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag() masks stats::lag()
#> ✖ recipes::step() masks stats::step()
# Two class
data("two_class_example")
mcc(two_class_example, truth, predicted)
#> # A tibble: 1 x 3
#> .metric .estimator .estimate
#> <chr> <chr> <dbl>
#> 1 mcc binary 0.677
table(two_class_example$truth, two_class_example$predicted) %>%
mcc()
#> # A tibble: 1 x 3
#> .metric .estimator .estimate
#> <chr> <chr> <dbl>
#> 1 mcc binary 0.677
# mutliclass example
data(hpc_cv)
table(hpc_cv$obs, hpc_cv$pred) %>%
mcc()
#> # A tibble: 1 x 3
#> .metric .estimator .estimate
#> <chr> <chr> <dbl>
#> 1 mcc multiclass 0.515
Created on 2019-07-01 by the reprex package (v0.2.1)
1 Like
system
Closed
5
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.