Registry / ai-ml / knnimpute

knnimpute

JSON →
library0.1.0pypypi✓ verified 80d ago

A lightweight Python library for k-Nearest Neighbor imputation of missing values in datasets. Current version 0.1.0 appears to be an initial release with minimal updates; last commit on GitHub was in 2018. The library is in maintenance mode.

pip install knnimpute
INSTALL
IMPORT
SIG · KNNIMPUTE
K
knnimpute
ai-mlpythonv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

knn_impute_few_observed
from knnimpute import knn_impute_few_observed
from knnimpute import knn_impute
knn_impute_optimistic
from knnimpute import knn_impute_optimistic
knn_impute_reference
from knnimpute import knn_impute_reference

Basic imputation of a matrix with missing values using default settings.

import numpy as np from knnimpute import knn_impute # Simulate data with missing values X = np.array([[1, 2, np.nan], [4, np.nan, 6], [7, 8, 9]]) # Impute using k=3 X_imputed = knn_impute(X, k=3) print(X_imputed) # Output: [[1. 2. 5.] [4. 5. 6.] [7. 8. 9.]]
Debug
Known issues
breakingThe function knn_impute_few_observed is not a drop-in replacement for knn_impute; it uses a different algorithm and signature. Ensure you read its documentation.
fix
Use knn_impute for standard tasks; only use knn_impute_few_observed when you have many features with few observed values.
affects: >=0.1.0
gotchaThe library does not handle non-numeric data. All columns must be numeric; categorical data must be encoded beforehand.
fix
Convert categorical variables to numeric using one-hot encoding or label encoding before calling knn_impute.
affects: >=0.1.0
gotchaMissing values must be represented as np.nan. Using None or other sentinels will cause incorrect behavior or errors.
fix
Ensure missing entries are np.nan. Use np.isnan() to check or convert None to np.nan.
affects: >=0.1.0
Upgrade
Version history
0.1.0latest on PyPI · released Mar 16, 2017
Audit
Dependencies
numpyrequiredRequired for array operations.
scipyrequiredRequired for distance computations.
Agent activity
8 hits · last 30 days
node
8
Resources
knnimpute — pip install knnimpute · libregistry