KNN#
- class scio.scores.KNN(*, act_norm=2.0, mode='raw', k=?, index_metric='l2')[source]#
Bases:
BaseScoreClassifKNN for classification.
Nonconformity is the distance to \(k\)-th neighbor in the chosen latent space, after activations normalization. Note that it is independant of the predicted class.
- Parameters:
k (
int) – Number of nearest neighbors to consider.index_metric (
IndexMetricLike) – Kind of metric to use for nearest neighbors search. SeeIndexMetric.mode – See
BaseScoreClassif.act_norm – See
BaseScore. Now defaults to2.0.
Note
In [SMZL22], authors operate solely on the penultimate layer activations. Here, we stack all recorded activations, which is equivalent if and only if the network only records the penultimate layer.
References
[SMZL22]Yiyou Sun, Yifei Ming, Xiaojin Zhu, and Yixuan Li. Out-of-Distribution detection with deep nearest neighbors. In Proceedings of the 39th International Conference on Machine Learning, volume 162 of Proceedings of Machine Learning Research, 20827–20840. 2022. URL: https://proceedings.mlr.press/v162/sun22d.html.