Update README.md
Browse files
README.md
CHANGED
|
@@ -1,60 +1,82 @@
|
|
|
|
|
| 1 |
license: mit
|
| 2 |
language:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
en
|
| 5 |
-
library_name: smartknn
|
| 6 |
-
tasks:
|
| 7 |
|
| 8 |
-
tabular-
|
| 9 |
|
| 10 |
-
tabular-regression
|
| 11 |
-
metrics:
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
mse
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
weighted-knn
|
| 25 |
|
| 26 |
-
|
| 27 |
|
| 28 |
-
machine-learning
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
explainable-ai
|
| 37 |
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
-
python
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
-
SmartKNN — Weighted & Interpretable K-Nearest Neighbours for Tabular ML
|
| 49 |
|
| 50 |
pip install smart-knn
|
| 51 |
|
| 52 |
-
SmartKNN is a smarter, weighted, feature-selective variant of KNN built for modern tabular machine learning.
|
| 53 |
-
It learns per-feature importance automatically, filters weak and noisy dimensions, handles missing values, normalizes numerical data internally, and consistently delivers higher accuracy than classical KNN — while preserving a simple scikit-learn style API.
|
| 54 |
-
It supports both regression and classification, requires no manual preprocessing, and integrates seamlessly with NumPy and Pandas.
|
| 55 |
-
|
| 56 |
-
Quickstart
|
| 57 |
-
|
| 58 |
import pandas as pd
|
| 59 |
from smart_knn import SmartKNN
|
| 60 |
|
|
@@ -67,64 +89,81 @@ model.fit(X, y)
|
|
| 67 |
|
| 68 |
sample = X.iloc[0]
|
| 69 |
pred = model.predict(sample)
|
| 70 |
-
print(
|
| 71 |
|
| 72 |
-
SmartKNN automatically:
|
| 73 |
|
| 74 |
-
|
| 75 |
-
• Cleans NaN / Inf values
|
| 76 |
-
• Learns feature weights
|
| 77 |
-
• Filters weak features
|
| 78 |
-
• Computes weighted distances
|
| 79 |
-
• Selects the most meaningful neighbours
|
| 80 |
|
| 81 |
-
Features
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
• Handles missing values (median imputation + NaN/Inf cleaning)
|
| 86 |
-
• Performs robust outlier clipping
|
| 87 |
-
• Normalizes data internally
|
| 88 |
-
• Uses weighted Euclidean distance
|
| 89 |
-
• Exposes global feature importance
|
| 90 |
-
• Works for both regression & classification
|
| 91 |
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
-
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
• Regression: SmartKNN outperformed classical KNN on 90%+ datasets
|
| 97 |
-
• Classification: SmartKNN beat classical KNN on 60% of datasets
|
| 98 |
|
| 99 |
-
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
|
|
|
|
| 106 |
|
| 107 |
-
GitHub → https://github.com/thatipamula-jashwanth/smart-knn
|
| 108 |
|
| 109 |
-
|
| 110 |
|
| 111 |
-
DOI → https://doi.org/10.5281/zenodo.17713746
|
| 112 |
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
|
| 116 |
|
| 117 |
-
@software{smartknn2025,
|
| 118 |
-
author = {Jashwanth Thatipamula},
|
| 119 |
-
title = {SmartKNN: An Interpretable Weighted Distance Framework for K-Nearest Neighbours},
|
| 120 |
-
year = {2025},
|
| 121 |
-
publisher = {Zenodo},
|
| 122 |
-
doi = {10.5281/zenodo.17713746},
|
| 123 |
-
url = {https://doi.org/10.5281/zenodo.17713746}
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
}
|
| 126 |
|
| 127 |
-
License
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
license: mit
|
| 3 |
language:
|
| 4 |
+
- en
|
| 5 |
+
metrics:
|
| 6 |
+
- r_squared
|
| 7 |
+
- accuracy
|
| 8 |
+
- mae
|
| 9 |
+
- mse
|
| 10 |
+
- f1
|
| 11 |
+
- recall
|
| 12 |
+
tags:
|
| 13 |
+
- machine-learning
|
| 14 |
+
- algorithms
|
| 15 |
+
- tabular-data
|
| 16 |
+
- knn
|
| 17 |
+
- python
|
| 18 |
+
- weighted-knn
|
| 19 |
+
- data-science
|
| 20 |
+
- preprocessing
|
| 21 |
+
---
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
SmartKNN is a weighted and interpretable extension of classical K-Nearest Neighbours (KNN), designed for real-world tabular machine learning. It automatically learns feature importance, filters weak features, handles missing values, normalizes inputs internally, and consistently achieves higher accuracy and robustness than classical KNN — while maintaining a simple scikit-learn-style API.
|
| 25 |
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# Model Details
|
| 28 |
|
|
|
|
| 29 |
|
| 30 |
+
Model Description
|
| 31 |
+
SmartKNN improves classical KNN by learning feature weights and applying a weighted Euclidean distance for neighbour selection. It performs normalization, NaN/Inf cleaning, median imputation, outlier clipping, and feature filtering internally. It exposes feature importance for transparency and explainability.
|
| 32 |
|
| 33 |
+
Developed by: Jashwanth Thatipamula
|
| 34 |
+
Model type: Weighted KNN for tabular ML
|
| 35 |
+
License: MIT
|
| 36 |
+
Language(s): Not language-dependent (numerical tabular ML)
|
| 37 |
+
Finetuned from model: Not applicable (original algorithm)
|
| 38 |
|
| 39 |
+
Model Sources
|
| 40 |
+
Repository: https://github.com/thatipamula-jashwanth/smart-knn
|
| 41 |
+
Paper (DOI): https://doi.org/10.5281/zenodo.17713746
|
| 42 |
+
Demo: Coming soon
|
| 43 |
|
|
|
|
| 44 |
|
| 45 |
+
# Uses
|
| 46 |
|
|
|
|
| 47 |
|
| 48 |
+
Direct Use
|
| 49 |
+
• Regression on tabular datasets
|
| 50 |
+
• Classification on tabular datasets
|
| 51 |
+
• Interpretable ML where feature importance matters
|
| 52 |
+
• Real-world ML pipelines with missing values and noisy features
|
| 53 |
|
| 54 |
+
Downstream Use
|
| 55 |
+
• Research on distance-metric learning
|
| 56 |
+
• Explainable ML baselines
|
| 57 |
+
• AutoML components for tabular data
|
| 58 |
|
| 59 |
+
Out-of-Scope Use
|
| 60 |
+
• NLP, image or audio modelling
|
| 61 |
+
• Deep learning / GPU models
|
| 62 |
+
• Raw categorical datasets without encoding
|
| 63 |
|
|
|
|
| 64 |
|
| 65 |
+
# Bias, Risks, and Limitations
|
| 66 |
|
| 67 |
+
• Instance-based prediction can be slower than tree-based models on large datasets
|
| 68 |
+
• Low performance on categorical-only datasets without encoding
|
| 69 |
+
• Requires storing full training set for inference
|
| 70 |
|
| 71 |
+
Recommendations
|
| 72 |
+
Users should numerically encode categorical features before fitting SmartKNN.
|
| 73 |
|
|
|
|
| 74 |
|
| 75 |
+
# How to Get Started with the Model
|
| 76 |
|
|
|
|
| 77 |
|
| 78 |
pip install smart-knn
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
import pandas as pd
|
| 81 |
from smart_knn import SmartKNN
|
| 82 |
|
|
|
|
| 89 |
|
| 90 |
sample = X.iloc[0]
|
| 91 |
pred = model.predict(sample)
|
| 92 |
+
print(pred)
|
| 93 |
|
|
|
|
| 94 |
|
| 95 |
+
# Training Details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
|
|
|
| 97 |
|
| 98 |
+
Training Data
|
| 99 |
+
SmartKNN is not pretrained and does not ship with training data; users train on their own dataset.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
Preprocessing
|
| 102 |
+
Performed automatically:
|
| 103 |
+
• Normalization
|
| 104 |
+
• NaN / Inf cleaning
|
| 105 |
+
• Median imputation
|
| 106 |
+
• Outlier clipping
|
| 107 |
+
• Feature filtering via learned weights
|
| 108 |
|
| 109 |
+
Training Hyperparameters
|
| 110 |
+
• k = number of neighbors
|
| 111 |
+
• weight_threshold = drop features below learned importance
|
| 112 |
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
# Evaluation
|
| 115 |
+
Testing Data
|
| 116 |
+
Evaluated across 35 regression and 20 classification public tabular datasets.
|
| 117 |
|
| 118 |
+
# Metrics
|
| 119 |
+
Regression: R², MSE
|
| 120 |
+
Classification: Accuracy
|
| 121 |
|
| 122 |
+
# Results
|
| 123 |
+
• Regression: SmartKNN outperformed classical KNN on 90%+ datasets
|
| 124 |
+
• Classification: SmartKNN beat classical KNN on 60% of datasets
|
| 125 |
|
| 126 |
+
# Summary
|
| 127 |
+
SmartKNN delivers higher accuracy, greater robustness to noise, and better interpretability than classical KNN while preserving its simplicity.
|
| 128 |
|
|
|
|
| 129 |
|
| 130 |
+
# Environmental Impact
|
| 131 |
|
|
|
|
| 132 |
|
| 133 |
+
SmartKNN requires no GPU and has minimal energy usage.
|
| 134 |
+
Hardware Type: CPU
|
| 135 |
+
Hours used: Minimal
|
| 136 |
+
Carbon Emitted: Negligible
|
| 137 |
|
| 138 |
+
# Technical Specifications
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
+
Model Architecture and Objective
|
| 142 |
+
• Instance-based learner
|
| 143 |
+
• Weighted Euclidean distance metric
|
| 144 |
+
• Learned feature weights (MSE + MI + Random Forest)
|
| 145 |
+
|
| 146 |
+
Compute Infrastructure
|
| 147 |
+
• Runs efficiently on CPU systems
|
| 148 |
+
• Implemented using NumPy
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
# Citation
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
@software{smartknn2025,
|
| 155 |
+
author = {Jashwanth Thatipamula},
|
| 156 |
+
title = {SmartKNN: An Interpretable Weighted Distance Framework for K-Nearest Neighbours},
|
| 157 |
+
year = {2025},
|
| 158 |
+
publisher = {Zenodo},
|
| 159 |
+
doi = {10.5281/zenodo.17713746},
|
| 160 |
+
url = {https://doi.org/10.5281/zenodo.17713746}
|
| 161 |
}
|
| 162 |
|
|
|
|
| 163 |
|
| 164 |
+
# Model Card Authors
|
| 165 |
+
|
| 166 |
+
Jashwanth Thatipamula
|
| 167 |
+
|
| 168 |
+
Model Card Contact
|
| 169 |
+
Contact via GitHub issues: https://github.com/thatipamula-jashwanth/smart-knn
|