recpack.algorithms.WeightedMatrixFactorization
- class recpack.algorithms.WeightedMatrixFactorization(confidence_scheme: str = 'minimal', alpha: int = 40, epsilon: float = 1e-08, num_components: int = 100, regularization: float = 0.01, iterations: int = 20, batch_size: int = 100)
WMF Algorithm by Yifan Hu, Yehuda Koren and Chris Volinsky et al.
As described in Hu, Yifan, Yehuda Koren, and Chris Volinsky. “Collaborative filtering for implicit feedback datasets.” 2008 Eighth IEEE International Conference on Data Mining. Ieee, 2008
Based on the input data a confidence of the interaction is computed. Parametrized by alpha and epsilon (hyper parameters)
If the chosen confidence scheme is
'minimal'
, confidence is computed asc(u,i) = 1 + alpha * r(u,i)
.If the chosen confidence scheme is
'log-scaling'
, confidence is computed asc(u,i) = 1 + alpha * log(1 + r(u,i)/epsilon)
Since the data during fitting is assumed to be implicit, this confidence will be the same for all interactions, and as such leaving the HP to the defaults works well enough.
- Parameters
confidence_scheme (string, optional) – Which confidence scheme should be used to calculate the confidence matrix. Options are [“minimal”, “log-scaling”]. Defaults to “minimal”
alpha (int, optional) – Scaling parameter for generating confidences from ratings. Defaults to 40.
epsilon (float, optional) – Small value to avoid division by zero, used to compute a confidence from a rating. Only used in case cs is set to ‘log-scaling’ Defaults to 1e-8
num_components (int, optional) – Dimension of the embeddings of both user- and item-factors. Defaults to 100
regularization (float, optional) – Regularization parameter used to calculate the Least Squares. Defaults to 0.01
iterations (int, optional) – Number of iterations to execute the ALS calculations. Defaults to 20
batch_size (int, optional) – Number of users/items to process in every mini batch. Defaults to 100
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
Allowed values for confidence scheme parameter
Name of the object.
Name of the object's class.
- CONFIDENCE_SCHEMES = ['minimal', 'log-scaling']
Allowed values for confidence scheme parameter
- 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