apply_preprocessor: Apply trained Preprocessor to new data

View source: R/preprocess.R

apply_preprocessorR Documentation

Apply trained Preprocessor to new data

Description

Apply a trained Preprocessor to new data, reusing the values learned from the training data. For example, the same mean and mode imputation values, scale centers and coefficients, one-hot levels, and removed features will be applied to the new data.

Usage

apply_preprocessor(preprocessor, new_data, verbosity = 1L)

Arguments

preprocessor

Preprocessor: Trained preprocessor, i.e. the output of preprocess.

new_data

Tabular data, i.e. data.frame, data.table, or tbl_df (tibble): New data to preprocess.

verbosity

Integer: Verbosity level.

Details

Imputation follows the preprocessor's impute_type. "meanMode" imputes the stored training values. "missRanger" applies the forests fitted on the training data with predict(), and imputes a feature that had no missing training values with its stored mean or mode; predict() stops on a factor level of an imputed feature that is absent from the training data. A preprocessor using "micePMM" cannot be applied to new data and is refused.

Value

Preprocessed data, in the same structure as new_data.

Author(s)

EDG

See Also

preprocess, setup_Preprocessor

Examples

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, setup_Preprocessor(scale = TRUE, center = TRUE))

# Apply the same preprocessing to test data
iris_test_pre <- apply_preprocessor(iris_pre, iris_test)

rtemis documentation built on Oct. 20, 2026, 1:06 a.m.