lenskit.implicit#

Classes

ALS(*args[, weight])

LensKit interface to implicit.cpu.als (or GPU version).

BPR(*args, **kwargs)

LensKit interface to implicit.cpu.bpr (or GPU version).

BaseRec(delegate)

Base class for Implicit-backed recommenders.

class lenskit.implicit.BaseRec(delegate)#

Bases: Recommender, Predictor

Base class for Implicit-backed recommenders.

Parameters:

delegate (implicit.RecommenderBase) – The delegate algorithm.

delegate#

The implicit delegate algorithm.

Type:

implicit.RecommenderBase

matrix_#

The user-item rating matrix.

Type:

scipy.sparse.csr_matrix

user_index_#

The user index.

Type:

pandas.Index

item_index_#

The item index.

Type:

pandas.Index

matrix_: csr_matrix#

The user-item rating matrix from training.

users_: Vocabulary#

The user ID mapping from training.

items_: Vocabulary#

The item ID mapping from training.

delegate: RecommenderBase#

The delegate algorithm from implicit.

weight: float#

The weight for positive examples (only used by some algorithms).

fit(data, **kwargs)#

Train a model using the specified ratings (or similar) data.

Parameters:
  • data (Dataset) – The training data.

  • kwargs – Additional training data the algorithm may require. Algorithms should avoid using the same keyword arguments for different purposes, so that they can be more easily hybridized.

Returns:

The algorithm object.

recommend(user, n=None, candidates=None, ratings=None)#

Compute recommendations for a user.

Parameters:
  • user – the user ID

  • n (int) – the number of recommendations to produce (None for unlimited)

  • candidates (array-like) – The set of valid candidate items; if None, a default set will be used. For many algorithms, this is their CandidateSelector.

  • ratings (pandas.Series) – the user’s ratings (indexed by item id); if provided, they may be used to override or augment the model’s notion of a user’s preferences.

Returns:

a frame with an item column; if the recommender also produces scores, they will be in a score column.

Return type:

pandas.DataFrame

predict_for_user(user, items, ratings=None)#

Compute predictions for a user and items.

Parameters:
  • user – the user ID

  • items (array-like) – the items to predict

  • ratings (pandas.Series) – the user’s ratings (indexed by item id); if provided, they may be used to override or augment the model’s notion of a user’s preferences.

Returns:

scores for the items, indexed by item id.

Return type:

pandas.Series

get_params(deep=True)#

Get the parameters for this algorithm (as in scikit-learn). Algorithm parameters should match constructor argument names.

The default implementation returns all attributes that match a constructor parameter name. It should be compatible with sklearn.base.BaseEstimator.get_params() method so that LensKit alogrithms can be cloned with sklearn.base.clone() as well as lenskit.util.clone().

Returns:

the algorithm parameters.

Return type:

dict

class lenskit.implicit.ALS(*args, weight=40.0, **kwargs)#

Bases: BaseRec

LensKit interface to implicit.cpu.als (or GPU version).

Parameters:

weight (float)

class lenskit.implicit.BPR(*args, **kwargs)#

Bases: BaseRec

LensKit interface to implicit.cpu.bpr (or GPU version).