lenskit.knn.user#
User-based k-NN collaborative filtering.
Functions
|
Classes
|
Configuration for |
|
User-user nearest-neighbor collaborative filtering with ratings. |
|
Dense user ratings. |
- class lenskit.knn.user.UserKNNConfig(*, max_nbrs=20, min_nbrs=1, min_sim=1e-06, feedback='explicit')#
Bases:
BaseModel
Configuration for
ItemKNNScorer
.- Parameters:
- max_nbrs: PositiveInt#
The maximum number of neighbors for scoring each item.
- min_nbrs: PositiveInt#
The minimum number of neighbors for scoring each item.
- min_sim: PositiveFloat#
Minimum similarity threshold for considering a neighbor. Must be positive; if less than the smallest 32-bit normal (\(1.175 \times 10^{-38}\)), is clamped to that value.
- feedback: FeedbackType#
The type of input data to use (explicit or implicit). This affects data pre-processing and aggregation.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class lenskit.knn.user.UserKNNScorer(config=None, **kwargs)#
Bases:
Component
[ItemList
, …],Trainable
User-user nearest-neighbor collaborative filtering with ratings. This user-user implementation is not terribly configurable; it hard-codes design decisions found to work well in the previous Java-based LensKit code.
Note
This component must be used with queries containing the user’s history, either directly in the input or by wiring its query input to the output of a user history component (e.g.,
UserTrainingHistoryLookup
).- Stability:
- Caller (see Stability Levels).
- Parameters:
config (UserKNNConfig)
kwargs (Any)
- users_: Vocabulary#
The index of user IDs.
- items_: Vocabulary#
The index of item IDs.
- train(data, options=TrainingOptions(retrain=True, device=None, rng=None))#
“Train” a user-user CF model. This memorizes the rating data in a format that is usable for future computations.
- Parameters:
ratings (pandas.DataFrame) – (user, item, rating) data for collaborative filtering.
data (Dataset)
options (TrainingOptions)