lenskit.algorithms.als.implicit#
Classes
|
Implicit matrix factorization trained with alternating least squares [HKV08]. |
- class lenskit.algorithms.als.implicit.ImplicitMF(features, *, epochs=20, reg=0.1, weight=40, use_ratings=False, rng_spec=None, save_user_features=True)#
Bases:
ALSBase
Implicit matrix factorization trained with alternating least squares [HKV08]. This algorithm outputs ‘predictions’, but they are not on a meaningful scale. If its input data contains
rating
values, these will be used as the ‘confidence’ values; otherwise, confidence will be 1 for every rated item.See the base class
MFPredictor
for documentation on the estimated parameters you can extract from a trained model.With weight \(w\), this function decomposes the matrix \(\mathbb{1}^* + Rw\), where \(\mathbb{1}^*\) is an \(m \times n\) matrix of all 1s.
Changed in version 2024.1:
ImplicitMF
no longer supports multiple training methods. It always uses Cholesky decomposition now.Changed in version 0.14: By default,
ImplicitMF
ignores arating
column if one is present in the training data. This can be changed through theuse_ratings
option.Changed in version 0.13: In versions prior to 0.13,
ImplicitMF
used the rating column if it was present. In 0.13, we added an option to control whether or not the rating column is used; it initially defaulted toTrue
, but with a warning. In 0.14 it defaults toFalse
.- Parameters:
features (int) – The number of features to train
epochs (int) – The number of iterations to train
reg (float | tuple[float, float]) – The regularization factor
weight (float) – The scaling weight for positive samples (\(\alpha\) in [HKV08]).
use_ratings (bool) – Whether to use the rating column, if present. Defaults to
False
; whenTrue
, the values from therating
column are used, and multipled byweight
; ifFalse
, ImplicitMF treats every rated user-item pair as having a rating of 1.rng_spec (Optional[SeedLike]) – Random number generator or state (see
numpy_rng()
).progress – a
tqdm.tqdm()
-compatible progress bar functionsave_user_features (bool)
- property logger#
Overridden in implementation to provide the logger.
- fit(data, **kwargs)#
Run ALS to train a model.
- Parameters:
ratings – the ratings data frame.
data (Dataset)
- Returns:
The algorithm (for chaining).
- prepare_data(data)#
Prepare data for training this model. This takes in the ratings, and is supposed to do two things:
Normalize or transform the rating/interaction data, as needed, for training.
Store any parameters learned from the normalization (e.g. means) in the appropriate member variables.
Return the training data object to use for model training.
- Parameters:
data (Dataset)
- Return type:
- initial_params(nrows, ncols)#
Compute initial parameter values of the specified shape.
- als_half_epoch(epoch, context)#
Run one half of an ALS training epoch.
- Parameters:
epoch (int)
context (TrainContext)
- Return type: