flurs.recommender.SketchRecommender
- class flurs.recommender.SketchRecommender(p=None, k=40, ell=- 1, r=- 1, proj='Raw')[source]
Online matrix sketching using Frequent Directions 1.
- Parameters
p (int) – Number of dimensions of an input vector.
k (int, default=40) – Number of dimensions of a projected vector.
ell (int, default=-1) – Upper bound for the number of tracked orthogonal bases \(\ell\). Defaults to \(\sqrt{k}\) if the value is negative.
r (int, default=-1) – Number of tracked orthogonal bases. Defaults to \(\ell / 2\) (ceiled).
proj (str, default='Raw') – Vector projection method for dimensionality reduction. Options are {‘Raw’, ‘RandomProjection’, ‘RandomMaclaurinProjection’, ‘TensorSketchProjection’}. See flurs.utils.projection for the detail.
References
- 1
E. Liberty. Simple and Deterministic Matrix Sketching. In Proc. of KDD 2013, pages 581-588, Aug. 2013.
- 2
T. Kitazawa. Sketching Dynamic User-Item Interactions for Online Item Recommendation. In Proc. of CHIIR 2017, March 2017.
Methods
__init__
([p, k, ell, r, proj])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, context)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[, context])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.
update_model
(y)- 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, context)[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.
context ((numpy array)) – Feature vector representing contextual information.
- 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, context=array([], dtype=float64))[source]
Compute scores for the pairs of given user and item candidates.
- Parameters
user (User) – Target user.
candidates (numpy array, (# candidates, )) – Target item indices.
context ((numpy array)) – Feature vector representing contextual information.
- 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.