PopularInCategoryModel
- class rectools.models.popular_in_category.PopularInCategoryModel(category_feature: str, n_categories: Optional[int] = None, mixing_strategy: Optional[str] = 'rotate', ratio_strategy: Optional[str] = 'proportional', popularity: str = 'n_users', period: Optional[timedelta] = None, begin_from: Optional[datetime] = None, add_cold: bool = False, inverse: bool = False, verbose: int = 0)[source]
Bases:
PopularModel
Model generating recommendations based on popularity of items.
- Parameters
category_feature (str) – Name of category feature in item features dataframe.
n_categories (int, optional, default
None
) – Number of most popular categories to take for recommendationsmixing_strategy ({“rotate”, “group”}, default “rotate”) – Method of mixing recommendations from different categories. The following methods are available: - rotate - items from different categories take turns in final recommendations, starting from the most popular category - group - items from each category are grouped together. Categories are sorted by popularity
ratio_strategy ({“equal”, “proportional”}, default “proportional”) – Method of defining ratios for categories. The following methods are available: - equal - all categories gain equal ratios in recommendations. Exceeding places for items are given to most popular categories - proportional - categories gain ratios in recommendations based on their popularity. Each category gains at least one item in recommendations if number of categories doesn’t exceed number of recs.
popularity ({“n_users”, “n_interactions”, “mean_weight”, “sum_weight”}, default “n_users”) – Method of calculating item popularity. To evaluate popularity score the following methods are available: - n_users - number of unique users that interacted with item; - n_interactions - number of interactions with item; - mean_weight - mean item interactions weight; - sum_weight - total item interactions weight.
period (timedelta, optional, default
None
) – Period before last interaction to consider interactions for popularity calculation. Either period or begin_from can be set at once. If both areNone
all interactions will be used.begin_from (datetime, optional, default
None
) – Exact datetime to consider interactions from for popularity calculation. Either period or begin_from can be set at once. If both areNone
all interactions will be used.add_cold (bool, default
False
) – IfTrue
cold items will be added to the end of popularity list and can be recommended. Item is cold if it’s not present in interactions at all (but present in id map) or not present in last interactions defined by either period or begin_from arguments. Order of cold items is unpredictable. Cold items score will be equal to0
.inverse (bool, default
False
) – IfTrue
least popular items will be selected.verbose (int, default
0
) – Degree of verbose output. If0
, no output will be provided.
- Inherited-members
Methods
fit
(dataset, *args, **kwargs)Fit model.
recommend
(users, dataset, k, filter_viewed)Recommend items for users.
recommend_to_items
(target_items, dataset, k)Recommend items for target items.
Attributes
recommends_for_cold
recommends_for_warm