API ReferenceΒΆ
Metric CalculationΒΆ
The following top-level functions calculate measures using any available provider.
- ir_measures.calc(measures: Iterable[Measure], qrels: Iterable[Qrel] | pandas.DataFrame | Dict[str, Dict[str, int]], run: Iterable[ScoredDoc] | pandas.DataFrame | Dict[str, Dict[str, float]]) CalcResultsΒΆ
Returns aggregated and per-query results for these measures, qrels, and run.
- ir_measures.calc_aggregate(measures: Iterable[Measure], qrels: Iterable[Qrel] | pandas.DataFrame | Dict[str, Dict[str, int]], run: Iterable[ScoredDoc] | pandas.DataFrame | Dict[str, Dict[str, float]]) Dict[Measure, float | int]ΒΆ
Returns aggregated measure values for these measures, qrels, and run.
Base ClassesΒΆ
- class ir_measures.providers.ProviderΒΆ
The base class for all measure providers (e.g., pytrec_eval, gdeval, etc.).
A
Providerimplements the calculation logic for one or moreMeasure(e.g., nDCG, P, etc.).- calc(measures: Iterable[Measure], qrels: Iterable[Qrel] | pandas.DataFrame | Dict[str, Dict[str, int]], run: Iterable[ScoredDoc] | pandas.DataFrame | Dict[str, Dict[str, float]]) CalcResultsΒΆ
Returns aggregated and per-query results for these measures, qrels, and run.
- calc_aggregate(measures: Iterable[Measure], qrels: Iterable[Qrel] | pandas.DataFrame | Dict[str, Dict[str, int]], run: Iterable[ScoredDoc] | pandas.DataFrame | Dict[str, Dict[str, float]]) Dict[Measure, float | int]ΒΆ
Returns aggregated measure values for these measures, qrels, and run.
- class ir_measures.providers.Evaluator(measures: Iterable[Measure], qrel_qids: Iterable[str])ΒΆ
The base class for scoring runs for a given set of measures and qrels. Returned from
Provider.evaluator().- calc(run: Iterable[ScoredDoc] | pandas.DataFrame | Dict[str, Dict[str, float]]) CalcResultsΒΆ
Returns aggregated and per-query results for this run.
- class ir_measures.measures.Measure(**params)ΒΆ
ParsingΒΆ
- ir_measures.read_trec_qrels(file)ΒΆ
- ir_measures.read_trec_run(file)ΒΆ
Custom MeasuresΒΆ
See here for an example of using custom measures.
- ir_measures.define(impl: Callable[[pd.DataFrame, pd.DataFrame], Iterable[Tuple[str, float]]], name: str | None = None, support_cutoff: bool = True)ΒΆ
Defines a new custom measure from a user-specified function that is is provided all queries at once.
implis a function that accepts (qrels,run) and returns an iterable of (qid, score) tuples.Most of the time, it is probably easier to use
define_byquery(), since it operates with one query at a time.- Parameters:
impl β A function that takes two pandas DataFrames (qrels and run) and returns an iterable of (qid, score) tuples.
name β The name of the measure (optional)
support_cutoff β Whether the measure supports a cutoff parameter, which reduces the results in run.
- ir_measures.define_byquery(impl: Callable[[pd.DataFrame, pd.DataFrame], float], name: str | None = None, support_cutoff: bool = True)ΒΆ
Defines a new custom measure from a user-specified function that is called once per query.
implis a function that accepts (qrels,run) and is called once per query, returning a float value each time for the specific query.- Parameters:
impl β A function that takes two pandas DataFrames (qrels and run) and returns a float.
name β The name of the measure (optional)
support_cutoff β Whether the measure supports a cutoff parameter, which reduces the results in run.
Data ClassesΒΆ
- class ir_measures.Metric(query_id, measure, value)ΒΆ
- class ir_measures.Qrel(query_id, doc_id, relevance, iteration)ΒΆ
- class ir_measures.ScoredDoc(query_id, doc_id, score)ΒΆ
- class ir_measures.CalcResults(aggregated, per_query)ΒΆ