Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于IRGAN的问题 #46

Open
aMIT-feat-aMEI opened this issue Oct 16, 2019 · 1 comment
Open

关于IRGAN的问题 #46

aMIT-feat-aMEI opened this issue Oct 16, 2019 · 1 comment

Comments

@aMIT-feat-aMEI
Copy link

aMIT-feat-aMEI commented Oct 16, 2019

`def simple_test_one_user(x):

rating = x[0]
u = x[1]
test_items = list(all_items - set(user_pos_train[u]))
item_score=[]
for i in test_items:
    item_score.append((i,rating[i]))
item_score = sorted(item_score,key=lambda x:x[1])
item_score.reverse()
item_sort = [x[0] for x in item_score]`

关于上面这段代码里的x是一个什么样的形式
item_score.append((i,rating[i])) item_sort = [x[0] for x in item_score]`` 从上面这两句里面看,x应该是{(i,rating[i])}的形式,i是不是items,后面的是评分,而一开始定义的 rating = x[0] ,u = x[1]`,所以这里不是太懂,x是什么 样的形式,x[0],x[1]又是代表什么,不知道能不能给解释下,谢谢

@iYiYaHa
Copy link

iYiYaHa commented Nov 20, 2019

函数参数 x 和最后的列表解析式中的 x 意义是不同的。
simple_test_one_user 中的 x 为 (user 对所有 item 的评分,user)
item_scores 中的每一个 element 是 (item, item 对应的 score), 即在 item_sort = [x[0] for x in item_score] 中 x[0] 是指 item,x[1] 指 item 对应的 score。

所以这一部分代码的意思如下:

def simple_test_one_user(x):# 
  rating = x[0] # user 对所有 item 的评分
  u = x[1] # user
  test_items = list(all_items - set(user_pos_train[u])) # 删除user 已经购买过的 item
  item_score=[]
  for i in test_items:# test_items 中的元素是 item 和 item 对应的 score 组成的 pair,即(item_id, item_score)
      item_score.append((i,rating[i]))
  item_score = sorted(item_score,key=lambda x:x[1])# 将上述 pairs 按照 score 进行从小到大排序
  item_score.reverse() # 将上述 pairs 按照 score 从大到小排序
  item_sort = [x[0] for x in item_score]` # 取出按照 score 从大到小排序过后的所有 item

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants