CutPolicy#

class scikitplot.corpus.CutPolicy(mode, threshold=None, min_k=1, max_k=None)[source]#

A rule for how many ranked hits to keep.

Parameters:
mode{“fixed”, “threshold”, “max_gap”}
thresholdfloat or None, default=None

Required for "threshold", in [0, 1]; refused otherwise.

min_kint, default=1

Fewest hits kept (when there are that many).

max_kint or None, default=None

Most hits kept; required for "fixed".

Raises:
ValueError

For an unknown mode, a missing or out-of-range threshold, a threshold given to another mode, min_k < 0, max_k < min_k, or "fixed" without max_k.

Parameters:

Examples

>>> CutPolicy("max_gap").cut([0.9, 0.85, 0.8, 0.3, 0.25]).k
3
>>> CutPolicy("threshold", threshold=0.5).cut([0.9, 0.6, 0.4]).k
2
apply(hits)[source]#

Keep the hits this policy keeps, scored by their score attribute.

Parameters:
hitssequence

Ranked hits with a score attribute (RetrievalHit).

Returns:
list

The first CutResult.k hits.

Parameters:

hits (Sequence[Any])

Return type:

list[Any]

cut(scores)[source]#

Decide how many of scores (best first) to keep.

Parameters:
scoressequence of float

Ranked scores, non-increasing and finite.

Returns:
CutResult
Raises:
ValueError

If the scores increase anywhere, are not finite, or – for "threshold" – lie outside [0, 1].

Parameters:

scores (Sequence[float])

Return type:

CutResult

max_k: int | None = None#
min_k: int = 1#
mode: str[source]#
threshold: float | None = None#