Title: | Visualizations for 'mlr3' |
Version: | 0.10.1 |
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. |
License: | LGPL-3 |
URL: | https://mlr3viz.mlr-org.com, https://github.com/mlr-org/mlr3viz |
BugReports: | https://github.com/mlr-org/mlr3viz/issues |
Depends: | R (≥ 3.1.0) |
Imports: | checkmate, data.table, ggplot2 (≥ 3.3.0), mlr3misc (≥ 0.7.0), scales, utils, viridis |
Suggests: | bbotk (≥ 1.0.0), cluster, GGally, ggdendro, ggfortify (≥ 0.4.11), ggparty, glmnet, knitr, lgr, mlr3 (≥ 0.6.0), mlr3cluster, mlr3filters, mlr3fselect (≥ 1.3.0), mlr3inferr, mlr3learners, mlr3tuning (≥ 1.0.0), paradox, partykit, patchwork (≥ 1.1.1), precrec, ranger, rpart, stats, testthat (≥ 3.0.0), vdiffr (≥ 1.0.2), xgboost, survminer, mlr3proba (≥ 0.6.3) |
Additional_repositories: | https://mlr-org.r-universe.dev |
Config/testthat/edition: | 3 |
Config/testthat/parallel: | true |
Encoding: | UTF-8 |
NeedsCompilation: | no |
RoxygenNote: | 7.3.2 |
Collate: | 'BenchmarkResult.R' 'Filter.R' 'LearnerClassif.R' 'LearnerClassifCVGlmnet.R' 'LearnerClassifGlmnet.R' 'LearnerClassifRpart.R' 'LearnerClustHierarchical.R' 'LearnerRegr.R' 'LearnerRegrCVGlmnet.R' 'LearnerRegrGlmnet.R' 'LearnerRegrRpart.R' 'LearnerSurvCoxPH.R' 'OptimInstanceBatchSingleCrit.R' 'Prediction.R' 'PredictionClassif.R' 'PredictionClust.R' 'PredictionRegr.R' 'ResampleResult.R' 'Task.R' 'TaskClassif.R' 'TaskClust.R' 'TaskRegr.R' 'TuningInstanceBatchSingleCrit.R' 'EnsembleFSResult.R' 'as_precrec.R' 'bibentries.R' 'helper.R' 'plot_learner_prediction.R' 'reexports.R' 'zzz.R' |
Packaged: | 2025-01-16 15:30:05 UTC; marc |
Author: | Michel Lang |
Maintainer: | Marc Becker <marcbecker@posteo.de> |
Repository: | CRAN |
Date/Publication: | 2025-01-16 16:40:02 UTC |
mlr3viz: 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.
Author(s)
Maintainer: Marc Becker marcbecker@posteo.de (ORCID)
Authors:
Michel Lang michellang@gmail.com (ORCID)
Patrick Schratz patrick.schratz@gmail.com (ORCID)
Raphael Sonabend raphael.sonabend.15@ucl.ac.uk (ORCID)
Jakob Richter jakob1richter@gmail.com (ORCID)
John Zobolas bblodfon@gmail.com (ORCID)
Other contributors:
Damir Pulatov dpulatov@uwyo.edu [contributor]
See Also
Useful links:
Report bugs at https://github.com/mlr-org/mlr3viz/issues
Convert to 'precrec' Format
Description
Converts to a format which is understood by precrec::evalmod()
of package precrec.
Usage
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)
Arguments
object |
( |
Value
Object as created by precrec::mmdata()
.
References
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.
Plots for Benchmark Results
Description
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"
. -
"ci"
: Plot confidence intervals. Pass amsr("ci", ...)
from themlr3inferr
package as argumentmeasure
.
Usage
## S3 method for class 'BenchmarkResult'
autoplot(
object,
type = "boxplot",
measure = NULL,
theme = theme_minimal(),
...
)
Arguments
object |
|
type |
(character(1)): |
measure |
(mlr3::Measure) |
theme |
( |
... |
arguments passed on to |
Value
References
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.
Examples
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")
}
Plots for Ensemble Feature Selection Results
Description
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.
Usage
## S3 method for class 'EnsembleFSResult'
autoplot(
object,
type = "pareto",
pareto_front = "stepwise",
stability_measure = "jaccard",
stability_args = NULL,
theme = theme_minimal(),
...
)
Arguments
object |
|
type |
(character(1)): |
pareto_front |
( |
stability_measure |
( |
stability_args |
( |
theme |
( |
... |
(ignored). |
Value
Examples
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),
inner_measure = msr("classif.ce"),
measure = msr("classif.acc"),
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")
# use inner measure
efsr$set_active_measure("inner")
# Pareto front uses now the classification error
autoplot(efsr)
}
Plots for Filter Scores
Description
Visualizations for mlr3filters::Filter.
The argument type
controls what kind of plot is drawn.
Possible choices are:
-
"barplot"
(default): Bar plot of filter scores.
Usage
## S3 method for class 'Filter'
autoplot(object, type = "boxplot", n = Inf, theme = theme_minimal(), ...)
Arguments
object |
|
type |
(character(1)): |
n |
( |
theme |
( |
... |
(ignored). |
Value
Examples
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)
}
Plot for Classification Learners
Description
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.
Usage
## S3 method for class 'LearnerClassif'
autoplot(
object,
type = "prediction",
task,
grid_points = 100L,
expand_range = 0,
theme = theme_minimal(),
...
)
Arguments
object |
|
type |
(character(1)): |
task |
(mlr3::Task) |
grid_points |
(integer(1)) |
expand_range |
(numeric(1)) |
theme |
( |
... |
(ignored). |
Value
Examples
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)
}
Plots for GLMNet Learners
Description
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.
Usage
## 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(),
...
)
Arguments
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). |
Value
References
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.
Examples
## 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)
Plots for Rpart Learners
Description
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.
Usage
## 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(),
...
)
Arguments
object |
|
type |
(character(1)): |
task |
(mlr3::Task) |
grid_points |
(integer(1)) |
expand_range |
(numeric(1)) |
theme |
( |
... |
(ignored). |
Value
Examples
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")
}
Plots for Hierarchical Clustering Learners
Description
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.
Usage
## S3 method for class 'LearnerClustHierarchical'
autoplot(
object,
type = "dend",
task = NULL,
theme = theme_minimal(),
theme_dendro = TRUE,
...
)
Arguments
object |
(mlr3cluster::LearnerClustAgnes | mlr3cluster::LearnerClustDiana | mlr3cluster::LearnerClustHclust). |
type |
(character(1)): |
task |
(mlr3::Task) |
theme |
( |
theme_dendro |
( |
... |
(ignored). |
Value
Examples
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")
}
Plot for Regression Learners
Description
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.
Usage
## S3 method for class 'LearnerRegr'
autoplot(
object,
type = "prediction",
task,
grid_points = 100L,
expand_range = 0,
theme = theme_minimal(),
...
)
Arguments
object |
|
type |
(character(1)): |
task |
(mlr3::Task) |
grid_points |
(integer(1)) |
expand_range |
(numeric(1)) |
theme |
( |
... |
(ignored). |
Value
Examples
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)
}
Plots for Cox Proportional Hazards Learner
Description
Visualizations for LearnerSurvCoxPH
of mlr3proba
.
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.
Usage
## S3 method for class 'LearnerSurvCoxPH'
autoplot(object, type = "ggforest", ...)
Arguments
object |
( |
type |
(character(1)): |
... |
Additional parameters passed down to |
Value
Examples
if (requireNamespace("mlr3proba")) {
library(mlr3proba)
library(mlr3viz)
task = tsk("lung")
learner = lrn("surv.coxph")
learner$train(task)
autoplot(learner)
}
Plots for Optimization Instances
Description
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.
Usage
## 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(),
...
)
Arguments
object |
|
type |
(character(1)): |
cols_x |
( |
trafo |
( |
learner |
(mlr3::Learner) |
grid_resolution |
( |
batch |
( |
theme |
( |
... |
(ignored). |
Value
Examples
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"))
}
Plots for Classification Predictions
Description
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 bymeasure
.
Usage
## S3 method for class 'PredictionClassif'
autoplot(
object,
type = "stacked",
measure = NULL,
theme = theme_minimal(),
...
)
Arguments
object |
|
type |
(character(1)): |
measure |
(mlr3::Measure) |
theme |
( |
... |
(ignored). |
Value
References
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.
Examples
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")
}
Plots for Cluster Predictions
Description
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.
Usage
## S3 method for class 'PredictionClust'
autoplot(
object,
task,
row_ids = NULL,
type = "scatter",
theme = theme_minimal(),
...
)
Arguments
object |
|
task |
|
row_ids |
( |
type |
(character(1)): |
theme |
( |
... |
(ignored). |
Value
References
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.
Examples
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)
}
Plots for Regression Predictions
Description
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 viageom_smooth(method = "lm")
to visualize the trend between x and y (by default colored blue). In additiongeom_abline()
withslope = 1
is added to the plot. Note thatgeom_smooth()
andgeom_abline()
may overlap, depending on the given data. -
"histogram"
: Histogram of residuals:r = y - \hat{y}
. -
"residual"
: Plot of the residuals, with the response\hat{y}
on the "x" and the residuals on the "y" axis. By default a linear model is fitted viageom_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 withpredict_type = "se"
.geom_abline()
withslope = 1
is added to the plot.
Usage
## S3 method for class 'PredictionRegr'
autoplot(
object,
type = "xy",
binwidth = NULL,
theme = theme_minimal(),
quantile = 1.96,
...
)
Arguments
object |
|
type |
(character(1)): |
binwidth |
( |
theme |
( |
quantile |
( |
... |
(ignored). |
Value
Examples
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")
}
}
Plots for Resample Results
Description
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. Setstore_models = TRUE
formlr3::resample()
. For classification, we support tasks with exactly two features and learners withpredict_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.
Usage
## S3 method for class 'ResampleResult'
autoplot(
object,
type = "boxplot",
measure = NULL,
predict_sets = "test",
binwidth = NULL,
theme = theme_minimal(),
...
)
Arguments
object |
|
type |
(character(1)): |
measure |
(mlr3::Measure) |
predict_sets |
( |
binwidth |
( |
theme |
( |
... |
arguments passed on to |
Value
References
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.
Examples
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")
}
Plots for Classification Tasks
Description
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 toGGally::ggduo()
.columnsX
is the target andcolumnsY
are the features. -
"pairs"
: Passes data toGGally::ggpairs()
. Color is set to target column.
Usage
## S3 method for class 'TaskClassif'
autoplot(object, type = "target", theme = theme_minimal(), ...)
Arguments
object |
|
type |
(character(1)): |
theme |
( |
... |
(ignored). |
Value
Examples
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")
}
Plots for Clustering Tasks
Description
Visualizations for mlr3cluster::TaskClust.
The argument type
controls what kind of plot is drawn.
Possible choices are:
-
"pairs"
(default): Passes dataGGally::ggpairs()
.
Usage
## S3 method for class 'TaskClust'
autoplot(object, type = "pairs", theme = theme_minimal(), ...)
Arguments
object |
|
type |
(character(1)): |
theme |
( |
... |
(ignored). |
Value
Examples
if (requireNamespace("mlr3")) {
library(mlr3)
library(mlr3cluster)
library(mlr3viz)
task = mlr_tasks$get("usarrests")
head(fortify(task))
autoplot(task)
}
Plots for Regression Tasks
Description
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 toGGally::ggpairs()
. Color is set to target column.
Usage
## S3 method for class 'TaskRegr'
autoplot(object, type = "target", theme = theme_minimal(), ...)
Arguments
object |
|
type |
(character(1)): |
theme |
( |
... |
(ignored). |
Value
Examples
if (requireNamespace("mlr3")) {
library(mlr3)
library(mlr3viz)
task = tsk("mtcars")
task$select(c("am", "carb"))
head(fortify(task))
autoplot(task)
autoplot(task, type = "pairs")
}
Plots for Tuning Instances
Description
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.
Usage
## 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(),
...
)
Arguments
object |
|
type |
(character(1)): |
cols_x |
( |
trafo |
( |
learner |
(mlr3::Learner) |
grid_resolution |
( |
theme |
( |
... |
(ignored). |
Value
Examples
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")
}
Plots for Learner Predictions
Description
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).
Usage
plot_learner_prediction(learner, task, grid_points = 100L, expand_range = 0)
Arguments
learner |
|
task |
(mlr3::Task). |
grid_points |
( |
expand_range |
( |
Value
Examples
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)
}
Generates a data.table of evenly distributed points.
Description
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
Usage
predict_grid(learners, task, grid_points, expand_range)
Arguments
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 |
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.