lenskit.data.MatrixRelationshipSet#
- class lenskit.data.MatrixRelationshipSet(ds, name, schema, table)#
Bases:
RelationshipSet
Two-entity relationships without duplicates, accessible in matrix form.
- Parameters:
ds (Dataset)
name (str)
schema (RelationshipSchema)
table (pa.Table)
- __init__(ds, name, schema, table)#
- Parameters:
ds (Dataset)
name (str)
schema (RelationshipSchema)
table (Table)
Methods
__init__
(ds, name, schema, table)arrow
(*[, attributes, ids])Get these relationships and their attributes as a PyArrow table.
col_stats
()count
()Get the compressed sparse row structure of this relationship matrix.
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.
row_items
([id, number])Get a single row of this interaction matrix as an item list. Only valid when the column entity class is ``item''.
row_stats
()row_table
([id, number])Get a single row of this interaction matrix as a table.
scipy
([attribute, layout, legacy])Get this relationship matrix as a SciPy sparse matrix.
torch
([attribute, layout])Get this relationship matrix as a PyTorch sparse tensor.
Attributes
attribute_names
is_interaction
Query whether these relationships represent interactions.
row_vocabulary
row_type
col_vocabulary
col_type
name
The name of the relationship class for these relationships.
schema
- matrix(*, combine=None)#
Convert this relationship set into a matrix, coalescing duplicate observations.
- Parameters:
combine (Literal['count', 'sum', 'mean', 'first', 'last'] | dict[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:
- csr_structure()#
Get the compressed sparse row structure of this relationship matrix.
- Return type:
- scipy(attribute=None, *, layout='csr', legacy=False)#
Get this relationship matrix as a SciPy sparse matrix.
- torch(attribute=None, *, layout='csr')#
Get this relationship matrix as a PyTorch sparse tensor.
- row_table(id=None, *, number=None)#
Get a single row of this interaction matrix as a table.