Skip to main content

A modern, weighted k-nearest neighbors algorithm with learned feature importance and fast CPU inference.

Project description

SmartKNN logo

SmartKNN

A modern, weighted nearest-neighbor learning algorithm with learned feature importance and adaptive neighbor search.

Website PyPI version Python versions CI status MIT License Hugging Face Demo Regression Benchmarks Classification Benchmarks

Overview

SmartKNN is a nearest-neighbor–based learning method that belongs to the broader KNN family of algorithms.

It is designed to address common limitations observed in classical KNN approaches, including:

  • uniform treatment of all features
  • sensitivity to noisy or weakly informative dimensions
  • limited scalability as dataset size grows

SmartKNN incorporates data-driven feature importance estimation, dimension suppression, and adaptive neighbor search strategies. Depending on dataset characteristics, it can operate using either a brute-force search or an approximate nearest-neighbor (ANN) backend, while exposing a consistent, scikit-learn–compatible API.

The method supports both regression and classification tasks and prioritizes robustness, predictive accuracy, and practical inference latency across a range of dataset sizes.


Key Capabilities

  • Learned feature weighting
    • MSE relevance
    • Mutual Information
    • Random Forest importance
      (method configurable depending on task and dataset)
  • Automatic preprocessing
    • normalization
    • NaN / Inf handling
    • feature masking
  • Distance-weighted neighbor voting
  • Brute-force and ANN backends
    • designed to scale to large datasets (hardware and tuning dependent)
    • optional GPU-accelerated neighbor search
  • Vectorized NumPy with Numba acceleration
  • Scikit-learn–compatible API

Installation

pip install smart-knn

Documentation

Detailed documentation and design notes are maintained externally. This repository README is intentionally kept concise.


Examples

Runnable examples are available in the examples/ directory:

python examples/regression_example.py
python examples/classification_example.py

Benchmarks & CI

  • Comprehensive benchmark suites for regression and classification
  • GitHub Actions CI for tests and benchmarks
  • Reproducible, engineering-focused evaluation

Benchmark details are documented in benchmarks/README.md.


Project Status

  • SmartKNN v2 is stable
  • API is frozen for the v2.x series (backward-compatible improvements only)
  • Actively maintained
  • Open to research and engineering collaboration

License

SmartKNN is released under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smart_knn-0.2.3.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smart_knn-0.2.3-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file smart_knn-0.2.3.tar.gz.

File metadata

  • Download URL: smart_knn-0.2.3.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for smart_knn-0.2.3.tar.gz
Algorithm Hash digest
SHA256 c0bcd7de88f95c46fd542f067bf45d3bc3f20dc6b69435e987bd8edaaf69a43b
MD5 33f7525ac7f0c9addc257ae39b94952d
BLAKE2b-256 8739b5d24c6943d47da204f0d4646f3c8de0d09e7f71ea7ca05d2fabf0c6f25e

See more details on using hashes here.

File details

Details for the file smart_knn-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: smart_knn-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for smart_knn-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a9e505298b24b387ba4a3b4b327fa8579b44eb981cb425275965f5bb18c0a5c2
MD5 ec8f4b33fcd95a53d52adb8bf465c005
BLAKE2b-256 56c0fd8940fe9ddc26e6ea0f97dd935bbe9b2039d5684996d29c81e38205d601

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page