autoplot.mirvie_learning_curve: Produce a learning curve plot from a mirvie_learning_curve...

Description Usage Arguments Value Examples

Description

This is a method for ggplot2::autoplot().

Usage

1
2
## S3 method for class 'mirvie_learning_curve'
autoplot(object, metric = NULL, smooth = FALSE, meansd = FALSE, ...)

Arguments

object

A mirvie_learning_curve object (i.e. the output of a call to learn_curve()).

metric

A string. The metric used to evaluate the performance.

smooth

A flag. Use a loess smoothed line instead of joining the dots?

meansd

A flag. If there are multiple repeats, rather than plotting all of them, plot means with standard deviation error bars?

...

Arguments passed to ggplot2::autoplot(). Safe to ignore.

Value

A ggplot2::ggplot().

Examples

 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
data("BostonHousing", package = "mlbench")
bh <- dplyr::select_if(BostonHousing, is.numeric)
model_evaluate <- function(training_data, testing_data) {
  trained_mod <- lm(medv ~ ., training_data)
  training_preds <- predict(trained_mod, newdata = training_data)
  preds <- predict(trained_mod, newdata = testing_data)
  c(
    train = yardstick::mae_vec(training_data$medv, training_preds),
    test = yardstick::mae_vec(testing_data$medv, preds)
  )
}
mlc <- mlc0 <- suppressWarnings(
  learn_curve(model_evaluate, bh, "medv",
    training_fracs = c(seq(0.1, 0.7, 0.2), 0.85),
    testing_frac = c(0.25, 0.5), repeats = 8,
    strata = "medv"
  )
)
suppressWarnings(print(autoplot(mlc, metric = "mae")))
suppressWarnings(print(autoplot(mlc, metric = "mae", smooth = TRUE)))
suppressWarnings(print(autoplot(mlc, metric = "mae", meansd = TRUE)))
suppressWarnings(
  print(autoplot(mlc, metric = "mae", smooth = TRUE, meansd = TRUE))
)
mlc <- dplyr::filter(mlc0, testing_frac == 0.25)
suppressWarnings(print(autoplot(mlc, metric = "mae")))
suppressWarnings(print(autoplot(mlc, metric = "mae", smooth = TRUE)))
suppressWarnings(print(autoplot(mlc, metric = "mae", meansd = TRUE)))
suppressWarnings(
  print(autoplot(mlc, metric = "mae", smooth = TRUE, meansd = TRUE))
)
mlc <- dplyr::filter(mlc0, rep == 1)
suppressWarnings(print(autoplot(mlc, metric = "mae")))
suppressWarnings(print(autoplot(mlc, metric = "mae", smooth = TRUE)))
mlc <- dplyr::filter(mlc0, rep == 1, testing_frac == 0.25)
suppressWarnings(print(autoplot(mlc, metric = "mae")))
suppressWarnings(print(autoplot(mlc, metric = "mae", smooth = TRUE)))
bh_split <- rsample::initial_split(bh, strata = medv)
bh_training <- rsample::training(bh_split)
bh_testing <- rsample::testing(bh_split)
mlc <- learn_curve(model_evaluate,
  training_data = bh_training,
  outcome = "medv", testing_data = bh_testing,
  strata = "medv"
)
suppressWarnings(print(autoplot(mlc)))
suppressWarnings(print(autoplot(mlc, smooth = TRUE)))

mirvie/mirmodels documentation built on Jan. 14, 2022, 11:12 a.m.