Bayesian Personalized Ranking A recommender model that learns a matrix factorization embedding based off minimizing the pairwise ranking loss described in the paper `BPR: Bayesian Personalized Ranking from Implicit Feedback `_. This factory fun
(
factors=100,
learning_rate=0.01,
regularization=0.01,
dtype=np.float32,
iterations=100,
use_gpu=implicit.gpu.HAS_CUDA,
num_threads=0,
verify_negative_samples=True,
random_state=None,
)
| 5 | |
| 6 | |
| 7 | def BayesianPersonalizedRanking( |
| 8 | factors=100, |
| 9 | learning_rate=0.01, |
| 10 | regularization=0.01, |
| 11 | dtype=np.float32, |
| 12 | iterations=100, |
| 13 | use_gpu=implicit.gpu.HAS_CUDA, |
| 14 | num_threads=0, |
| 15 | verify_negative_samples=True, |
| 16 | random_state=None, |
| 17 | ): |
| 18 | """Bayesian Personalized Ranking |
| 19 | |
| 20 | A recommender model that learns a matrix factorization embedding based off minimizing the |
| 21 | pairwise ranking loss described in the paper `BPR: Bayesian Personalized Ranking from Implicit |
| 22 | Feedback <https://arxiv.org/pdf/1205.2618.pdf>`_. |
| 23 | |
| 24 | This factory function returns either the cpu implementation from implicit.cpu.bpr or |
| 25 | the gpu implementation from implicit.gpu.bpr depending on the value of the use_gpu flag. |
| 26 | |
| 27 | Parameters |
| 28 | ---------- |
| 29 | factors : int, optional |
| 30 | The number of latent factors to compute |
| 31 | learning_rate : float, optional |
| 32 | The learning rate to apply for SGD updates during training |
| 33 | regularization : float, optional |
| 34 | The regularization factor to use |
| 35 | dtype : data-type, optional |
| 36 | Specifies whether to generate 64 bit or 32 bit floating point factors |
| 37 | use_gpu : bool, optional |
| 38 | Fit on the GPU if available |
| 39 | iterations : int, optional |
| 40 | The number of training epochs to use when fitting the data |
| 41 | verify_negative_samples: bool, optional |
| 42 | When sampling negative items, check if the randomly picked negative item has actually |
| 43 | been liked by the user. This check increases the time needed to train but usually leads |
| 44 | to better predictions. |
| 45 | num_threads : int, optional |
| 46 | The number of threads to use for fitting the model. This only |
| 47 | applies for the native extensions. Specifying 0 means to default |
| 48 | to the number of cores on the machine. |
| 49 | random_state : int, RandomState or None, optional |
| 50 | The random state for seeding the initial item and user factors. |
| 51 | Default is None. |
| 52 | """ |
| 53 | |
| 54 | if use_gpu: |
| 55 | return implicit.gpu.bpr.BayesianPersonalizedRanking( |
| 56 | factors, |
| 57 | learning_rate, |
| 58 | regularization, |
| 59 | iterations=iterations, |
| 60 | verify_negative_samples=verify_negative_samples, |
| 61 | random_state=random_state, |
| 62 | ) |
| 63 | return implicit.cpu.bpr.BayesianPersonalizedRanking( |
| 64 | factors, |
no outgoing calls