lir.algorithms.percentile_rank module

class lir.algorithms.percentile_rank.PercentileRankTransformer[source]

Bases: TransformerMixin

Compute the percentile rankings of a dataset, relative to another dataset.

Rankings are in range [0, 1]. Handling ties: the maximum of the ranks that would have been assigned to all the tied values is assigned to each value.

To compute the ranks of dataset Z relative to dataset X, fit() will create a ranking function for each feature using X. transform() then applies those per-feature ranking functions to Z.

Both fit() and transform() accept an array X with one row per instance, i.e. shape (n_samples, n_features). The number of features must match between fit() and transform().

If X contains paired measurements per instance (shape (n_samples, n_features, 2)), ranking is fitted and applied independently to the first and second measurement in the pair.

fit(X: ndarray, y: ndarray | None = None) PercentileRankTransformer[source]

Fit the transformer model on the data.

Parameters:
  • X (np.ndarray) – Input array with shape (n_samples, n_features) or (n_samples, n_features, 2).

  • y (np.ndarray | None, optional) – Ignored; present for scikit-learn API compatibility.

Returns:

Fitted transformer.

Return type:

PercentileRankTransformer

transform(X: ndarray) ndarray[source]

Use the fitted model to transform input data.

Parameters:

X (np.ndarray) – Input array with shape (n_samples, n_features) or (n_samples, n_features, 2).

Returns:

Percentile ranks with the same shape as input.

Return type:

np.ndarray