recpack.algorithms.FactorizationAlgorithm

class recpack.algorithms.FactorizationAlgorithm(num_components=100)

Base class for factorization algorithms

During fitting two matrices are constructed.

  • user_embedding_ contains the users embedded in a lower dimensional space, shape = |users| x num_components

  • item_embedding_ contains the items embedded in the same dimensions shape = num_components x |items|

Prediction happens by multiplying a user’s features with the item embedding.

Usually a child class will have to implement just the _fit() method, to construct the self.user_embedding_ and self.item_embedding_ attributes.

Parameters

num_components (int, optional) – the dimension of the feature matrices. defaults to 100

Methods

_check_fit_complete()

Helper function to check that fit stored information.

_predict(X)

Predict scores for nonzero users in the interaction matrix

Attributes

identifier

Name of the object.

name

Name of the object's class.

_check_fit_complete()

Helper function to check that fit stored information.

Checks implemented:

_predict(X: scipy.sparse._csr.csr_matrix) scipy.sparse._csr.csr_matrix

Predict scores for nonzero users in the interaction matrix

For each nonzero users their embedding is multiplied with the item embeddings, and scores are the result of this matrix multiplication.

Before recommending checks the shape of X to the number of items and users in the embeddings.

Parameters

X (csr_matrix) – binary interaction matrix.

Returns

matrix with scores for each nonzero user.

Return type

csr_matrix