Code Monkey home page Code Monkey logo

Comments (1)

iYiYaHa avatar iYiYaHa commented on September 26, 2024

函数参数 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

from tensorflow_practice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.