LightFMWrapperModel
- class rectools.models.lightfm.LightFMWrapperModel(model: LightFM, epochs: int = 1, num_threads: int = 1, verbose: int = 0)[source]
Bases:
FixedColdRecoModelMixin,VectorModel[LightFMWrapperModelConfig]Wrapper for lightfm.LightFM.
See https://making.lyst.com/lightfm/docs/home.html for details of base model.
SparseFeatures are used for this model, if you use DenseFeatures, it’ll be converted to sparse. Also it’s usually better to use categorical features. If you have real features (age, price, etc.), you can binarize it.
- Parameters
model (LightFM) – Base model that will be used.
epochs (int, default 1) – Will be used as epochs parameter for LightFM.fit.
num_threads (int, default 1) – Will be used as num_threads parameter for LightFM.fit.
verbose (int, default 0) – Degree of verbose output. If 0, no output will be provided.
- Inherited-members
Methods
dumps()Serialize model to bytes.
fit(dataset, *args, **kwargs)Fit model.
fit_partial(dataset, *args, **kwargs)Fit model.
from_config(config)Create model from config.
get_config([mode, simple_types])Return model config.
get_params([simple_types, sep])Return model parameters.
get_vectors(dataset[, add_biases])Return user and item vector representations from fitted model.
load(f)Load model from file.
loads(data)Load model from bytes.
recommend(users, dataset, k, filter_viewed)Recommend items for users.
recommend_to_items(target_items, dataset, k)Recommend items for target items.
save(f)Save model to file.
Attributes
i2i_distn_threadsrecommends_for_coldrecommends_for_warmu2i_dist- config_class
alias of
LightFMWrapperModelConfig
- get_vectors(dataset: Dataset, add_biases: bool = True) Tuple[ndarray, ndarray][source]
Return user and item vector representations from fitted model.
- Parameters
dataset (Dataset) – Dataset with input data. Usually it’s the same dataset that was used to fit model.
add_biases (bool, default True) – LightFM model stores separately embeddings and biases for users and items. If False, only embeddings will be returned. If True, biases will be added as 2 first columns (see Returns section for details).
- Returns
User and item embeddings.
If add_biases is
False, shapes are(n_users, no_components)and(n_items, no_components).If add_biases is
True, shapes are(n_users, no_components + 2)and(n_items, no_components + 2). In that case(user_biases_column, ones_column)will be added to user embeddings, and(ones_column, item_biases_column)- to item embeddings. So, if you calculate user_embeddings @ item_embeddings.T, for each user-item pair you will get value user_embedding @ item_embedding + user_bias + item_bias.- Return type
(np.ndarray, np.ndarray)