Inference
This module is concerned with making predictions on unseen data, using nearest neigbour techiqnues on either features or similarity matrix.
KnnClassifier
Reference
Predict query label as k labels of nearest matches in database. If there is tie at given k, prediction from k-1 is used.
Input is similarity matrix with n_query
x n_database
shape.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k |
int
|
use k nearest in database for the majority voting. |
1
|
database_labels |
np.array | None
|
list of labels in database. If provided, decode predictions to database (e.g. string) labels. |
None
|
Returns:
Type | Description |
---|---|
1D array with length |
Source code in inference/classifier.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
aggregate(predictions)
Aggregates array of nearest neigbours to single prediction for each k. If there is tie at given k, prediction from k-1 is used.
Returns:
Type | Description |
---|---|
array of shape [n_query, k] of predicitons. Column dimensions are predictions for [k=1, k=2 ... k=k] |
Source code in inference/classifier.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
KnnMatcher
Reference
Find nearest match to query in existing database of features. Combines CosineSimilarity and KnnClassifier.
Source code in inference/classifier.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|