V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
tezo
V2EX  ›  Python

一个入门电影推荐算法题,希望能给点思路和伪代码

  •  
  •   tezo · 2021-04-08 11:34:37 +08:00 · 873 次点击
    这是一个创建于 1113 天前的主题,其中的信息可能已经有所发展或是发生改变。
    本人 python 初学者,现在在算法课程中遇到一个问题,希望大家给点思路。
    这是一个简单电影推荐算法的题目。题目会给 3 个 list. movies = ["Parasite","1917","Ford v Ferrari","Jojo Rabbit","Joker"]
    similarities = [["Parasite", "1917"],
    ["Parasite", "Jojo Rabbit"],
    ["Joker", "Ford v Ferrari"]]
    friends = [["Joker"],
    ["Joker","1917"],
    ["Joker"],
    ["Parasite"],
    ["1917"],
    ["Jojo Rabbit", "Joker"]]
    Movies 里有 5 部电影。Similarities 代表里面的两部电影是相关的,所以 parasite 和 1917 相关,同样 1917 和 jojo rabbit 也相关,因为它们都和 parasite 相关。Friends 里代码有哪些电影被看过。

    我们要得出的结果是推荐 观看度和独特性最高的那部电影。 观看度就是 friends 里出现最多的那部电影。那就是 joker
    • Joker - 4
    • 1917 - 2
    • Parasite - 1
    • Jojo Rabbit - 1
    • Ford v Ferrari - 0
    独特性计算 Uniqueness is 1 divided by the mean number of similar movies that the user's friends have already seen. Similar movies have transitive property: if movie 1 is similar to movie 2 and movie 2 is similar to movie 3 -> movie 1 is similar to movie 3 and vice versa.
    下面是每部电影的相似电影
    • Joker - 1 (Ford v Ferrari)
    • 1917 - 2 (Parasite, Jojo Rabbit)
    • Parasite - 2 (1917, Jojo Rabbit)
    • Jojo Rabbit - 2 (Parasite, 1917)
    • Ford v Ferrari - 1 (Joker)
    下面是朋友里看过这些相似电影的统计
    • Joker - 0 (None saw Ford v Ferrari)
    • 1917 - 1 (Parasite), 1 (Jojo Rabbit)
    • Parasite - 2 (1917) , 1 (Jojo Rabbit)
    • Jojo Rabbit - 1 (Parasite), 2 (1917)
    • Ford v Ferrari - 4 (Joker)

    然后计算平均数:
    • Joker - mean(0) = 0
    • 1917 - mean(1,1) = 1
    • Parasite - mean(2 ,1) = 1.5
    • Jojo Rabbit - mean(1,2) = 1.5
    • Ford v Ferrari - mean(4) = 4

    In the end we need to return movie with highest score which is calculated like this: F/S, where F = number of friends who have seen this movie and S = mean of the number of similar movies seen for each friend Let's find out what movie should we recommend:
    • Joker - 4/0 = 0
    • 1917 - 2/1 = 2
    • Parasite - 1/1.5 = 0.66666
    • Jojo Rabbit - 1/1.5 = 0.66666
    • Ford v Ferrari - 0/4 = 0

    这不是一个超级复杂的算法推荐题(但是我仍然搞不定),班里的一个同学说只需要用 dictionaries with sets (hashable data structures) and the logics loop 就能解决了,不需要用 DFS 算法之类的。
    希望大家能给点思路,最好就只用基本数据结构。
    Thanks
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4493 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:09 · PVG 18:09 · LAX 03:09 · JFK 06:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.