FusionPolicy#
- class scikitplot.corpus.FusionPolicy(k=60, weights=(), default_weight=1.0, top_k=None)[source]#
Weighted reciprocal rank fusion with one tie-break and returned contributions.
- Parameters:
- kint, optional
The RRF constant, at least 1. Default 60.
- weightsmapping of str to float, or tuple of (str, float) pairs, optional
Weight per leg name. Finite and non-negative; a weight of 0 removes the leg. Stored as a tuple of pairs sorted by leg name, so
dict(weights)reads it back and the policy is hashable.- default_weightfloat, optional
Weight of a leg that
weightsdoes not name. Default 1.0.- top_kint or None, optional
Number of items to return, at least 0;
Nonereturns every item.
- Raises:
- TypeError
If
kortop_kis not an int (boolincluded), a weight is not a real number, or a leg name is not astr.- ValueError
If
k < 1,top_k < 0, or a weight is negative or not finite.
- Parameters:
Examples
>>> FusionPolicy.from_alpha(0.0).fuse([("lexical", ["a"]), ("dense", ["z"])])[0].key 'a' >>> len(FusionPolicy.from_alpha(0.0).fuse([("lexical", ["a"]), ("dense", ["z"])])) 1
- classmethod from_alpha(alpha, *, k=60, top_k=None, lexical='lexical', dense='dense')[source]#
Return the two-leg policy that
alphais shorthand for.- Parameters:
- alphafloat
Dense share in
[0, 1]:{lexical: 1 - alpha, dense: alpha}.0is the lexical leg alone and1the dense leg alone.- kint, optional
The RRF constant. Default 60.
- top_kint or None, optional
Number of items to return.
- lexical, densestr, optional
The two leg names.
- Returns:
- FusionPolicy
Every other leg name gets weight 0.
- Raises:
- TypeError
If
alphais not a real number.- ValueError
If
alphais outside[0, 1]or not finite.
- Parameters:
- Return type:
- fuse(legs)[source]#
Fuse ranked legs into one ranking.
- Parameters:
- legsiterable of (str, iterable of str)
Each leg’s name and its keys, best first.
- Returns:
- list of FusedItem
Descending exact score, ties by ascending key, at most
top_k.
- Raises:
- TypeError
If a leg is not a
(name, keys)pair, a name is not astr, or a key is not astr.- ValueError
If a key is the empty string.
- Parameters:
- Return type: