mlr_graphs_convert_types | R Documentation |
Converts all columns of type type_from
to type_to
, using the corresponding R function (e.g. as.numeric()
, as.factor()
).
It is possible to further subset the columns that should be affected using the affect_columns
argument.
The resulting Graph
contains a PipeOpColApply
, followed, if appropriate, by a PipeOpFixFactors
.
Unlike R's as.factor()
function, ppl("convert_types")
will convert ordered
types into (unordered) factor
vectors.
pipeline_convert_types(
type_from,
type_to,
affect_columns = NULL,
id = NULL,
fixfactors = NULL,
more_args = list()
)
type_from |
|
type_to |
|
affect_columns |
|
id |
|
fixfactors |
|
more_args |
|
Graph
library("mlr3")
data_chr = data.table::data.table(
x = factor(letters[1:3]),
y = letters[1:3],
z = letters[1:3]
)
task_chr = TaskClassif$new("task_chr", data_chr, "x")
str(task_chr$data())
graph = ppl("convert_types", "character", "factor")
str(graph$train(task_chr)[[1]]$data())
graph_z = ppl("convert_types", "character", "factor",
affect_columns = selector_name("z"))
graph_z$train(task_chr)[[1]]$data()
# `affect_columns` and `type_from` are both applied. The following
# looks for a 'numeric' column with name 'z', which is not present;
# the task is therefore unchanged.
graph_z = ppl("convert_types", "numeric", "factor",
affect_columns = selector_name("z"))
graph_z$train(task_chr)[[1]]$data()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.