PopularModel

class rectools.models.popular.PopularModel(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[PopularModelConfig]

Model generating recommendations based on popularity of items.

Parameters
  • 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 are None 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 are None all interactions will be used.

  • add_cold (bool, default False) – If True 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 to 0.

  • inverse (bool, default False) – If True least popular items will be selected.

  • verbose (int, default 0) – Degree of verbose output. If 0, 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_cold

recommends_for_warm

require_recommend_context

Indicates whether recommendation context is required for predictions.

config_class

alias of PopularModelConfig