PerUserNegativeSampler

class rectools.models.ranking.candidate_ranking.PerUserNegativeSampler(n_negatives: int = 3, random_state: Optional[int] = None)[source]

Bases: NegativeSamplerBase

A negative sampler that samples a specified number of negative examples per user from the training data. This class implements a per-user negative sampling strategy, where a fixed number of negative examples are randomly selected for each user.

Inherited-members

Parameters
  • n_negatives (int) –

  • random_state (Optional[int]) –

Methods

sample_negatives(train)

Sample negative examples from the given training data for each user.

sample_negatives(train: DataFrame) DataFrame[source]

Sample negative examples from the given training data for each user.

Parameters

train (pd.DataFrame) – A DataFrame containing the training data with user-item interactions.

Returns

A DataFrame containing the sampled training data, which includes the specified number of negative examples per user along with all positive examples. The resulting DataFrame is shuffled.

Return type

pd.DataFrame