lenskit.data.RelationshipSet#

class lenskit.data.RelationshipSet(ds, name, schema, table)#

Bases: object

Representation for a set of relationship records. This is the class for accessing general relationships, with arbitrarily many entity classes involved and repeated relationships allowed.

For two-entity relationships without duplicates (including relationships formed by coalescing repeated relationships or interactions), MatrixRelationshipSet extends this with additional capabilities.

Relationship sets can be pickled or serialized, and will not save the entire dataset with them. They are therefore safe to save as component elements during training processes.

Parameters:
__init__(ds, name, schema, table)#
Parameters:

Methods

__init__(ds, name, schema, table)

arrow(*[, attributes, ids])

Get these relationships and their attributes as a PyArrow table.

count()

matrix(*[, combine])

Convert this relationship set into a matrix, coalescing duplicate observations.

pandas(*[, attributes, ids])

Get these relationship and their attributes as a PyArrow table.

Attributes

attribute_names

is_interaction

Query whether these relationships represent interactions.

name

The name of the relationship class for these relationships.

schema

name: str#

The name of the relationship class for these relationships.

property is_interaction: bool#

Query whether these relationships represent interactions.

arrow(*, attributes=None, ids=False)#

Get these relationships and their attributes as a PyArrow table.

Parameters:
  • attributes (str | list[str] | None) – The attributes to select.

  • ids – If True, include ID columns for the entities, instead of just the number columns.

Return type:

Table

pandas(*, attributes=None, ids=False)#

Get these relationship and their attributes as a PyArrow table.

Parameters:
  • attributes (str | list[str] | None) – The attributes to include in the resulting table.

  • ids – If True, include ID columns for the entities, instead of just the number columns.

Return type:

DataFrame

matrix(*, combine=None)#

Convert this relationship set into a matrix, coalescing duplicate observations.

Parameters:

combine (Literal['count', 'sum', 'mean', 'first', 'last'] | ~collections.abc.Mapping[str, ~typing.Literal['count', 'sum', 'mean', 'first', 'last']] | None) – The method for combining attribute values for repeated relationships or interactions. Can either be a single strategy or a mapping from attribute names to combination strategies.

Return type:

MatrixRelationshipSet