impute | R Documentation |
A universal missing data imputation tool that wraps successive calls to train
and fuse
under the hood. Designed for simplicity and ease of use.
impute(
data,
weight = NULL,
ignore = NULL,
cores = parallel::detectCores(logical = FALSE) - 1L
)
data |
A data frame with missing values. |
weight |
Optional name of observation weights column in |
ignore |
Optional names of columns in |
cores |
Number of physical CPU cores used by |
Variables with missing values are imputed sequentially, beginning with the variable with the fewest missing values. Since LightGBM models accommodate NA values in the predictor set, all available variables are used as potential predictors (excluding ignore
variables). For each call to train
, 80% of observations are randomly selected for training and the remaining 20% are used as a validation set to determine an appropriate number of tree learners. All LightGBM model parameters are kept at the sensible default values in train
. Since lightgbm
uses OpenMP multithreading, it is not advisable to use impute
inside a forked/parallel process when cores > 1
.
A data frame with all missing values imputed.
# Create data frame with random NA values
?recs
data <- recs[, 2:7]
miss <- replicate(ncol(data), runif(nrow(data)) < runif(1, 0.01, 0.3))
data[miss] <- NA
colSums(is.na(data))
# Impute the missing values
result <- impute(data)
anyNA(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.