楼主: ReneeBK
670 4

Using theano_bpr for Recommendations [推广有奖]

  • 1关注
  • 62粉丝

VIP

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49407 个
通用积分
51.8704
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57815 点
帖子
4006
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
  1. Using theano_bpr for recommendations

  2. Bayesian Personalised Ranking (BPR) is a state-of-the-art algorithm for predicting personalised preferences over a range of items from implicit feedback. One of the main difference with other machine learning approaches for item recommenders is that it doesn't assume that unseen items are items that weren't liked by a user.
  3. BPR is also used for a number of other use-cases, such as tag and link prediction, matrix completion, etc.
复制代码
  1. Loading data

  2. We start by loading training and testing data from Movielens data. The theano_bpr library provides a small utility function for that, which will extract all user-item pairs for which the rating is above a given threshold and map user and item identifiers to coordinates in a user-item matrix.
  3. In [1]:
  4. from theano_bpr.utils import load_data_from_movielens
  5. In [2]:
  6. training_data, users_to_index, items_to_index = load_data_from_movielens('http://files.grouplens.org/datasets/movielens/ml-100k/ua.base', 3)

  7. This function returns three things
  8. Entries in the user-item matrix
  9. In [3]:
  10. training_data[0:5]

  11. A mapping from user identifiers to coordinates
  12. In [4]:
  13. users_to_index.keys()[0:10]

  14. In [5]:
  15. users_to_index['811']



  16. A mapping from item identifiers (in our case programme identifiers) to coordinates
  17. In [6]:
  18. items_to_index.keys()[0:10]

  19. In [7]:
  20. items_to_index['349']

  21. We now load the testing data, in the same way. The only difference is the two extra parameters, which define initial coordinates for users and items (the ones generated from the training data).
  22. In [8]:
  23. testing_data, users_to_index, items_to_index = load_data_from_movielens('http://files.grouplens.org/datasets/movielens/ml-100k/ua.test', 3, users_to_index, items_to_index)
  24. In [9]:
  25. testing_data[0:5]

  26. We now have data for training our model, and data to test our trained model. We import the BPR class from our theano_bpr library, an implementation of Bayesian Personalised Ranking for Matrix Factorisation, using the Theano machine learning library.
复制代码


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Recommend commend Theano Using ATION

沙发
ReneeBK 发表于 2017-9-11 02:59:02 |只看作者 |坛友微信交流群
  1. Training a BPR model
  2. In [10]:from theano_bpr import BPR

  3. We create a new BPR object. The required initialisation arguments are:
  4. The number of latent dimensions in our matrix factorisation model
  5. The total number of users
  6. The total number of items
  7. In [18]:bpr = BPR(10, len(users_to_index.keys()), len(items_to_index.keys()))

  8. We now train our BPR matrix factorisation model using our training data. We can also define the number of iterations through the entire training data at this stage. The actual learning will be done through stochastic gradient descent over the training data, with randomly sampled batches of training data (uniform user sampling to make sure we don't skew the model towards very active users).
  9. For training, we recommend using a GPU or multithreaded OpenBLAS.
  10. In [19]:bpr.train(training_data, epochs=50)
复制代码

使用道具

藤椅
ReneeBK 发表于 2017-9-11 02:59:31 |只看作者 |坛友微信交流群
  1. Testing a BPR model

  2. We can now evaluate how well our trained model is doing over our test data. How accurately can it predict user viewings in the testing dataset? The metric we use to quantify that is the Area Under Curve (AUC) measure.
  3. In [20]:
  4. bpr.test(testing_data)
复制代码

使用道具

板凳
MouJack007 发表于 2017-9-11 06:48:31 |只看作者 |坛友微信交流群
谢谢楼主分享!

使用道具

报纸
MouJack007 发表于 2017-9-11 06:49:24 |只看作者 |坛友微信交流群

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-1 02:04