KNNImputer<T>
Models & Types · AiDotNet.Preprocessing.Imputers
Imputes missing values using K-Nearest Neighbors.
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → KNNImputer<T>
For Beginners
This imputer fills in missing values by looking at similar data points:
- Finds the K most similar rows that have the value you need
- Uses their average to fill in the missing value
- “Similar” is measured using Euclidean distance on non-missing features
Example: If you’re missing someone’s income, KNN finds K similar people (same age, education, etc.) and uses their average income.
How It Works
KNNImputer replaces missing values with the mean (or weighted mean) of the K nearest neighbors found in the training set. Each sample’s missing values are imputed using the values from the K most similar samples that have non-missing values for that feature.
Constructors
| Constructor | Summary |
|---|---|
KNNImputer(int nNeighbors, KNNWeights weights, double missingValue, int[] columnIndices) |
Creates a new instance of KNNImputer. |
Properties
| Property | Summary |
|---|---|
KNNWeights Weights { get; } |
Gets the weighting scheme used for neighbors. |
bool SupportsInverseTransform { get; } |
Gets whether this transformer supports inverse transformation. |
int NNeighbors { get; } |
Gets the number of neighbors to use for imputation. |
Methods
| Method | Summary |
|---|---|
string[] GetFeatureNamesOut(string[] inputFeatureNames) |
Gets the output feature names after transformation. |