KNORA-IU
This algorithm comes from the KNORA family and is designed to be a variation to KNORA-U that works for most classification tasks. It checks the K nearest neighbors and has the models perform weighted vote based on how many correct predictions were made and how distant those neighbors are.
When to use
- KNORA-IU is an algorithm designed as a variation to KNORA-U for general classification tasks,
to be used a discrete metric, usually
accuracy - It performs best when the dataset has class overlaps and the dataset is large enough that distant neighbors are less relevant
- It performs worst on datasets where one model heavily dominates a competence region
How it works
When fit is called, KNORA-IU fits a KNN algorithm on the validation data and builds a criterion score matrix.
When predict is called, it finds the K nearest neighbors from the test point and for normalizes the model scores
for every neighbor with min-max normalization. If all models scored identically, they all get 1.0. For each model, the amount of neighbors where its score
exceeded the threshold (in classification, this would mean that the predictions were correct) multiplied by the inverse of the
neighbor distance is that model's vote total.
The vote counts are then normalized by dividing them by the total amount of votes and turned into weights. If no model earned any votes at all,
uniform weights are assigned.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
task |
str | — | "classification" or "regression" |
metric |
str or callable | — | Scoring function per sample. Built-ins: accuracy, mae, mse, rmse, log_loss, prob_correct. Custom callables (y_true, y_pred) -> float are accepted |
mode |
str | — | "max" if higher is better, "min" if lower |
k |
int | 10 | Number of neighbours |
threshold |
float | 0.5 | Competence cutoff |
temperature |
float | 1.0 | Accepted for internal API consistency but not used |
preset |
str | "balanced" |
ANN backend preset |
finder |
str | —, optional | Only if the preset is "custom"; Options: "knn", "faiss", "annoy", "hnsw" |
Example
from deskit.des.knoraiu import KNORAIU
router = KNORAIU(task="classification", metric="accuracy", mode="max", k=20)
router.fit(X_val, y_val, val_preds)
weights = router.predict(x)
Notes
The threshold parameter is used only for regression; For classification with a discrete metrics, any threshold (0,1] behaves identically.
However, this algorithm is not designed to be used for regression, so using it for regression is not recommended.