lenskit.metrics.ListGini#

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

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:
  • k (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.

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

Methods

__init__(*, items[, k])

compute_list_data(output, test)

Compute measurements for a single list.

extract_list_metric(metric, /)

Extract a single-list metric from the per-list measurement result (if applicable).

global_aggregate(values)

Aggregate list metrics to compute a global value.

truncate(items)

Truncate an item list if it is longer than k.

Attributes

k

The maximum length of rankings to consider.

label

Default name — class name, optionally @K.

item_count

compute_list_data(output, test)#

Compute measurements for a single list.

Parameters:

output (ItemList)

global_aggregate(values)#

Aggregate list metrics to compute a global value.

Parameters:

values (list[Array])