ML之CB:基于自定义电影数据集利用CB基于内容推荐算法(多个指标基于同种相似度加权得分)实现电影Top5推荐案例
Posted 一个处女座的程序猿
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ML之CB:基于自定义电影数据集利用CB基于内容推荐算法(多个指标基于同种相似度加权得分)实现电影Top5推荐案例相关的知识,希望对你有一定的参考价值。
ML之CB:基于自定义电影数据集利用CB基于内容推荐算法(多个指标基于同种相似度加权得分)实现电影Top5推荐案例
目录
基于自定义电影数据集利用CB基于内容推荐算法(多个指标基于同种相似度加权得分)实现电影Top5推荐案例
# 3.1、以当前为对象,逐个遍历与其计算相似度,找出Top5推荐
相关文章
ML之CB:基于自定义电影数据集利用CB基于内容推荐算法(多个指标基于同种相似度加权得分)实现电影Top5推荐案例
ML之CB:基于自定义电影数据集利用CB基于内容推荐算法(多个指标基于同种相似度加权得分)实现电影Top5推荐案例实现案例
基于自定义电影数据集利用CB基于内容推荐算法(多个指标基于同种相似度加权得分)实现电影Top5推荐案例
# 1、定义数据集
movies = [
"name": "The Shawshank Redemption",
"genres": ["Drama", "Crime"],
"director": "Frank Darabont",
"cast": ["Tim Robbins", "Morgan Freeman", "Bob Gunton"],
"rating": 9.3
,
"name": "The Godfather",
"genres": ["Drama", "Crime"],
"director": "Francis Ford Coppola",
"cast": ["Marlon Brando", "Al Pacino", "James Caan"],
"rating": 9.2
,
"name": "The Dark Knight",
"genres": ["Action", "Crime", "Drama"],
"director": "Christopher Nolan",
"cast": ["Christian Bale", "Heath Ledger", "Aaron Eckhart"],
"rating": 9.0
,
"name": "Pulp Fiction",
"genres": ["Crime", "Drama"],
"director": "Quentin Tarantino",
"cast": ["John Travolta", "Uma Thurman", "Samuel L. Jackson"],
"rating": 8.9
,
"name": "Forrest Gump",
"genres": ["Drama", "Romance"],
"director": "Robert Zemeckis",
"cast": ["Tom Hanks", "Robin Wright", "Gary Sinise"],
"rating": 8.8
,
"name": "The Matrix",
"genres": ["Action", "Sci-Fi"],
"director": "Lana Wachowski",
"cast": ["Keanu Reeves", "Laurence Fishburne", "Carrie-Anne Moss"],
"rating": 8.7
,
"name": "The Silence of the Lambs",
"genres": ["Crime", "Drama", "Thriller"],
"director": "Jonathan Demme",
"cast": ["Jodie Foster", "Anthony Hopkins", "Lawrence A. Bonney"],
"rating": 8.6
,
"name": "The Lord of the Rings: The Return of the King",
"genres": ["Action", "Adventure", "Drama"],
"director": "Peter Jackson",
"cast": ["Elijah Wood", "Viggo Mortensen", "Ian McKellen"],
"rating": 8.9
,
"name": "Inception",
"genres": ["Action", "Adventure", "Sci-Fi"],
"director": "Christopher Nolan",
"cast": ["Leonardo DiCaprio", "Joseph Gordon-Levitt", "Ellen Page"],
"rating": 8.8
,
"name": "The Godfather: Part II",
"genres": ["Drama", "Crime"],
"director": "Francis Ford Coppola",
"cast": ["Al Pacino", "Robert De Niro", "Robert Duvall"],
"rating": 9.0
]
# 2、数据集预处理
# 定义测试集
'name': 'The Shawshank Redemption', 'genres': ['Drama', 'Crime'], 'director': 'Frank Darabont', 'cast': ['Tim Robbins', 'Morgan Freeman', 'Bob Gunton'], 'rating': 9.3
# 3、模型训练与推理
# 3.1、以当前为对象,逐个遍历与其计算相似度,找出Top5推荐
similarities
[('name': 'The Godfather', 'genres': ['Drama', 'Crime'], 'director': 'Francis Ford Coppola', 'cast': ['Marlon Brando', 'Al Pacino', 'James Caan'], 'rating': 9.2, 0.4),
('name': 'Pulp Fiction', 'genres': ['Crime', 'Drama'], 'director': 'Quentin Tarantino', 'cast': ['John Travolta', 'Uma Thurman', 'Samuel L. Jackson'], 'rating': 8.9, 0.4),
('name': 'The Godfather: Part II', 'genres': ['Drama', 'Crime'], 'director': 'Francis Ford Coppola', 'cast': ['Al Pacino', 'Robert De Niro', 'Robert Duvall'], 'rating': 9.0, 0.4),
('name': 'The Dark Knight', 'genres': ['Action', 'Crime', 'Drama'], 'director': 'Christopher Nolan', 'cast': ['Christian Bale', 'Heath Ledger', 'Aaron Eckhart'], 'rating': 9.0, 0.26666666666666666),
('name': 'The Silence of the Lambs', 'genres': ['Crime', 'Drama', 'Thriller'], 'director': 'Jonathan Demme', 'cast': ['Jodie Foster', 'Anthony Hopkins', 'Lawrence A. Bonney'], 'rating': 8.6, 0.26666666666666666),
('name': 'Forrest Gump', 'genres': ['Drama', 'Romance'], 'director': 'Robert Zemeckis', 'cast': ['Tom Hanks', 'Robin Wright', 'Gary Sinise'], 'rating': 8.8, 0.13333333333333333),
('name': 'The Lord of the Rings: The Return of the King', 'genres': ['Action', 'Adventure', 'Drama'], 'director': 'Peter Jackson', 'cast': ['Elijah Wood', 'Viggo Mortensen', 'Ian McKellen'], 'rating': 8.9, 0.1),
('name': 'The Matrix', 'genres': ['Action', 'Sci-Fi'], 'director': 'Lana Wachowski', 'cast': ['Keanu Reeves', 'Laurence Fishburne', 'Carrie-Anne Moss'], 'rating': 8.7, 0.0),
('name': 'Inception', 'genres': ['Action', 'Adventure', 'Sci-Fi'], 'director': 'Christopher Nolan', 'cast': ['Leonardo DiCaprio', 'Joseph Gordon-Levitt', 'Ellen Page'], 'rating': 8.8, 0.0)]
# 3.2、基于测试集,输出Top 5推荐
喜欢的电影: The Shawshank Redemption
推荐的电影:
The Godfather 9.2
Pulp Fiction 8.9
The Godfather: Part II 9.0
The Dark Knight 9.0
The Silence of the Lambs 8.6
以上是关于ML之CB:基于自定义电影数据集利用CB基于内容推荐算法(多个指标基于同种相似度加权得分)实现电影Top5推荐案例的主要内容,如果未能解决你的问题,请参考以下文章
ML之KG:基于MovieLens电影评分数据集利用基于知识图谱的推荐算法(networkx+基于路径相似度的方法)实现对用户进行Top电影推荐案例
ML之shap:基于boston波士顿房价回归预测数据集利用shap值对XGBoost模型实现可解释性案例
ML之PFI(eli5):基于mpg汽车油耗数据集利用RF随机森林算法和PFI置换特征重要性算法实现模型特征可解释性排序
ML之shap:基于boston波士顿房价回归预测数据集利用Shap值对LiR线性回归模型实现可解释性案例
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用Shap值对XGBoost模型实现可解释性案例之详细攻略
ML之shap:基于FIFA 2018 Statistics(2018年俄罗斯世界杯足球赛)球队比赛之星分类预测数据集利用RF随机森林+计算SHAP值单样本力图/依赖关系贡献图可视化实现可解释性之攻略