lenskit.algorithms.mf_common#

Common utilities & implementations for matrix factorization.

Module Attributes

M

Type of matrix factorization parameter data.

Classes

MFPredictor()

Common predictor for matrix factorization.

class lenskit.algorithms.mf_common.M#

Type of matrix factorization parameter data. Can be either Tensor or ndarray.

alias of TypeVar(‘M’, ~torch.Tensor, ~numpy.ndarray)

class lenskit.algorithms.mf_common.MFPredictor#

Bases: Predictor, Generic[M]

Common predictor for matrix factorization.

users_: Vocabulary#

Users in the model (length=:math:m).

items_: Vocabulary#

Items in the model (length=:math:n).

user_features_: M#

The \(m \times k\) user-feature matrix.

item_features_: M#

The \(m \times k\) user-feature matrix.

property n_features#

The number of features.

property n_users#

The number of users.

property n_items#

The number of items.

lookup_user(user)#

Look up the index for a user.

Parameters:

user – the user ID to look up

Returns:

the user index.

Return type:

int

lookup_items(items)#

Look up the indices for a set of items.

Parameters:

items (array-like) – the item IDs to look up.

Returns:

the item indices. Unknown items will have negative indices.

Return type:

numpy.ndarray

score(user, items, u_features=None)#

Score a set of items for a user. User and item parameters must be indices into the matrices.

Parameters:
  • user (int) – the user index

  • items (array-like of int) – the item indices

  • raw (bool) – if True, do return raw scores without biases added back.

Returns:

the scores for the items.

Return type:

numpy.ndarray