PopularInCategoryModel
- class rectools.models.popular_in_category.PopularInCategoryModel(category_feature: str, n_categories: Optional[int] = None, mixing_strategy: Literal['rotate', 'group'] = 'rotate', ratio_strategy: Literal['proportional', 'equal'] = 'proportional', popularity: Literal['n_users', 'n_interactions', 'mean_weight', 'sum_weight'] = 'n_users', period: Optional[timedelta] = None, begin_from: Optional[datetime] = None, add_cold: bool = False, inverse: bool = False, verbose: int = 0)[source]
Bases:
FixedColdRecoModelMixin,PopularModelMixin,ModelBase[PopularInCategoryModelConfig]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 areNoneall 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 areNoneall interactions will be used.add_cold (bool, default
False) – IfTruecold 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) – IfTrueleast popular items will be selected.verbose (int, default
0) – Degree of verbose output. If0, no output will be provided.
- Inherited-members
Methods
dumps()Serialize model to bytes.
fit(dataset, *args, **kwargs)Fit model.
fit_partial(dataset, *args, **kwargs)Fit model.
from_config(config)Create model from config.
from_params(params[, sep])Create model from parameters.
get_config([mode, simple_types])Return model config.
get_params([simple_types, sep])Return model parameters.
load(f)Load model from file.
loads(data)Load model from bytes.
recommend(users, dataset, k, filter_viewed)Recommend items for users.
recommend_to_items(target_items, dataset, k)Recommend items for target items.
save(f)Save model to file.
Attributes
recommends_for_coldrecommends_for_warmrequire_recommend_contextIndicates whether recommendation context is required for predictions.
- config_class
alias of
PopularInCategoryModelConfig