KNN Imputer#

An unsupervised imputer that replaces missing values in datasets with the distance-weighted average of the samples' k nearest neighbors' values.

Note: NaN safe distance kernels, such as Safe Euclidean, are required for continuous features.

Interfaces: Transformer, Stateful

Data Type Compatibility: Depends on distance kernel


# Param Default Type Description
1 k 5 int The number of nearest neighbors to consider when imputing a value.
2 weighted true bool Should we use the inverse distances as confidence scores when imputing values?
3 placeholder '?' string The categorical placeholder denoting the category that contains missing values.
4 tree BallTree Spatial The spatial tree used to run nearest neighbor searches.


use Rubix\ML\Transformers\KNNImputer;
use Rubix\ML\Graph\Trees\BallTee;
use Rubix\ML\Kernels\Distance\SafeEuclidean;

$transformer = new KNNImputer(10, false, '?', new BallTree(30, new SafeEuclidean()));

Additional Methods#

This transformer does not have any additional methods.


  • O. Troyanskaya et al. (2001). Missing value estimation methods for DNA microarrays.