DRecPy.Sampler package

DRecPy.Sampler.point_sampler module

class DRecPy.Sampler.point_sampler.PointSampler(interaction_dataset, neg_ratio, interaction_threshold=None, seed=None)

Bases: object

PointSampler class that abstracts sampling positive and negative (user, item) interaction pairs.

Parameters:
  • interaction_dataset – An instance of the InteractionDataset type, representing the data set where points are being sampled from.
  • neg_ratio – The number of negative interaction pairs to be sampled for each positive interaction pair.
  • interaction_threshold – An optional integer that is used as the boundary interaction value between positive and negative interaction pairs. All values above or equal to interaction_threshold are considered positive, and all values bellow are considered negative. If none is provided, positive interactions are the ones present on the data set, and all the others are considered negative. Default: None.
  • seed – An optional integer to be used as the seed value for the pseudo-random number generated used to sample interaction pairs. Default: None.
sample(n=16)

Sample positive and negative interaction pairs according to the set definitions of the PointSampler instance.

Parameters:n – An integer representing the number of interaction pairs to be sampled. Default: 16.
Returns:A list with n triple entries, each representing either a negative or positive interaction pair. The first element on each triple represents the sampled uid (user), the second the sampled iid (item), and
the third the interaction value.
sample_negative()

Sample one negative interaction pair.

Returns:A triple representing a negative interaction pair. The first element on each triple represents the sampled uid (user), the second the sampled iid (item), and
the third the interaction value (which will always be 0).
sample_one()

Sample one positive or negative interaction pair according to the set definitions of the PointSampler instance.

Returns:A triple representing either a negative or positive interaction pair. The first element on each triple represents the sampled uid (user), the second the sampled iid (item), and
the third the interaction value.
sample_positive()

Sample one positive interaction pair.

Returns:A triple representing a positive interaction pair. The first element on each triple represents the sampled uid (user), the second the sampled iid (item), and
the third the interaction value.