scores.KNNScore

Abstract base class for KNN distance-based uncertainty scores.

Usage

Source

scores.KNNScore(
    k=1,
    stat="max",
    pca=None,
    save_index=False,
)

Computes distance-based uncertainty scores where low scores indicate samples similar to the training distribution (low uncertainty) and high scores indicate samples deviating from the training distribution (high uncertainty).

Parameters

k: int = 1

Number of nearest neighbors used to compute the distance score.

stat: (max, mean, median, min) = "max"

Statistic applied to aggregate distances across the k neighbors.

pca: TensorPCA or None = None

Optional TensorPCA object for dimensionality reduction prior to scoring.

save_index: bool or Path = False
If True, the HNSW index is saved to a default file. If a Path is provided (must end in .bin), the index is saved there.

See Also

scores.EuclideanScore
scores.CosineScore
scores.MahalanobisScore

Methods

Name Description
knn_search() Compute the K-nearest-neighbour distances and indices for a set of query embeddings.