Title: | Visualizations for 'mlr3' |
---|---|
Description: | Visualization package of the 'mlr3' ecosystem. It features plots for mlr3 objects such as tasks, learners, predictions, benchmark results, tuning instances and filters via the 'autoplot()' generic of 'ggplot2'. The package draws plots with the 'viridis' color palette and applies the minimal theme. Visualizations include barplots, boxplots, histograms, ROC curves, and Precision-Recall curves. |
Authors: | Michel Lang [aut] , Patrick Schratz [aut] , Raphael Sonabend [aut] , Marc Becker [cre, aut] , Jakob Richter [aut] , Damir Pulatov [ctb], John Zobolas [aut] |
Maintainer: | Marc Becker <[email protected]> |
License: | LGPL-3 |
Version: | 0.10.0 |
Built: | 2024-12-08 07:21:06 UTC |
Source: | CRAN |
Visualization package of the 'mlr3' ecosystem. It features plots for mlr3 objects such as tasks, learners, predictions, benchmark results, tuning instances and filters via the 'autoplot()' generic of 'ggplot2'. The package draws plots with the 'viridis' color palette and applies the minimal theme. Visualizations include barplots, boxplots, histograms, ROC curves, and Precision-Recall curves.
Maintainer: Marc Becker [email protected] (ORCID)
Authors:
Michel Lang [email protected] (ORCID)
Patrick Schratz [email protected] (ORCID)
Raphael Sonabend [email protected] (ORCID)
Jakob Richter [email protected] (ORCID)
John Zobolas [email protected] (ORCID)
Other contributors:
Damir Pulatov [email protected] [contributor]
Useful links:
Report bugs at https://github.com/mlr-org/mlr3viz/issues
Converts to a format which is understood by precrec::evalmod()
of package precrec.
as_precrec(object) ## S3 method for class 'PredictionClassif' as_precrec(object) ## S3 method for class 'ResampleResult' as_precrec(object) ## S3 method for class 'BenchmarkResult' as_precrec(object)
as_precrec(object) ## S3 method for class 'PredictionClassif' as_precrec(object) ## S3 method for class 'ResampleResult' as_precrec(object) ## S3 method for class 'BenchmarkResult' as_precrec(object)
object |
( |
Object as created by precrec::mmdata()
.
Saito T, Rehmsmeier M (2017). “Precrec: fast and accurate precision-recall and ROC curve calculations in R.” Bioinformatics, 33(1), 145-147. doi:10.1093/bioinformatics/btw570.
Visualizations for mlr3::BenchmarkResult.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"boxplot"
(default): Boxplots of performance measures, one box per mlr3::Learner and one facet per mlr3::Task.
"roc"
: ROC curve (1 - specificity on x, sensitivity on y).
The mlr3::BenchmarkResult may only have a single mlr3::Task and a single mlr3::Resampling.
Note that you can subset any mlr3::BenchmarkResult with its $filter()
method (see examples).
Requires package precrec.
"prc"
: Precision recall curve.
See "roc"
.
## S3 method for class 'BenchmarkResult' autoplot( object, type = "boxplot", measure = NULL, theme = theme_minimal(), ... )
## S3 method for class 'BenchmarkResult' autoplot( object, type = "boxplot", measure = NULL, theme = theme_minimal(), ... )
object |
|
type |
(character(1)): |
measure |
(mlr3::Measure) |
theme |
( |
... |
(ignored). |
Saito T, Rehmsmeier M (2017). “Precrec: fast and accurate precision-recall and ROC curve calculations in R.” Bioinformatics, 33(1), 145-147. doi:10.1093/bioinformatics/btw570.
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) tasks = tsks(c("pima", "sonar")) learner = lrns(c("classif.featureless", "classif.rpart"), predict_type = "prob") resampling = rsmps("cv") object = benchmark(benchmark_grid(tasks, learner, resampling)) head(fortify(object)) autoplot(object) autoplot(object$clone(deep = TRUE)$filter(task_ids = "pima"), type = "roc") }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) tasks = tsks(c("pima", "sonar")) learner = lrns(c("classif.featureless", "classif.rpart"), predict_type = "prob") resampling = rsmps("cv") object = benchmark(benchmark_grid(tasks, learner, resampling)) head(fortify(object)) autoplot(object) autoplot(object$clone(deep = TRUE)$filter(task_ids = "pima"), type = "roc") }
Visualizations for EnsembleFSResult.
The argument type
determines the type of plot generated.
The available options are:
"pareto"
(default): Scatterplot of performance versus the number of
features, possibly including the Pareto front, which allows users to
decide how much performance they are willing to trade off for a more sparse
model.
"performance"
: Boxplot of performance across the different learners
used in the ensemble feature selection process.
Each box represents the distribution of scores across different resampling
iterations for a particular learner.
"n_features
: Boxplot of the number of features selected by each learner
in the different resampling iterations.
"stability"
: Barplot of stability score for each learner used in the
ensemble feature selection. This plot shows how similar are the output feature
sets from each learner across the different resamplings.
## S3 method for class 'EnsembleFSResult' autoplot( object, type = "pareto", pareto_front = "stepwise", stability_measure = "jaccard", stability_args = NULL, theme = theme_minimal(), ... )
## S3 method for class 'EnsembleFSResult' autoplot( object, type = "pareto", pareto_front = "stepwise", stability_measure = "jaccard", stability_args = NULL, theme = theme_minimal(), ... )
object |
|
type |
(character(1)): |
pareto_front |
( |
stability_measure |
( |
stability_args |
( |
theme |
( |
... |
(ignored). |
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3fselect) set.seed (42) efsr = ensemble_fselect( fselector = fs("random_search"), task = tsk("sonar"), learners = lrns(c("classif.rpart", "classif.featureless")), init_resampling = rsmp("subsampling", repeats = 5), inner_resampling = rsmp("cv", folds = 3), measure = msr("classif.ce"), terminator = trm("evals", n_evals = 5) ) # Pareto front (default, stepwise) autoplot(efsr) # Pareto front (estimated) autoplot(efsr, pareto_front = "estimated") # Performance autoplot(efsr, type = "performance") # Number of features autoplot(efsr, type = "n_features") # stability autoplot(efsr, type = "stability") }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3fselect) set.seed (42) efsr = ensemble_fselect( fselector = fs("random_search"), task = tsk("sonar"), learners = lrns(c("classif.rpart", "classif.featureless")), init_resampling = rsmp("subsampling", repeats = 5), inner_resampling = rsmp("cv", folds = 3), measure = msr("classif.ce"), terminator = trm("evals", n_evals = 5) ) # Pareto front (default, stepwise) autoplot(efsr) # Pareto front (estimated) autoplot(efsr, pareto_front = "estimated") # Performance autoplot(efsr, type = "performance") # Number of features autoplot(efsr, type = "n_features") # stability autoplot(efsr, type = "stability") }
Visualizations for mlr3filters::Filter.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"barplot"
(default): Bar plot of filter scores.
## S3 method for class 'Filter' autoplot(object, type = "boxplot", n = Inf, theme = theme_minimal(), ...)
## S3 method for class 'Filter' autoplot(object, type = "boxplot", n = Inf, theme = theme_minimal(), ...)
object |
|
type |
(character(1)): |
n |
( |
theme |
( |
... |
(ignored). |
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) library(mlr3filters) task = tsk("mtcars") f = flt("correlation") f$calculate(task) head(fortify(f)) autoplot(f, n = 5) }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) library(mlr3filters) task = tsk("mtcars") f = flt("correlation") f$calculate(task) head(fortify(f)) autoplot(f, n = 5) }
Visualizations for mlr3::LearnerClassif.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"prediction"
(default): Decision boundary of the learner and the true class labels.
## S3 method for class 'LearnerClassif' autoplot( object, type = "prediction", task, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... )
## S3 method for class 'LearnerClassif' autoplot( object, type = "prediction", task, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... )
object |
|
type |
(character(1)): |
task |
(mlr3::Task) |
grid_points |
(integer(1)) |
expand_range |
(numeric(1)) |
theme |
( |
... |
(ignored). |
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("pima")$select(c("age", "pedigree")) learner = lrn("classif.rpart", predict_type = "prob") learner$train(task) autoplot(learner, type = "prediction", task) }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("pima")$select(c("age", "pedigree")) learner = lrn("classif.rpart", predict_type = "prob") learner$train(task) autoplot(learner, type = "prediction", task) }
Visualizations for mlr3learners::LearnerClassifGlmnet.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"prediction"
(default): Decision boundary of the learner and the true class labels.
"ggfortify"
: Visualizes the model using the package ggfortify.
## S3 method for class 'LearnerClassifCVGlmnet' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... ) ## S3 method for class 'LearnerClassifGlmnet' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... ) ## S3 method for class 'LearnerRegrCVGlmnet' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... ) ## S3 method for class 'LearnerRegrGlmnet' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... )
## S3 method for class 'LearnerClassifCVGlmnet' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... ) ## S3 method for class 'LearnerClassifGlmnet' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... ) ## S3 method for class 'LearnerRegrCVGlmnet' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... ) ## S3 method for class 'LearnerRegrGlmnet' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... )
object |
(mlr3learners::LearnerClassifGlmnet | mlr3learners::LearnerRegrGlmnet | mlr3learners::LearnerRegrCVGlmnet | mlr3learners::LearnerRegrCVGlmnet). |
type |
(character(1)): |
task |
(mlr3::Task) |
grid_points |
(integer(1)) |
expand_range |
(numeric(1)) |
theme |
( |
... |
(ignored). |
Tang Y, Horikoshi M, Li W (2016). “ggfortify: Unified Interface to Visualize Statistical Result of Popular R Packages.” The R Journal, 8(2), 474–485. doi:10.32614/RJ-2016-060.
## Not run: library(mlr3) library(mlr3viz) library(mlr3learners) # classification task = tsk("sonar") learner = lrn("classif.glmnet") learner$train(task) autoplot(learner, type = "ggfortify") # regression task = tsk("mtcars") learner = lrn("regr.glmnet") learner$train(task) autoplot(learner, type = "ggfortify") ## End(Not run)
## Not run: library(mlr3) library(mlr3viz) library(mlr3learners) # classification task = tsk("sonar") learner = lrn("classif.glmnet") learner$train(task) autoplot(learner, type = "ggfortify") # regression task = tsk("mtcars") learner = lrn("regr.glmnet") learner$train(task) autoplot(learner, type = "ggfortify") ## End(Not run)
Visualizations for mlr3::LearnerClassifRpart.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"prediction"
(default): Decision boundary of the learner and the true class labels.
"ggparty"
: Visualizes the tree using the package ggparty.
## S3 method for class 'LearnerClassifRpart' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... ) ## S3 method for class 'LearnerRegrRpart' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... )
## S3 method for class 'LearnerClassifRpart' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... ) ## S3 method for class 'LearnerRegrRpart' autoplot( object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... )
object |
|
type |
(character(1)): |
task |
(mlr3::Task) |
grid_points |
(integer(1)) |
expand_range |
(numeric(1)) |
theme |
( |
... |
(ignored). |
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) # classification task = tsk("iris") learner = lrn("classif.rpart", keep_model = TRUE) learner$train(task) autoplot(learner, type = "ggparty") # regression task = tsk("mtcars") learner = lrn("regr.rpart", keep_model = TRUE) learner$train(task) autoplot(learner, type = "ggparty") }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) # classification task = tsk("iris") learner = lrn("classif.rpart", keep_model = TRUE) learner$train(task) autoplot(learner, type = "ggparty") # regression task = tsk("mtcars") learner = lrn("regr.rpart", keep_model = TRUE) learner$train(task) autoplot(learner, type = "ggparty") }
Visualizations for hierarchical clusters.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"dend"
(default): Dendrograms using ggdendro package.
"scree"
: Scree plot that shows the number of possible clusters on the x-axis and the height on the y-axis.
## S3 method for class 'LearnerClustHierarchical' autoplot( object, type = "dend", task = NULL, theme = theme_minimal(), theme_dendro = TRUE, ... )
## S3 method for class 'LearnerClustHierarchical' autoplot( object, type = "dend", task = NULL, theme = theme_minimal(), theme_dendro = TRUE, ... )
object |
(mlr3cluster::LearnerClustAgnes | mlr3cluster::LearnerClustDiana | mlr3cluster::LearnerClustHclust). |
type |
(character(1)): |
task |
(mlr3::Task) |
theme |
( |
theme_dendro |
( |
... |
(ignored). |
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3cluster) library(mlr3viz) task = tsk("usarrests") # agnes clustering learner = lrn("clust.agnes") learner$train(task) autoplot(learner) # diana clustering learner = lrn("clust.diana") learner$train(task) autoplot(learner) # hclust clustering learner = lrn("clust.hclust") learner$train(task) autoplot(learner, type = "scree") }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3cluster) library(mlr3viz) task = tsk("usarrests") # agnes clustering learner = lrn("clust.agnes") learner$train(task) autoplot(learner) # diana clustering learner = lrn("clust.diana") learner$train(task) autoplot(learner) # hclust clustering learner = lrn("clust.hclust") learner$train(task) autoplot(learner, type = "scree") }
Visualizations for mlr3::LearnerRegr.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"prediction"
(default): Decision boundary of the learner and the true class labels.
## S3 method for class 'LearnerRegr' autoplot( object, type = "prediction", task, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... )
## S3 method for class 'LearnerRegr' autoplot( object, type = "prediction", task, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ... )
object |
|
type |
(character(1)): |
task |
(mlr3::Task) |
grid_points |
(integer(1)) |
expand_range |
(numeric(1)) |
theme |
( |
... |
(ignored). |
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("mtcars")$select(c("am", "carb")) learner = lrn("regr.rpart") learner$train(task) autoplot(learner, type = "prediction", task) }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("mtcars")$select(c("am", "carb")) learner = lrn("regr.rpart") learner$train(task) autoplot(learner, type = "prediction", task) }
Visualizations for mlr3proba::LearnerSurvCoxPH.
The argument type
controls what kind of plot is drawn.
The only possible choice right now is "ggforest"
(default) which is a
Forest Plot, using ggforest.
This plot displays the estimated hazard ratios (HRs) and their confidence
intervals (CIs) for different variables included in the (trained) model.
## S3 method for class 'LearnerSurvCoxPH' autoplot(object, type = "ggforest", ...)
## S3 method for class 'LearnerSurvCoxPH' autoplot(object, type = "ggforest", ...)
object |
|
type |
(character(1)): |
... |
Additional parameters passed down to |
if (requireNamespace("mlr3proba")) { library(mlr3proba) library(mlr3viz) task = tsk("lung") learner = lrn("surv.coxph") learner$train(task) autoplot(learner) }
if (requireNamespace("mlr3proba")) { library(mlr3proba) library(mlr3viz) task = tsk("lung") learner = lrn("surv.coxph") learner$train(task) autoplot(learner) }
Visualizations for bbotk::OptimInstanceBatchSingleCrit.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"marginal"
(default): Scatter plots of x versus y.
The color of the points shows the batch number.
"performance"
: Scatter plots of batch number versus y
"parameter"
: Scatter plots of batch number versus input.
The color of the points shows the y values.
"parallel"
: Parallel coordinates plot.
x values are rescaled by (x - mean(x)) / sd(x)
.
"points"
: Scatter plot of two x dimensions versus.
The color of the points shows the y values.
"surface"
: Surface plot of two x dimensions versus y values.
The y values are interpolated with the supplied mlr3::Learner.
"pairs"
: Plots all x and y values against each other.
"incumbent"
: Plots the incumbent versus the number of configurations.
## S3 method for class 'OptimInstanceBatchSingleCrit' autoplot( object, type = "marginal", cols_x = NULL, trafo = FALSE, learner = mlr3::lrn("regr.ranger"), grid_resolution = 100, batch = NULL, theme = theme_minimal(), ... )
## S3 method for class 'OptimInstanceBatchSingleCrit' autoplot( object, type = "marginal", cols_x = NULL, trafo = FALSE, learner = mlr3::lrn("regr.ranger"), grid_resolution = 100, batch = NULL, theme = theme_minimal(), ... )
object |
|
type |
(character(1)): |
cols_x |
( |
trafo |
( |
learner |
(mlr3::Learner) |
grid_resolution |
( |
batch |
( |
theme |
( |
... |
(ignored). |
if (requireNamespace("mlr3") && requireNamespace("bbotk") && requireNamespace("patchwork")) { library(bbotk) library(paradox) fun = function(xs) { c(y = -(xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10) } domain = ps( x1 = p_dbl(-10, 10), x2 = p_dbl(-5, 5) ) codomain = ps( y = p_dbl(tags = "maximize") ) obfun = ObjectiveRFun$new( fun = fun, domain = domain, codomain = codomain ) instance = oi(objective = obfun, terminator = trm("evals", n_evals = 20)) optimizer = opt("random_search", batch_size = 2) optimizer$optimize(instance) # plot y versus batch number print(autoplot(instance, type = "performance")) # plot x1 values versus performance print(autoplot(instance, type = "marginal", cols_x = "x1")) # plot parallel coordinates plot print(autoplot(instance, type = "parallel")) # plot pairs print(autoplot(instance, type = "pairs")) # plot incumbent print(autoplot(instance, type = "incumbent")) }
if (requireNamespace("mlr3") && requireNamespace("bbotk") && requireNamespace("patchwork")) { library(bbotk) library(paradox) fun = function(xs) { c(y = -(xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10) } domain = ps( x1 = p_dbl(-10, 10), x2 = p_dbl(-5, 5) ) codomain = ps( y = p_dbl(tags = "maximize") ) obfun = ObjectiveRFun$new( fun = fun, domain = domain, codomain = codomain ) instance = oi(objective = obfun, terminator = trm("evals", n_evals = 20)) optimizer = opt("random_search", batch_size = 2) optimizer$optimize(instance) # plot y versus batch number print(autoplot(instance, type = "performance")) # plot x1 values versus performance print(autoplot(instance, type = "marginal", cols_x = "x1")) # plot parallel coordinates plot print(autoplot(instance, type = "parallel")) # plot pairs print(autoplot(instance, type = "pairs")) # plot incumbent print(autoplot(instance, type = "incumbent")) }
Visualizations for mlr3::PredictionClassif.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"stacked"
(default): Stacked barplot of true and estimated class labels.
"roc"
: ROC curve (1 - specificity on x, sensitivity on y).
Requires package precrec.
"prc"
: Precision recall curve.
Requires package precrec.
"threshold"
: Systematically varies the threshold of the mlr3::PredictionClassif object and plots the resulting performance as returned by measure
.
## S3 method for class 'PredictionClassif' autoplot( object, type = "stacked", measure = NULL, theme = theme_minimal(), ... )
## S3 method for class 'PredictionClassif' autoplot( object, type = "stacked", measure = NULL, theme = theme_minimal(), ... )
object |
|
type |
(character(1)): |
measure |
(mlr3::Measure) |
theme |
( |
... |
(ignored). |
Saito T, Rehmsmeier M (2017). “Precrec: fast and accurate precision-recall and ROC curve calculations in R.” Bioinformatics, 33(1), 145-147. doi:10.1093/bioinformatics/btw570.
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("spam") learner = lrn("classif.rpart", predict_type = "prob") object = learner$train(task)$predict(task) head(fortify(object)) autoplot(object) autoplot(object, type = "roc") autoplot(object, type = "prc") }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("spam") learner = lrn("classif.rpart", predict_type = "prob") object = learner$train(task)$predict(task) head(fortify(object)) autoplot(object) autoplot(object, type = "roc") autoplot(object, type = "prc") }
Visualizations for mlr3cluster::PredictionClust.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"scatter"
(default): scatterplot with correlation values and colored cluster assignments.
"sil"
: Silhouette plot with mean silhouette value as the reference line.
Requires package ggfortify.
"pca"
: Perform PCA on data and color code cluster assignments.
Inspired by and uses ggfortify::autoplot.kmeans.
## S3 method for class 'PredictionClust' autoplot( object, task, row_ids = NULL, type = "scatter", theme = theme_minimal(), ... )
## S3 method for class 'PredictionClust' autoplot( object, task, row_ids = NULL, type = "scatter", theme = theme_minimal(), ... )
object |
|
task |
|
row_ids |
( |
type |
(character(1)): |
theme |
( |
... |
(ignored). |
Tang Y, Horikoshi M, Li W (2016). “ggfortify: Unified Interface to Visualize Statistical Result of Popular R Packages.” The R Journal, 8(2), 474–485. doi:10.32614/RJ-2016-060.
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3cluster) library(mlr3viz) task = tsk("usarrests") learner = lrn("clust.kmeans", centers = 3) object = learner$train(task)$predict(task) head(fortify(object)) autoplot(object, task) }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3cluster) library(mlr3viz) task = tsk("usarrests") learner = lrn("clust.kmeans", centers = 3) object = learner$train(task)$predict(task) head(fortify(object)) autoplot(object, task) }
Visualizations for mlr3::PredictionRegr.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"xy"
(default): Scatterplot of "true" response vs. "predicted" response.
By default a linear model is fitted via geom_smooth(method = "lm")
to visualize the trend between x and y (by default colored blue).
In addition geom_abline()
with slope = 1
is added to the plot.
Note that geom_smooth()
and geom_abline()
may overlap, depending on the given data.
"histogram"
: Histogram of residuals: .
"residual"
: Plot of the residuals, with the response on the "x" and the residuals on the "y" axis.
By default a linear model is fitted via
geom_smooth(method = "lm")
to visualize the trend between x and y (by default colored blue).
"confidence
: Scatterplot of "true" response vs. "predicted" response with
confidence intervals. Error bars calculated as object$reponse +- quantile * object$se and so only
possible with predict_type = "se"
. geom_abline()
with slope = 1
is added to the plot.
## S3 method for class 'PredictionRegr' autoplot( object, type = "xy", binwidth = NULL, theme = theme_minimal(), quantile = 1.96, ... )
## S3 method for class 'PredictionRegr' autoplot( object, type = "xy", binwidth = NULL, theme = theme_minimal(), quantile = 1.96, ... )
object |
|
type |
(character(1)): |
binwidth |
( |
theme |
( |
quantile |
( |
... |
(ignored). |
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("mtcars") learner = lrn("regr.rpart") object = learner$train(task)$predict(task) head(fortify(object)) autoplot(object) autoplot(object, type = "histogram", binwidth = 1) autoplot(object, type = "residual") if (requireNamespace("mlr3learners")) { library(mlr3learners) learner = lrn("regr.ranger", predict_type = "se") object = learner$train(task)$predict(task) autoplot(object, type = "confidence") } }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("mtcars") learner = lrn("regr.rpart") object = learner$train(task)$predict(task) head(fortify(object)) autoplot(object) autoplot(object, type = "histogram", binwidth = 1) autoplot(object, type = "residual") if (requireNamespace("mlr3learners")) { library(mlr3learners) learner = lrn("regr.ranger", predict_type = "se") object = learner$train(task)$predict(task) autoplot(object, type = "confidence") } }
Visualizations for mlr3::ResampleResult.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"boxplot"
(default): Boxplot of performance measures.
"histogram"
: Histogram of performance measures.
"roc"
: ROC curve (1 - specificity on x, sensitivity on y).
The predictions of the individual mlr3::Resamplings are merged prior to calculating the ROC curve (micro averaged).
Requires package precrec.
"prc"
: Precision recall curve.
See "roc"
.
"prediction"
: Plots the learner prediction for a grid of points.
Needs models to be stored. Set store_models = TRUE
for [mlr3::resample]
.
For classification, we support tasks with exactly two features and learners with predict_type=
set to "response"
or "prob"
.
For regression, we support tasks with one or two features.
For tasks with one feature we can print confidence bounds if the predict type of the learner was set to "se"
.
For tasks with two features the predict type will be ignored.
## S3 method for class 'ResampleResult' autoplot( object, type = "boxplot", measure = NULL, predict_sets = "test", binwidth = NULL, theme = theme_minimal(), ... )
## S3 method for class 'ResampleResult' autoplot( object, type = "boxplot", measure = NULL, predict_sets = "test", binwidth = NULL, theme = theme_minimal(), ... )
object |
|
type |
(character(1)): |
measure |
(mlr3::Measure) |
predict_sets |
( |
binwidth |
( |
theme |
( |
... |
(ignored). |
Saito T, Rehmsmeier M (2017). “Precrec: fast and accurate precision-recall and ROC curve calculations in R.” Bioinformatics, 33(1), 145-147. doi:10.1093/bioinformatics/btw570.
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("sonar") learner = lrn("classif.rpart", predict_type = "prob") resampling = rsmp("cv", folds = 3) object = resample(task, learner, resampling) head(fortify(object)) # Default: boxplot autoplot(object) # Histogram autoplot(object, type = "histogram", bins = 30) # ROC curve, averaged over resampling folds: autoplot(object, type = "roc") # ROC curve of joint prediction object: autoplot(object$prediction(), type = "roc") # Precision Recall Curve autoplot(object, type = "prc") # Prediction Plot task = tsk("iris")$select(c("Sepal.Length", "Sepal.Width")) resampling = rsmp("cv", folds = 3) object = resample(task, learner, resampling, store_models = TRUE) autoplot(object, type = "prediction") }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("sonar") learner = lrn("classif.rpart", predict_type = "prob") resampling = rsmp("cv", folds = 3) object = resample(task, learner, resampling) head(fortify(object)) # Default: boxplot autoplot(object) # Histogram autoplot(object, type = "histogram", bins = 30) # ROC curve, averaged over resampling folds: autoplot(object, type = "roc") # ROC curve of joint prediction object: autoplot(object$prediction(), type = "roc") # Precision Recall Curve autoplot(object, type = "prc") # Prediction Plot task = tsk("iris")$select(c("Sepal.Length", "Sepal.Width")) resampling = rsmp("cv", folds = 3) object = resample(task, learner, resampling, store_models = TRUE) autoplot(object, type = "prediction") }
Visualizations for mlr3::TaskClassif.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"target"
(default): Bar plot of the target variable (default).
"duo"
: Passes data to GGally::ggduo()
.
columnsX
is the target and columnsY
are the features.
"pairs"
: Passes data to GGally::ggpairs()
.
Color is set to target column.
## S3 method for class 'TaskClassif' autoplot(object, type = "target", theme = theme_minimal(), ...)
## S3 method for class 'TaskClassif' autoplot(object, type = "target", theme = theme_minimal(), ...)
object |
|
type |
(character(1)): |
theme |
( |
... |
(ignored). |
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("iris") head(fortify(task)) autoplot(task) autoplot(task$clone()$select(c("Sepal.Length", "Sepal.Width")), type = "pairs") autoplot(task, type = "duo") }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("iris") head(fortify(task)) autoplot(task) autoplot(task$clone()$select(c("Sepal.Length", "Sepal.Width")), type = "pairs") autoplot(task, type = "duo") }
Visualizations for mlr3cluster::TaskClust.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"pairs"
(default): Passes data GGally::ggpairs()
.
## S3 method for class 'TaskClust' autoplot(object, type = "pairs", theme = theme_minimal(), ...)
## S3 method for class 'TaskClust' autoplot(object, type = "pairs", theme = theme_minimal(), ...)
object |
|
type |
(character(1)): |
theme |
( |
... |
(ignored). |
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3cluster) library(mlr3viz) task = mlr_tasks$get("usarrests") head(fortify(task)) autoplot(task) }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3cluster) library(mlr3viz) task = mlr_tasks$get("usarrests") head(fortify(task)) autoplot(task) }
Visualizations for mlr3::TaskRegr.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"target"
(default): Box plot of the target variable.
"pairs"
: Passes data to GGally::ggpairs()
.
Color is set to target column.
## S3 method for class 'TaskRegr' autoplot(object, type = "target", theme = theme_minimal(), ...)
## S3 method for class 'TaskRegr' autoplot(object, type = "target", theme = theme_minimal(), ...)
object |
|
type |
(character(1)): |
theme |
( |
... |
(ignored). |
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("mtcars") task$select(c("am", "carb")) head(fortify(task)) autoplot(task) autoplot(task, type = "pairs") }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = tsk("mtcars") task$select(c("am", "carb")) head(fortify(task)) autoplot(task) autoplot(task, type = "pairs") }
Visualizations for mlr3tuning::TuningInstanceBatchSingleCrit.
The argument type
controls what kind of plot is drawn.
Possible choices are:
"marginal"
(default): Scatter plots of x versus y.
The color of the points shows the batch number.
"performance"
: Scatter plots of batch number versus y
"parameter"
: Scatter plots of batch number versus input.
The color of the points shows the y values.
"parallel"
: Parallel coordinates plot.
hyperparameters are rescaled by (x - mean(x)) / sd(x)
.
"points"
: Scatter plot of two x dimensions versus.
The color of the points shows the y values.
"surface"
: Surface plot of two x dimensions versus y values.
The y values are interpolated with the supplied mlr3::Learner.
"pairs"
: Plots all x and y values against each other.
"incumbent"
: Plots the incumbent versus the number of configurations.
## S3 method for class 'TuningInstanceBatchSingleCrit' autoplot( object, type = "marginal", cols_x = NULL, trafo = FALSE, learner = mlr3::lrn("regr.ranger"), grid_resolution = 100, theme = theme_minimal(), ... )
## S3 method for class 'TuningInstanceBatchSingleCrit' autoplot( object, type = "marginal", cols_x = NULL, trafo = FALSE, learner = mlr3::lrn("regr.ranger"), grid_resolution = 100, theme = theme_minimal(), ... )
object |
|
type |
(character(1)): |
cols_x |
( |
trafo |
( |
learner |
(mlr3::Learner) |
grid_resolution |
( |
theme |
( |
... |
(ignored). |
if (requireNamespace("mlr3tuning") && requireNamespace("patchwork")) { library(mlr3tuning) learner = lrn("classif.rpart") learner$param_set$values$cp = to_tune(0.001, 0.1) learner$param_set$values$minsplit = to_tune(1, 10) instance = ti( task = tsk("iris"), learner = learner, resampling = rsmp("holdout"), measure = msr("classif.ce"), terminator = trm("evals", n_evals = 10)) tuner = tnr("random_search") tuner$optimize(instance) # plot performance versus batch number autoplot(instance, type = "performance") # plot cp values versus performance autoplot(instance, type = "marginal", cols_x = "cp") # plot transformed parameter values versus batch number autoplot(instance, type = "parameter", trafo = TRUE) # plot parallel coordinates plot autoplot(instance, type = "parallel") # plot pairs autoplot(instance, type = "pairs") }
if (requireNamespace("mlr3tuning") && requireNamespace("patchwork")) { library(mlr3tuning) learner = lrn("classif.rpart") learner$param_set$values$cp = to_tune(0.001, 0.1) learner$param_set$values$minsplit = to_tune(1, 10) instance = ti( task = tsk("iris"), learner = learner, resampling = rsmp("holdout"), measure = msr("classif.ce"), terminator = trm("evals", n_evals = 10)) tuner = tnr("random_search") tuner$optimize(instance) # plot performance versus batch number autoplot(instance, type = "performance") # plot cp values versus performance autoplot(instance, type = "marginal", cols_x = "cp") # plot transformed parameter values versus batch number autoplot(instance, type = "parameter", trafo = TRUE) # plot parallel coordinates plot autoplot(instance, type = "parallel") # plot pairs autoplot(instance, type = "pairs") }
Visualizations for the mlr3::Prediction of a single mlr3::Learner on a single mlr3::Task.
For classification we support tasks with exactly two features and learners with predict_type
set to "response"
or "prob"
.
For regression we support tasks with one or two features.
For tasks with one feature we print confidence bounds if the predict type of the learner was set to "se"
.
For tasks with two features the predict type will be ignored.
Note that this function is a wrapper around autoplot.ResampleResult()
for a temporary mlr3::ResampleResult using mlr3::mlr_resamplings_holdout with ratio 1 (all observations in the training set).
plot_learner_prediction(learner, task, grid_points = 100L, expand_range = 0)
plot_learner_prediction(learner, task, grid_points = 100L, expand_range = 0)
learner |
|
task |
(mlr3::Task). |
grid_points |
( |
expand_range |
( |
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = mlr3::tsk("pima")$select(c("age", "glucose")) learner = lrn("classif.rpart", predict_type = "prob") p = plot_learner_prediction(learner, task) print(p) }
if (requireNamespace("mlr3")) { library(mlr3) library(mlr3viz) task = mlr3::tsk("pima")$select(c("age", "glucose")) learner = lrn("classif.rpart", predict_type = "prob") p = plot_learner_prediction(learner, task) print(p) }
For each point we have the predicted class / regression value in column response. If the learner predicts probabilities, a column ".prob.response" is added that contains the probability of the predicted class
predict_grid(learners, task, grid_points, expand_range)
predict_grid(learners, task, grid_points, expand_range)
learners |
list of trained learners, each learner belongs to one resampling iteration |
task |
the task all learners are trained on |
grid_points |
(int): see sequenize |
expand_range |
see sequenize |