scores.EuclideanScore

Returns the KNN-distance based on the Euclidean distance to the nearest samples.

Usage

Source

scores.EuclideanScore()

Computes Euclidean distance-based confidence scores where low scores indicate samples similar to the training distribution (likely inliers) and high scores indicate samples deviating from the training distribution (likely outliers).

Parameters

k: int = 1

Number of nearest neighbors to use.

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

Statistic to aggregate distances across the k neighbors.

pca: TensorPCA or None = None

Optional PCA for dimensionality reduction prior to scoring.

save_index: bool or Path = False
Whether (and where) to save the HNSW index to disk.

Examples

import torch
from seapig.scores import EuclideanScore
score = EuclideanScore(k=5)
score.fit(X=torch.randn(200, 64), Y=torch.randn(50, 64))
score.set_threshold(q=0.95)
result = score.select(X=torch.randn(10, 64))

Attributes

Name Description
ident str(object=’’) -> str
k int([x]) -> integer

ident

str(object=’’) -> str

ident: str = "euclidean"

str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.


k

int([x]) -> integer

k: int

int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

See Also