recpack.algorithms.EASE
- class recpack.algorithms.EASE(l2=1000.0, alpha=0, density=None)
Implementation of the EASEr algorithm.
Implementation of the Embarrassingly Shallow Autoencoder as presented in Steck, Harald. “Embarrassingly shallow autoencoders for sparse data.” The World Wide Web Conference. 2019.
The algorithm essentially computes a high-dimensional linear autoencoder. Constructs a similarity matrix \(B\) with 0 diagonal which minimises:
\[||X \cdot \text{diagMat}(w) - X \cdot B||_F^2 + \lambda \cdot ||B||_F^2\]where \(w\) is an array with importance weights per item: \(w_i = \frac{1}{pop(i)^\alpha}\)
Thanks to a closed form solution this algorithm has a significant speed up compared to the SLIM algorithm on which it is based.
Warning
Memory consumption scales worse than quadratically in the amount of items. So check the size of the input matrix before using this algorithm.
- Parameters
l2 (float, optional) – Regularization parameter to avoid overfitting, defaults to 1e3.
alpha (int, optional) – Parameter to punish popular items. Each similarity score between items i and j is divided by count(j)**alpha. Defaults to 0
density (float, optional) – Parameter to reduce density of the output matrix, significantly speeds up and reduces memory footprint of prediction with only a small loss of accuracy. Does not impact memory consumption of training. Defaults to None
Methods
fit
(X)Fit the model to the input interaction matrix.
Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
predict
(X)Predicts scores, given the interactions in X
set_params
(**params)Set the parameters of the estimator.
Attributes
Name of the object.
Name of the object's class.
- fit(X: Union[recpack.matrix.interaction_matrix.InteractionMatrix, scipy.sparse._csr.csr_matrix]) recpack.algorithms.base.Algorithm
Fit the model to the input interaction matrix.
After fitting the model will be ready to use for prediction.
This function will handle some generic bookkeeping for each of the child classes,
The fit function gets timed, and this will get printed
Input data is converted to expected type using call to
_transform_predict_input()
The model is trained using the
_fit()
method_check_fit_complete()
is called to check fitting was succesful
- Parameters
X (Matrix) – The interactions to fit the model on.
- Returns
self, fitted algorithm
- Return type
- get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns
routing – A
MetadataRequest
encapsulating routing information.- Return type
MetadataRequest
- get_params(deep=True)
Get parameters for this estimator.
- Parameters
deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns
params – Parameter names mapped to their values.
- Return type
dict
- property identifier
Name of the object.
Name is made by combining the class name with the parameters passed at construction time.
Constructed by recreating the initialisation call. Example:
Algorithm(param_1=value)
- property name
Name of the object’s class.
- predict(X: Union[recpack.matrix.interaction_matrix.InteractionMatrix, scipy.sparse._csr.csr_matrix]) scipy.sparse._csr.csr_matrix
Predicts scores, given the interactions in X
Recommends items for each nonzero user in the X matrix.
This function is a wrapper around the
_predict()
method, and performs checks on in- and output data to guarantee proper computation.Checks that model is fitted correctly
checks the output using
_check_prediction()
function
- Parameters
X (Matrix) – interactions to predict from.
- Returns
The recommendation scores in a sparse matrix format.
- Return type
csr_matrix
- set_params(**params)
Set the parameters of the estimator.
- Parameters
params (dict) – Estimator parameters