scores.CosineScore
Returns the KNN-distance based on the cosine distance to the nearest samples.
Usage
scores.CosineScore()Computes cosine 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).
The cosine distance is computed as (1 - cosine_similarity), with a range of [0, 2] where 0 indicates identical vectors, 1 indicates orthogonal vectors, and 2 indicates opposite vectors.
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.
Attributes
| Name | Description |
|---|---|
| ident | str(object=’’) -> str |
| k | int([x]) -> integer |
ident
str(object=’’) -> str
ident: str = "cosine"
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 = 1
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
- seapig.scores.knn.EuclideanScore: KNN score using Euclidean distance.
- seapig.scores.knn.MahalanobisScore: KNN score using Mahalanobis distance.