recpack.algorithms.ItemSimilarityMatrixAlgorithm
- class recpack.algorithms.ItemSimilarityMatrixAlgorithm
Base algorithm for algorithms that fit an item to item similarity model
Model that encodes the similarity between items is expected under the
similarity_matrix_
attribute.This matrix should have shape
(|items| x |items|)
. This can be dense or sparse matrix depending on the algorithm used.Predictions are made by computing the dot product of the history vector of a user and the similarity matrix.
Usually a new algorithm will have to implement just the
_fit()
method, to construct the self.similarity_matrix_ attribute.Methods
Helper function to check if model was correctly fitted
_predict
(X)Predict scores for nonzero users in X
Attributes
identifier
Name of the object.
name
Name of the object's class.
- _check_fit_complete()
Helper function to check if model was correctly fitted
Checks implemented:
Checks if the algorithm has been fitted, using sklearn’s check_is_fitted
Checks if the fitted similarity matrix contains similar items for each item
For failing checks a warning is printed.
- _predict(X: scipy.sparse._csr.csr_matrix) scipy.sparse._csr.csr_matrix
Predict scores for nonzero users in X
Scores are computed by matrix multiplication of X with the stored similarity matrix.
- Parameters
X (csr_matrix) – csr_matrix with interactions
- Returns
csr_matrix with scores
- Return type
csr_matrix