icrlearn.rarity.calculate_l2class#

icrlearn.rarity.calculate_l2class(X, y, n_neighbors=5, psi=1, beta=0.5)#

Calculate L2Class rarity scores.

Parameters:
X{array-like, sparse matrix} of shape (n_samples, n_features)

The input samples. Internally, its dtype will be converted to dtype=np.float32. If a sparse matrix is provided, it will be converted into a sparse csc_matrix.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

The class labels of the input samples.

n_neighborsint, default=5

The number of neighbors to consider for the rarity score calculation.

psifloat, default=1

The exponent to scale the count of other classes. The default of 1 equates to a linear scaling.

betafloat, default=0.5

The minimum rarity score to assign to samples that are not rare.

Returns:
np.ndarray of shape (n_samples,)

The rarity scores for each sample in X. If beta is set to 0.0, the scores will be in the range [0, 1], where 0 indicates a common sample and 1 indicates a rare sample.