Learn R Programming

emil (version 2.2.3)

pre_impute_knn: Nearest neighbors imputation

Description

Nearest neighbor methods needs to have a distance matrix of the dataset it works on. When doing repeated model fittings on subsets of the entire dataset it is unnecessary to recalculate it every time, therefore this function requires the user to manually calculate it prior to resampling and supply it in a wrapper function.

Usage

pre_impute_knn(data, k = 0.05, distance_matrix)

Arguments

Details

Features with fewer than k non-missing values will be removed automatically.

Examples

Run this code
x <- iris[-5]
x[sample(nrow(x), 30), 3] <- NA
my.dist <- dist(x)
evaluate(modeling_procedure("lda"), x = x, y = iris$Species,
    pre_process = function(...){
        pre_split(...) %>% pre_impute_knn(k = 4, distance_matrix = my.dist)
    }
)

Run the code above in your browser using DataLab