flurs.baseline.Popular
- class flurs.baseline.Popular[source]
Popularity-based non-personalized baseline that prioritizes items observed most through update, regardless of user profiles.
Methods
__init__
()get_params
([deep])Get parameters for this estimator.
Initialize a recommender by resetting stored users and items.
is_new_item
(i)Check if an item is already registered to a recommender.
is_new_user
(u)Check if a user is already registered to a recommender.
recommend
(user, candidates)Recommend items for a user by calculating sorted list of item candidates.
register
(actor)Register a user or item to a recommender.
register_item
(item)Register an item to a recommender with an empty dictionary that is potentially used to record any auxiliary information.
register_user
(user)Register a user to a recommender with an empty dictionary that records a set of item indices observed in the past.
score
(user, candidates)Compute scores for the pairs of given user and item candidates.
scores2recos
(scores, candidates[, rev])Get recommendation list for a user based on scores.
set_params
(**params)Set the parameters of this estimator.
update
(e[, batch_train])Update model parameters given a single user-item interaction.
- get_params(deep=True)
Get parameters for this estimator.
- Parameters
deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns
params – Parameter names mapped to their values.
- Return type
dict
- initialize()[source]
Initialize a recommender by resetting stored users and items. Default the number of users and items to zero.
- is_new_item(i)[source]
Check if an item is already registered to a recommender.
- Parameters
i (int) – Item index.
- Returns
Whether the item is new.
- Return type
bool
- is_new_user(u)[source]
Check if a user is already registered to a recommender.
- Parameters
u (int) – User index.
- Returns
Whether the user is new.
- Return type
bool
- recommend(user, candidates)[source]
Recommend items for a user by calculating sorted list of item candidates.
Scores are computed.
scores2recos() is called to convert the scores into a recommendation list.
- Parameters
user (User) – Target user.
candidates (numpy array, (# target items, )) – Target items indices. Only these items are considered as the recommendation candidates.
- Returns
A tuple of
(sorted list of item indices, sorted scores)
.- Return type
(array, array)
- register(actor)[source]
Register a user or item to a recommender. Delegate the process to register_user or register_item.
- register_item(item)[source]
Register an item to a recommender with an empty dictionary that is potentially used to record any auxiliary information.
- Parameters
item (Item) – A Item instance to register.
- register_user(user)[source]
Register a user to a recommender with an empty dictionary that records a set of item indices observed in the past.
- Parameters
user (User) – A User instance to register.
- score(user, candidates)[source]
Compute scores for the pairs of given user and item candidates.
- Parameters
user (User) – Target user.
candidates (numpy array, (# candidates, )) – Target item indices.
- Returns
Predicted values for the given user-candidates pairs.
- Return type
array, (# candidates, )
- scores2recos(scores, candidates, rev=False)[source]
Get recommendation list for a user based on scores.
- Parameters
scores (numpy array, (n_target_items,)) – Scores for the target items. Smaller score indicates a promising item.
candidates (numpy array, (# target items, )) – Target items indices. Only these items are considered as the recommendation candidates.
rev (bool, default=False) – If
True
, sort and return items in an descending order. The default is an ascending order (i.e., smaller scores are more promising).
- Returns
A tuple of
(sorted list of item indices, sorted scores)
.- Return type
(array, array)
- set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters
**params (dict) – Estimator parameters.
- Returns
self – Estimator instance.
- Return type
estimator instance
- update(e, batch_train=False)[source]
Update model parameters given a single user-item interaction.
- Parameters
e (Event) – Observed event representing a user-item interaction.
batch_train (bool) – Let recommender know if the update operation is part of batch training rather than incremental, online update.