Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/plot_probabilities_ecdf.R

Plots the empirical cumulative distribution function (ECDF) for the probabilities of either the target classes or the predicted classes.

Creates a `ggplot2`

with the `stat_ecdf()`

geom.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ```
plot_probabilities_ecdf(
data,
target_col,
probability_cols,
predicted_class_col = NULL,
obs_id_col = NULL,
group_col = NULL,
probability_of = "target",
positive = 2,
theme_fn = ggplot2::theme_minimal,
color_scale = ggplot2::scale_colour_brewer(palette = "Dark2"),
apply_facet = length(probability_cols) > 1,
add_caption = TRUE,
ecdf_settings = list(),
facet_settings = list(),
xlim = c(0, 1)
)
``` |

`data` |
Example for binary classification:
Example for multiclass classification:
As created with the various validation functions in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`target_col` |
Name of column with target levels. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`probability_cols` |
Name of columns with predicted probabilities. For For | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`predicted_class_col` |
Name of column with predicted classes. This is required when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`obs_id_col` |
Name of column with observation identifiers for averaging the
predicted probabilities per observation before computing the ECDF ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`group_col` |
Name of column with groups. The plot elements are split by these groups and can be identified by their color. E.g. the
``color_scale`` might run out of colors. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`probability_of` |
Whether to plot the ECDF for the probabilities of the
target classes ( For each row, we extract the probability of either the
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`positive` |
TODO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`theme_fn` |
The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`color_scale` |
E.g. the output of
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`apply_facet` |
Whether to use
By default, faceting is applied when there are more than one probability column (multiclass). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`add_caption` |
Whether to add a caption explaining the plot. This is dynamically generated and intended as a starting point. (Logical) You can overwrite the text with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`ecdf_settings` |
Named list of arguments for The Any argument not in the list will use the default value set by Defaults: Common changes are to set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`facet_settings` |
Named list of arguments for The Any argument not in the list will use its default value. Commonly set arguments are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

`xlim` |
Limits for the x-scale. |

TODO

A `ggplot2`

object with a faceted line plot. TODO

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

Other plotting functions:
`font()`

,
`plot_confusion_matrix()`

,
`plot_metric_density()`

,
`plot_probabilities()`

,
`sum_tile_settings()`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | ```
# Attach cvms
library(cvms)
library(ggplot2)
library(dplyr)
#
# Multiclass
#
# TODO: Go through and rewrite comments and code!
# Plot probabilities of target classes
# From repeated cross-validation of three classifiers
# plot_probabilities_ecdf(
# data = predicted.musicians,
# target_col = "Target",
# probability_cols = c("A", "B", "C", "D"),
# predicted_class_col = "Predicted Class",
# group_col = "Classifier",
# probability_of = "target"
# )
# Plot probabilities of predicted classes
# From repeated cross-validation of three classifiers
# plot_probabilities_ecdf(
# data = predicted.musicians,
# target_col = "Target",
# probability_cols = c("A", "B", "C", "D"),
# predicted_class_col = "Predicted Class",
# group_col = "Classifier",
# probability_of = "prediction"
# )
#
# Binary
#
# Filter the predicted.musicians dataset
# binom_data <- predicted.musicians %>%
# dplyr::filter(
# Target %in% c("A", "B")
# ) %>%
# # "B" is the second class alphabetically
# dplyr::rename(Probability = B) %>%
# dplyr::mutate(`Predicted Class` = ifelse(
# Probability > 0.5, "B", "A")) %>%
# dplyr::select(-c("A","C","D"))
# Plot probabilities of predicted classes
# From repeated cross-validation of three classifiers
# plot_probabilities_ecdf(
# data = binom_data,
# target_col = "Target",
# probability_cols = "Probability",
# predicted_class_col = "Predicted Class",
# group_col = "Classifier",
# probability_of = "target"
# )
# plot_probabilities_ecdf(
# data = binom_data,
# target_col = "Target",
# probability_cols = "Probability",
# predicted_class_col = "Predicted Class",
# group_col = "Classifier",
# probability_of = "prediction",
# xlim = c(0.5, 1)
# )
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.