Convert to visualizer
as_visualizer.Rd
This function converts to a visualizer. Automatically chooses between 1D and 2D visualizations based on the number of features/dimensions using ggplot2 backend. For 2D inputs, you can optionally use `type = "surface"` to get interactive plotly surface plots (available for Models and Objectives only).
Usage
as_visualizer(
x,
type = "auto",
x1_limits = NULL,
x2_limits = NULL,
padding = 0,
n_points = 100L,
y_pred = NULL,
y_true = NULL,
input_type = "auto",
y_curves = "both",
learner = NULL,
...
)
# S3 method for class 'Task'
as_visualizer(
x,
type = "auto",
x1_limits = NULL,
x2_limits = NULL,
padding = 0,
n_points = 100L,
y_pred = NULL,
y_true = NULL,
input_type = "auto",
y_curves = "both",
learner = NULL,
hypothesis = NULL,
retrain = TRUE,
...
)
# S3 method for class 'Hypothesis'
as_visualizer(
x,
type = "auto",
x1_limits = NULL,
x2_limits = NULL,
padding = 0,
n_points = 100L,
y_pred = NULL,
y_true = NULL,
input_type = "auto",
y_curves = "both",
learner = NULL,
domain = NULL,
...
)
# S3 method for class 'Objective'
as_visualizer(
x,
type = "auto",
x1_limits = NULL,
x2_limits = NULL,
padding = 0,
n_points = 100L,
y_pred = NULL,
y_true = NULL,
input_type = "auto",
y_curves = "both",
learner = NULL,
allow_extrapolation = FALSE,
...
)
# S3 method for class 'LossFunction'
as_visualizer(
x,
type = "auto",
x1_limits = NULL,
x2_limits = NULL,
padding = 0,
n_points = 1000L,
y_pred = NULL,
y_true = NULL,
input_type = "auto",
y_curves = "both",
learner = NULL,
...
)
# S3 method for class 'list'
as_visualizer(
x,
type = "auto",
x1_limits = NULL,
x2_limits = NULL,
padding = 0,
n_points = 1000L,
y_pred = NULL,
y_true = NULL,
input_type = "auto",
y_curves = "both",
learner = NULL,
...
)
Arguments
- x
(`any`)
Object to convert to a visualizer.- type
(`character(1)`)
The type of visualization: "auto" (default), "1d", "2d", or "surface". If "auto", automatically chooses between 1D and 2D ggplot2 visualizations based on the number of features/dimensions. Use "surface" for interactive plotly surface plots (2D inputs only, Models and Objectives only).- x1_limits
(`numeric(2)`)
The x1 limits.- x2_limits
(`numeric(2)`)
The x2 limits.- padding
(`numeric(1)`)
A margin that is added to x1limits and x2limits. The x1 margin is calculated by `max(x1lmits) - min(x1limits) * padding`.- n_points
(`integer(1)`)
The number of generated point per dimension. Note that a grid of `npoints^2` values is generated and evaluated by `objective$eval(x)` to plot the surface.- y_pred
(`numeric()`)
Predicted values (used for loss function visualizations).- y_true
(`numeric()`)
True values (used for loss function visualizations).- input_type
(`character(1)`)
`"auto"` (default), `"score"` or `"probability"`. Passed through to the loss visualiser.- y_curves
(`character(1)`)
Which response curve(s) to draw when `input_type = "probability"`. One of `"both"`, `"y1"`, or `"y0"`.- learner
(`mlr3::Learner`)
The learner to train the model with.- ...
(`any`)
Additional arguments.- hypothesis
(`Hypothesis`|`NULL`) Optional hypothesis object that provides predictions instead of a learner. Supply either `learner` or `hypothesis`, but not both.
- retrain
(`logical(1)`)
If a learner is supplied, whether it should be (re)trained on the task (`TRUE`, default) or reused as-is (`FALSE`). If `FALSE` but the learner is untrained, a warning is issued and training is performed.- domain
(`list`|`NULL`) Named list giving axis limits per predictor when no Task data is available, e.g., `list(x = c(-1, 1))` for 1D or `list(x = c(-1,1), y = c(-1,1))` for 2D.
- allow_extrapolation
(`logical(1)`) Whether to evaluate the objective outside its evaluation (canonical) bounds when plot limits extend further. If `FALSE` (default), values outside are masked (set to `NA`) producing blank regions in the plot; if `TRUE`, the objective is called on the extended region (may yield misleading or numerically extreme values depending on the function definition).
Value
An object inheriting from a Visualizer class (Visualizer1D, Visualizer2D, VisualizerSurface, etc.) depending on the input and selected type.
Details
If `type = "auto"` (default), the function will inspect the input and select the appropriate ggplot2 visualizer: - 1D: For objects with 1 feature/dimension (uses ggplot2) - 2D: For objects with 2 features/dimensions (uses ggplot2) You can override this by specifying `type = "1d"`, `type = "2d"`, or for 2D inputs only: `type = "surface"` (uses plotly for interactive surfaces, Models and Objectives only).
Hypotheses can be used instead of learners to visualize functional forms directly. When no Task is provided (i.e., visualizing a `Hypothesis` alone), a `domain` must be supplied to define plotting limits.