| preprocess | R Documentation |
Preprocess data for analysis and visualization.
preprocess(
x,
config,
dat_validation = NULL,
dat_test = NULL,
verbosity = 1L,
...
)
x |
Tabular data, i.e. data.frame, data.table, or tbl_df (tibble): Training set data to preprocess. |
config |
|
dat_validation |
Optional tabular data: Validation set data. Preprocessed using the values learned from the training set data. |
dat_test |
Optional tabular data: Test set data. Preprocessed using the values learned from the training set data. |
verbosity |
Integer: Verbosity level. |
... |
setup_Preprocessor arguments: Only used when |
preprocess() preprocesses training data and learns any data-dependent values (e.g. scale
centers and coefficients, one-hot levels). Optional dat_validation and dat_test data are
preprocessed using the values learned from the training data. To apply a trained
Preprocessor to new data, use apply_preprocessor.
For interactive use, config may be omitted and setup_Preprocessor arguments passed
directly instead, e.g. preprocess(x, scale = TRUE, center = TRUE). At least one
preprocessing parameter must be specified: preprocess(x) is an error.
The preprocessed data comes back in the structure it was given – data.frame, data.table or tibble – and the object passed in is never modified. It carries no row names: a case identifier that matters belongs in a column, where it can be selected, joined, validated and serialized.
Preprocessor object.
EDG
apply_preprocessor, setup_Preprocessor
# Setup a `Preprocessor`: this outputs a `PreprocessorConfig` object.
prp <- setup_Preprocessor(remove_duplicates = TRUE, scale = TRUE, center = TRUE)
# Includes a long list of parameters
prp
# Resample iris to get train and test data
res <- resample(iris, setup_KFold(seed = 2026))
iris_train <- iris[res[[1]], ]
iris_test <- iris[-res[[1]], ]
# Preprocess training data
iris_pre <- preprocess(iris_train, prp)
# Alternatively, for interactive use, pass `setup_Preprocessor()` arguments directly
iris_pre <- preprocess(iris_train, remove_duplicates = TRUE, scale = TRUE, center = TRUE)
# Access preprocessed training data with `preprocessed()`
preprocessed(iris_pre)
# Apply the same preprocessing to test data with `apply_preprocessor()`,
# which returns the preprocessed data directly.
# The scale and center values learned from the training data will be used.
iris_test_pre <- apply_preprocessor(iris_pre, iris_test)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.