lenskit.metrics.ListGini#

class lenskit.metrics.ListGini(n=None, *, k=None, items)#

Bases: GiniBase

Measure item diversity of recommendations with the Gini coefficient.

This computes the Gini coefficient of the number of lists that each item appears in.

Parameters:
  • n (int | None) – The maximum recommendation list length.

  • items (int | pd.Series | pd.DataFrame | Dataset) – The total number of items, a data frame or series of item data, or a dataset. If a frame or series is provided, its length will be used as the number of items. If a dataset is provided, its item count will be used.

  • k (int | None)

Stability:
Caller (see Stability Levels).
__init__(n=None, *, k=None, items)#
Parameters:

Methods

__init__([n, k])

extract_list_metrics(data, /)

Extract per-list metric(s) from intermediate measurement data.

measure_list(output, test)

Compute measurements for a single list.

summarize(values, /)

Aggregate intermediate values into summary statistics.

truncate(items)

Truncate an item list if it is longer than n.

Attributes

k

label

Default name — class name, optionally @N.

n

The maximum length of rankings to consider.

set_k

item_count

measure_list(output, test)#

Compute measurements for a single list.

Returns:

  • A float for simple metrics

  • Intermediate data for decomposed metrics

  • A dict mapping metric names to values for multi-metric classes

Parameters:

output (ItemList)

summarize(values, /)#

Aggregate intermediate values into summary statistics.

Returns:

A dictionary of summary statistics.

Parameters:

values (list[Array] | ChunkedArray)