zl程序教程

您现在的位置是:首页 >  其他

当前栏目

ML之CB:基于自定义电影数据集利用CB基于内容推荐算法(多个指标基于同种相似度加权得分)实现电影Top5推荐案例

案例算法数据 实现 基于 利用 自定义 内容
2023-09-14 09:04:44 时间
ML之CB:基于自定义电影数据集利用CB基于内容推荐算法(多个指标基于同种相似度加权得分)实现电影Top5推荐案例

目录

基于自定义电影数据集利用CB基于内容推荐算法(多个指标基于同种相似度加权得分)实现电影Top5推荐案例

# 1、定义数据集

# 2、数据集预处理

# 定义测试集

# 3、模型训练与推理

# 3.1、以当前为对象,逐个遍历与其计算相似度,找出Top5推荐

# 3.2、基于测试集,输出Top 5推荐


相关文章
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