lenskit.sklearn.nmf#

Nonnegative matrix factorization for implicit feedback.

This module contains a non-negative factorization implicit-feedback scorer built on sklearn.decomposition.non_negative_factorization().

Classes#

NMFConfig

Configuration for NMFScorer.

NMFScorer

Non-negative matrix factorization for implicit feedback using SciKit-Learn's

Module Contents#

class lenskit.sklearn.nmf.NMFConfig#

Bases: lenskit.config.common.EmbeddingSizeMixin, pydantic.BaseModel

Configuration for NMFScorer. See the documentation for sklearn.decomposition.non_negative_factorization() for the configuration options.

beta_loss: Literal['frobenius', 'kullback-leibler', 'itakura-saito'] = 'frobenius'#
max_iter: pydantic.PositiveInt#
embedding_size: pydantic.PositiveInt | None#

The dimension of user and item embeddings (number of latent features to learn).

alpha_W: float = 0.0#
alpha_H: float | Literal['same'] = 'same'#
l1_ratio: float = 0.0#
class lenskit.sklearn.nmf.NMFScorer(config=None, **kwargs)#

Bases: lenskit.pipeline.Component[lenskit.data.ItemList], lenskit.training.Trainable

Non-negative matrix factorization for implicit feedback using SciKit-Learn’s sklearn.decomposition.non_negative_factorization(). It computes the user and item embedding matrices using an indicator matrix as the input.

Stability:
Caller (see Stability Levels).
Parameters:
  • config (object | None)

  • kwargs (Any)

config: NMFConfig#

The component configuration object. Component classes that support configuration must redefine this attribute with their specific configuration class type, which can be a Python dataclass or a Pydantic model class.

users: lenskit.data.Vocabulary#
items: lenskit.data.Vocabulary#
user_components: lenskit.data.types.NPMatrix#
item_components: lenskit.data.types.NPMatrix#
is_trained()#

Query if this component has already been trained.

train(data, options=TrainingOptions())#

Train the model to learn its parameters from a training dataset.

Parameters:
__call__(query, items)#

Run the pipeline’s operation and produce a result. This is the key method for components to implement.

Parameters:
Return type:

lenskit.data.ItemList

Exported Aliases#

class lenskit.sklearn.nmf.EmbeddingSizeMixin#

Re-exported alias for lenskit.config.common.EmbeddingSizeMixin.

class lenskit.sklearn.nmf.Dataset#

Re-exported alias for lenskit.data.Dataset.

class lenskit.sklearn.nmf.ItemList#

Re-exported alias for lenskit.data.ItemList.

lenskit.sklearn.nmf.QueryInput#

Re-exported alias for lenskit.data.QueryInput.

class lenskit.sklearn.nmf.RecQuery#

Re-exported alias for lenskit.data.RecQuery.

class lenskit.sklearn.nmf.Vocabulary#

Re-exported alias for lenskit.data.Vocabulary.

lenskit.sklearn.nmf.NPMatrix#

Re-exported alias for lenskit.data.types.NPMatrix.

class lenskit.sklearn.nmf.Stopwatch#

Re-exported alias for lenskit.logging.Stopwatch.

lenskit.sklearn.nmf.get_logger()#

Re-exported alias for lenskit.logging.get_logger().

class lenskit.sklearn.nmf.Component#

Re-exported alias for lenskit.pipeline.Component.

class lenskit.sklearn.nmf.Trainable#

Re-exported alias for lenskit.training.Trainable.

class lenskit.sklearn.nmf.TrainingOptions#

Re-exported alias for lenskit.training.TrainingOptions.