推荐系统项目实战-电影推荐系统

推荐系统项目实战

推荐系统项目实战-电影推荐系统_第1张图片

强烈推荐按这本书哦,资料很全,也很有逻辑
新的一年,学习新的知识,这里学习了这本书,计划两周学完
推荐系统项目实战-电影推荐系统_第2张图片

  1. 数据集 链接:https://pan.baidu.com/s/1MVsdKM2q6cq-mL_I5DOt7A
    提取码:0tqo

推荐系统项目实战-电影推荐系统_第3张图片

  1. 代码
# -*- coding:utf-8 -*-

"""
    Author: Thinkgamer
    Desc:
        代码2-1  实例1:搭建你的第一个推荐系统-电影推荐系统
        从中随机选择1000个与用户进行计算
"""
import os
import json
import random
import math

class FirstRec:
    """
        初始化函数
            filePath: 原始文件路径
            seed:产生随机数的种子
            k:选取的近邻用户个数
            nitems:为每个用户推荐的电影数
    """
    def __init__(self,file_path,seed,k,n_items):
        self.file_path = file_path
        self.users_1000 = self.__select_1000_users()
        self.seed = seed
        self.k = k
        self.n_items = n_items
        self.train,self.test = self._load_and_split_data()

    # 获取所有用户并随机选取1000个
    def __select_1000_users(self):
        print("随机选取1000个用户!")
        if os.path.exists("data/train.json") and os.path.exists("data/test.json"):
            return list()
        else:
            users = set()
            # 获取所有用户
            for file in os.listdir(self.file_path):
                one_path = "{}/{}".format(self.file_path, file)
                print("{}".format(one_path))
                with open(one_path, "r") as fp:
                    for line in fp.readlines():
                        if line.strip().endswith(":"):
                            continue
                        userID, _ , _ = line.split(",")
                        users.add(userID)
            # 随机选取1000个
            users_1000 = random.sample(list(users),1000)
            print(users_1000)
            return users_1000

    # 加载数据,并拆分为训练集和测试集
    def _load_and_split_data(self):
        train = dict()
        test = dict()
        if os.path.exists("data/train.json") and os.path.exists("data/test.json"):
            print("从文件中加载训练集和测试集")
            train = json.load(open("data/train.json"))
            test = json.load(open("data/test.json"))
            print("从文件中加载数据完成")
        else:
            # 设置产生随机数的种子,保证每次实验产生的随机结果一致
            random.seed(self.seed)
            for file in os.listdir(self.file_path):
                one_path = "{}/{}".format(self.file_path, file)
                print("{}".format(one_path))
                with open(one_path,"r") as fp:
                    movieID = fp.readline().split(":")[0]
                    for line in fp.readlines():
                        if line.endswith(":"):
                            continue
                        userID, rate, _ = line.split(",")
                        # 判断用户是否在所选择的1000个用户中
                        if userID in self.users_1000:
                            if random.randint(1,50) == 1:
                                test.setdefault(userID, {
     })[movieID] = int(rate)
                            else:
                                train.setdefault(userID, {
     })[movieID] = int(rate)
            print("加载数据到 data/train.json 和 data/test.json")
            json.dump(train,open("data/train.json","w"))
            json.dump(test,open("data/test.json","w"))
            print("加载数据完成")
        return train,test

    """
        计算皮尔逊相关系数
            rating1:用户1的评分记录,形式如{"movieid1":rate1,"movieid2":rate2,...}
            rating2:用户1的评分记录,形式如{"movieid1":rate1,"movieid2":rate2,...}
    """
    def pearson(self,rating1,rating2):
        sum_xy = 0
        sum_x = 0
        sum_y = 0
        sum_x2 = 0
        sum_y2 = 0
        num = 0
        for key in rating1.keys():
            if key in rating2.keys():
                num += 1
                x = rating1[key]
                y = rating2[key]
                sum_xy += x * y
                sum_x += x
                sum_y += y
                sum_x2 += math.pow(x,2)
                sum_y2 += math.pow(y,2)
        if num == 0:
            return  0
        # 皮尔逊相关系数分母
        denominator = math.sqrt( sum_x2 - math.pow(sum_x,2) / num) * math.sqrt( sum_y2 - math.pow(sum_y,2) / num )
        if denominator == 0:
            return  0
        else:
            return ( sum_xy - ( sum_x * sum_y ) / num ) / denominator

    """
        用户userID进行电影推荐
            userID:用户ID
    """
    def recommend(self,userID):
        neighborUser = dict()
        for user in self.train.keys():
            if userID != user:
                distance = self.pearson(self.train[userID],self.train[user])
                neighborUser[user]=distance
        # 字典排序
        newNU = sorted(neighborUser.items(),key = lambda k:k[1] ,reverse=True)

        movies = dict()
        for (sim_user,sim) in newNU[:self.k]:
            for movieID in self.train[sim_user].keys():
                movies.setdefault(movieID,0)
                movies[movieID] += sim * self.train[sim_user][movieID]
        newMovies = sorted(movies.items(), key = lambda  k:k[1], reverse=True)
        return newMovies

    """
        推荐系统效果评估函数
            num: 随机抽取 num 个用户计算准确率
    """
    def evaluate(self,num=30):
        print("开始计算准确率")
        precisions = list()
        random.seed(10)
        for userID in random.sample(self.test.keys(),num):
            hit = 0
            result = self.recommend(userID)[:self.n_items]
            for (item,rate) in result:
                if item in self.test[userID]:
                    hit += 1
            precisions.append(hit/self.n_items)
        return  sum(precisions) / precisions.__len__()

# main函数,程序的入口
if __name__ == "__main__":
    file_path = "data/netflix/training_set"
    seed = 30
    k = 15
    n_items =20
    f_rec = FirstRec(file_path,seed,k,n_items)
    # 计算用户 195100 和 1547579的皮尔逊相关系数
    r = f_rec.pearson(f_rec.train["195100"],f_rec.train["1547579"])
    print("195100 和 1547579的皮尔逊相关系数为:{}".format(r))
    # 为用户195100进行电影推荐
    result = f_rec.recommend("195100")
    print("为用户ID为:195100的用户推荐的电影为:{}".format(result))
    print("算法的推荐准确率为: {}".format(f_rec.evaluate()))
  1. 结果
随机选取1000个用户!
从文件中加载训练集和测试集
从文件中加载数据完成
1951001547579的皮尔逊相关系数为:0.1194695382178992
为用户ID为:195100的用户推荐的电影为:[('3938', 22.0), ('14538', 19.000000000000004), ('14103', 19.0), ('15205', 18.000000000000004), ('17355', 18.0), ('1905', 18.0), ('12317', 16.000000000000004), ('13255', 16.000000000000004), ('5317', 14.000000000000004), ('11283', 14.0), ('14240', 14.0), ('6974', 14.0), ('16265', 14.0), ('6206', 14.0), ('11521', 14.0), ('1145', 13.000000000000005), ('17169', 13.000000000000005), ('9340', 13.000000000000004), ('4306', 13.0), ('11132', 13.0), ('17324', 13.0), ('14313', 12.000000000000002), ('16879', 12.0), ('3917', 12.0), ('7624', 12.0), ('8644', 12.0), ('13593', 12.0), ('6844', 11.000000000000002), ('758', 11.0), ('313', 11.0), ('8393', 11.0), ('11089', 11.0), ('13050', 11.0), ('14454', 11.0), ('16882', 11.0), ('12911', 10.000000000000005), ('15582', 10.000000000000005), ('30', 10.0), ('14621', 10.0), ('16377', 10.0), ('5582', 10.0), ('9628', 10.0), ('3274', 10.0), ('5496', 10.0), ('16082', 10.0), ('10550', 9.999999999999998), ('1220', 9.999999999999998), ('1804', 9.999999999999998), ('12721', 9.999999999999998), ('12672', 9.000000000000005), ('6386', 9.0), ('12918', 9.0), ('13052', 9.0), ('5085', 9.0), ('6030', 9.0), ('7928', 9.0), ('9189', 9.0), ('12293', 9.0), ('14410', 9.0), ('14550', 9.0), ('14574', 9.0), ('223', 9.0), ('12161', 9.0), ('197', 9.0), ('1191', 9.0), ('3427', 9.0), ('13087', 9.0), ('17303', 9.0), ('1110', 9.0), ('15646', 9.0), ('17330', 9.0), ('2452', 9.0), ('3624', 9.0), ('13673', 9.0), ('996', 8.999999999999998), ('5577', 8.999999999999998), ('11022', 8.999999999999998), ('13258', 8.999999999999998), ('2152', 8.000000000000004), ('4972', 8.000000000000004), ('12470', 8.000000000000004), ('6972', 8.0), ('16668', 8.0), ('3756', 8.0), ('4123', 8.0), ('5087', 8.0), ('7406', 8.0), ('10583', 8.0), ('11607', 8.0), ('16452', 8.0), ('3894', 8.0), ('16242', 8.0), ('1406', 7.999999999999999), ('1962', 7.999999999999999), ('2342', 7.999999999999999), ('2862', 7.999999999999999), ('6134', 7.999999999999999), ('6615', 7.999999999999999), ('15563', 7.999999999999999), ('3638', 7.999999999999999), ('4384', 7.999999999999999), ('9818', 7.999999999999999), ('5320', 7.999999999999999), ('6475', 7.999999999999999), ('6859', 7.999999999999999), ('15063', 7.999999999999999), ('15099', 7.999999999999999), ('15409', 7.999999999999999), ('10729', 7.999999999999998), ('13380', 7.999999999999998), ('11149', 7.000000000000005), ('6287', 7.0000000000000036), ('14712', 7.000000000000001), ('3282', 7.0), ('11677', 7.0), ('15107', 7.0), ('15788', 7.0), ('4262', 7.0), ('12056', 7.0), ('14187', 7.0), ('10421', 7.0), ('13728', 6.999999999999999), ('17149', 6.999999999999999), ('9054', 6.999999999999999), ('11314', 6.999999999999999), ('11182', 6.999999999999998), ('5814', 6.999999999999998), ('2112', 6.999999999999998), ('4996', 6.0), ('7987', 6.0), ('12155', 6.0), ('6037', 6.0), ('3860', 5.999999999999999), ('10429', 5.999999999999999), ('571', 5.999999999999998), ('6648', 5.999999999999998), ('7060', 5.0), ('14533', 5.0), ('1102', 5.0), ('3962', 5.0), ('4356', 5.0), ('5531', 5.0), ('11040', 5.0), ('12870', 5.0), ('15101', 5.0), ('15296', 5.0), ('15844', 5.0), ('17157', 5.0), ('166', 5.0), ('199', 5.0), ('788', 5.0), ('1661', 5.0), ('17014', 5.0), ('17479', 5.0), ('762', 5.0), ('2989', 5.0), ('5285', 5.0), ('7429', 5.0), ('11370', 5.0), ('12433', 5.0), ('14302', 5.0), ('15124', 5.0), ('16147', 5.0), ('819', 5.0), ('937', 5.0), ('1364', 5.0), ('1542', 5.0), ('1590', 5.0), ('1914', 5.0), ('2023', 5.0), ('2140', 5.0), ('2162', 5.0), ('2254', 5.0), ('2326', 5.0), ('2594', 5.0), ('2612', 5.0), ('2953', 5.0), ('3807', 5.0), ('3825', 5.0), ('4829', 5.0), ('5875', 5.0), ('6119', 5.0), ('6194', 5.0), ('6448', 5.0), ('6482', 5.0), ('7186', 5.0), ('7617', 5.0), ('8192', 5.0), ('8339', 5.0), ('8595', 5.0), ('9036', 5.0), ('9188', 5.0), ('9326', 5.0), ('9471', 5.0), ('9756', 5.0), ('10123', 5.0), ('10359', 5.0), ('11433', 5.0), ('11805', 5.0), ('12766', 5.0), ('13090', 5.0), ('13217', 5.0), ('13462', 5.0), ('13810', 5.0), ('13851', 5.0), ('14167', 5.0), ('14755', 5.0), ('14963', 5.0), ('15170', 5.0), ('15755', 5.0), ('15798', 5.0), ('16139', 5.0), ('17053', 5.0), ('17250', 5.0), ('17441', 5.0), ('17707', 5.0), ('16128', 5.0), ('14376', 5.0), ('457', 5.0), ('1803', 5.0), ('3612', 5.0), ('4008', 5.0), ('4432', 5.0), ('6027', 5.0), ('6042', 5.0), ('8118', 5.0), ('8160', 5.0), ('11337', 5.0), ('12338', 5.0), ('12785', 5.0), ('13359', 5.0), ('17004', 5.0), ('17293', 5.0), ('17405', 5.0), ('17627', 5.0), ('290', 4.999999999999999), ('2913', 4.999999999999999), ('3138', 4.999999999999999), ('5695', 4.999999999999999), ('5947', 4.999999999999999), ('6366', 4.999999999999999), ('6450', 4.999999999999999), ('7193', 4.999999999999999), ('7713', 4.999999999999999), ('7786', 4.999999999999999), ('8966', 4.999999999999999), ('8993', 4.999999999999999), ('10189', 4.999999999999999), ('10986', 4.999999999999999), ('12367', 4.999999999999999), ('14264', 4.999999999999999), ('15209', 4.999999999999999), ('17339', 4.999999999999999), ('17449', 4.999999999999999), ('8954', 4.999999999999999), ('175', 4.999999999999999), ('210', 4.999999999999999), ('473', 4.999999999999999), ('561', 4.999999999999999), ('872', 4.999999999999999), ('1741', 4.999999999999999), ('1848', 4.999999999999999), ('2348', 4.999999999999999), ('2480', 4.999999999999999), ('3139', 4.999999999999999), ('3374', 4.999999999999999), ('4477', 4.999999999999999), ('5283', 4.999999999999999), ('5561', 4.999999999999999), ('5653', 4.999999999999999), ('5862', 4.999999999999999), ('6117', 4.999999999999999), ('6221', 4.999999999999999), ('6445', 4.999999999999999), ('6545', 4.999999999999999), ('6807', 4.999999999999999), ('6808', 4.999999999999999), ('7170', 4.999999999999999), ('7433', 4.999999999999999), ('7516', 4.999999999999999), ('7523', 4.999999999999999), ('7586', 4.999999999999999), ('7735', 4.999999999999999), ('8806', 4.999999999999999), ('8829', 4.999999999999999), ('8832', 4.999999999999999), ('8893', 4.999999999999999), ('8951', 4.999999999999999), ('9076', 4.999999999999999), ('9330', 4.999999999999999), ('9426', 4.999999999999999), ('10276', 4.999999999999999), ('10661', 4.999999999999999), ('11573', 4.999999999999999), ('11899', 4.999999999999999), ('12417', 4.999999999999999), ('12942', 4.999999999999999), ('14061', 4.999999999999999), ('14210', 4.999999999999999), ('14525', 4.999999999999999), ('15333', 4.999999999999999), ('15657', 4.999999999999999), ('16175', 4.999999999999999), ('16306', 4.999999999999999), ('16431', 4.999999999999999), ('16482', 4.999999999999999), ('16721', 4.999999999999999), ('17412', 4.999999999999999), ('17472', 4.999999999999999), ('270', 4.999999999999999), ('798', 4.999999999999999), ('985', 4.999999999999999), ('1256', 4.999999999999999), ('2938', 4.999999999999999), ('3078', 4.999999999999999), ('4345', 4.999999999999999), ('4577', 4.999999999999999), ('4951', 4.999999999999999), ('5309', 4.999999999999999), ('5414', 4.999999999999999), ('6034', 4.999999999999999), ('7057', 4.999999999999999), ('7155', 4.999999999999999), ('7158', 4.999999999999999), ('7230', 4.999999999999999), ('8438', 4.999999999999999), ('8840', 4.999999999999999), ('10988', 4.999999999999999), ('11271', 4.999999999999999), ('12184', 4.999999999999999), ('12453', 4.999999999999999), ('12530', 4.999999999999999), ('13663', 4.999999999999999), ('14961', 4.999999999999999), ('15070', 4.999999999999999), ('15307', 4.999999999999999), ('15609', 4.999999999999999), ('15689', 4.999999999999999), ('16083', 4.999999999999999), ('17023', 4.999999999999999), ('17328', 4.999999999999999), ('15151', 4.999999999999999), ('9939', 4.000000000000004), ('3610', 4.0), ('7635', 4.0), ('17431', 4.0), ('708', 4.0), ('759', 4.0), ('886', 4.0), ('1073', 4.0), ('1174', 4.0), ('1931', 4.0), ('2743', 4.0), ('3079', 4.0), ('3605', 4.0), ('4330', 4.0), ('4640', 4.0), ('5056', 4.0), ('6274', 4.0), ('6408', 4.0), ('6630', 4.0), ('6833', 4.0), ('7364', 4.0), ('9728', 4.0), ('10808', 4.0), ('12471', 4.0), ('13622', 4.0), ('13763', 4.0), ('13883', 4.0), ('14507', 4.0), ('14827', 4.0), ('15968', 4.0), ('16286', 4.0), ('17088', 4.0), ('660', 4.0), ('1646', 4.0), ('5084', 4.0), ('6362', 4.0), ('10982', 4.0), ('13923', 4.0), ('17426', 4.0), ('642', 4.0), ('8561', 4.0), ('283', 4.0), ('607', 4.0), ('896', 4.0), ('1045', 4.0), ('1610', 4.0), ('1625', 4.0), ('1645', 4.0), ('2430', 4.0), ('2541', 4.0), ('3021', 4.0), ('3127', 4.0), ('3242', 4.0), ('3542', 4.0), ('3737', 4.0), ('3905', 4.0), ('3999', 4.0), ('4263', 4.0), ('4533', 4.0), ('5421', 4.0), ('5503', 4.0), ('5897', 4.0), ('6281', 4.0), ('6555', 4.0), ('6692', 4.0), ('7019', 4.0), ('7076', 4.0), ('7077', 4.0), ('7633', 4.0), ('8253', 4.0), ('8278', 4.0), ('9205', 4.0), ('9617', 4.0), ('10809', 4.0), ('10921', 4.0), ('11103', 4.0), ('11669', 4.0), ('12101', 4.0), ('12102', 4.0), ('12273', 4.0), ('12299', 4.0), ('13523', 4.0), ('13656', 4.0), ('13805', 4.0), ('14144', 4.0), ('14149', 4.0), ('14593', 4.0), ('14856', 4.0), ('15048', 4.0), ('15247', 4.0), ('15540', 4.0), ('16339', 4.0), ('16516', 4.0), ('16724', 4.0), ('17035', 4.0), ('17559', 4.0), ('17743', 4.0), ('257', 4.0), ('3907', 4.0), ('5293', 4.0), ('7745', 4.0), ('8764', 4.0), ('12508', 4.0), ('13651', 4.0), ('15500', 4.0), ('15700', 4.0), ('16384', 4.0), ('17321', 4.0), ('273', 4.0), ('7234', 4.0), ('8204', 4.0), ('10255', 4.0), ('12739', 4.0), ('3526', 4.0), ('4315', 4.0), ('4522', 4.0), ('5284', 4.0), ('5621', 4.0), ('6060', 4.0), ('6267', 4.0), ('6329', 4.0), ('6437', 4.0), ('6698', 4.0), ('6874', 4.0), ('6971', 4.0), ('7852', 4.0), ('9662', 4.0), ('10358', 4.0), ('10906', 4.0), ('11812', 4.0), ('11910', 4.0), ('12600', 4.0), ('12966', 4.0), ('13330', 4.0), ('14467', 4.0), ('14999', 4.0), ('16380', 4.0), ('16707', 4.0), ('16793', 4.0), ('17174', 4.0), ('564', 4.0), ('1324', 4.0), ('2649', 4.0), ('3864', 4.0), ('4109', 4.0), ('5926', 4.0), ('6552', 4.0), ('7067', 4.0), ('9458', 4.0), ('13081', 4.0), ('13582', 4.0), ('14531', 4.0), ('14571', 4.0), ('14691', 4.0), ('14897', 4.0), ('16438', 4.0), ('16469', 4.0), ('16872', 4.0), ('14644', 3.9999999999999996), ('4914', 3.9999999999999996), ('8', 3.999999999999999), ('443', 3.999999999999999), ('2580', 3.999999999999999), ('3125', 3.999999999999999), ('5345', 3.999999999999999), ('5762', 3.999999999999999), ('6131', 3.999999999999999), ('6454', 3.999999999999999), ('6518', 3.999999999999999), ('6917', 3.999999999999999), ('7517', 3.999999999999999), ('8801', 3.999999999999999), ('8976', 3.999999999999999), ('9778', 3.999999999999999), ('10433', 3.999999999999999), ('10582', 3.999999999999999), ('11227', 3.999999999999999), ('12534', 3.999999999999999), ('12838', 3.999999999999999), ('13015', 3.999999999999999), ('14233', 3.999999999999999), ('14274', 3.999999999999999), ('14549', 3.999999999999999), ('16240', 3.999999999999999), ('16495', 3.999999999999999), ('17033', 3.999999999999999), ('17184', 3.999999999999999), ('17312', 3.999999999999999), ('6829', 3.999999999999999), ('14527', 3.999999999999999), ('15483', 3.999999999999999), ('599', 3.999999999999999), ('1466', 3.999999999999999), ('2175', 3.999999999999999), ('2965', 3.999999999999999), ('3106', 3.999999999999999), ('3879', 3.999999999999999), ('4139', 3.999999999999999), ('7384', 3.999999999999999), ('7419', 3.999999999999999), ('8526', 3.999999999999999), ('10004', 3.999999999999999), ('10162', 3.999999999999999), ('10662', 3.999999999999999), ('10832', 3.999999999999999), ('10920', 3.999999999999999), ('11295', 3.999999999999999), ('11575', 3.999999999999999), ('11904', 3.999999999999999), ('12360', 3.999999999999999), ('13082', 3.999999999999999), ('13186', 3.999999999999999), ('13317', 3.999999999999999), ('13909', 3.999999999999999), ('16810', 3.999999999999999), ('1144', 3.999999999999999), ('3538', 3.999999999999999), ('4570', 3.999999999999999), ('5939', 3.999999999999999), ('7233', 3.999999999999999), ('7331', 3.999999999999999), ('14215', 3.999999999999999), ('17215', 3.999999999999999), ('17762', 3.999999999999999), ('2192', 3.999999999999999), ('3347', 3.999999999999999), ('13342', 3.999999999999999), ('5071', 3.0000000000000036), ('12694', 3.0000000000000036), ('3197', 3.0), ('4745', 3.0), ('7446', 3.0), ('8782', 3.0), ('11064', 3.0), ('11837', 3.0), ('12343', 3.0), ('15339', 3.0), ('16765', 3.0), ('720', 3.0), ('1180', 3.0), ('1673', 3.0), ('2874', 3.0), ('3730', 3.0), ('4043', 3.0), ('4488', 3.0), ('5952', 3.0), ('6347', 3.0), ('7649', 3.0), ('8784', 3.0), ('9381', 3.0), ('10042', 3.0), ('10423', 3.0), ('10818', 3.0), ('13384', 3.0), ('13413', 3.0), ('13636', 3.0), ('13827', 3.0), ('13845', 3.0), ('14367', 3.0), ('14653', 3.0), ('15902', 3.0), ('16792', 3.0), ('16891', 3.0), ('2678', 3.0), ('3434', 3.0), ('3772', 3.0), ('5819', 3.0), ('7032', 3.0), ('14977', 3.0), ('5528', 3.0), ('5760', 3.0), ('8799', 3.0), ('14278', 3.0), ('2518', 3.0), ('4092', 3.0), ('5604', 3.0), ('6311', 3.0), ('7322', 3.0), ('10789', 3.0), ('15529', 3.0), ('17129', 3.0), ('17175', 3.0), ('17381', 3.0), ('16113', 3.0), ('11681', 3.0), ('15641', 3.0), ('1138', 3.0), ('5793', 3.0), ('5828', 3.0), ('5836', 3.0), ('6860', 3.0), ('7184', 3.0), ('7281', 3.0), ('8295', 3.0), ('10860', 3.0), ('11931', 3.0), ('12322', 3.0), ('14113', 3.0), ('15764', 3.0), ('312', 2.999999999999999), ('1283', 2.999999999999999), ('2779', 2.999999999999999), ('2958', 2.999999999999999), ('3151', 2.999999999999999), ('4493', 2.999999999999999), ('4695', 2.999999999999999), ('6497', 2.999999999999999), ('7238', 2.999999999999999), ('7971', 2.999999999999999), ('9415', 2.999999999999999), ('9442', 2.999999999999999), ('10773', 2.999999999999999), ('13061', 2.999999999999999), ('13214', 2.999999999999999), ('14890', 2.999999999999999), ('14940', 2.999999999999999), ('15343', 2.999999999999999), ('17062', 2.999999999999999), ('17111', 2.999999999999999), ('9645', 2.999999999999999), ('15034', 2.999999999999999), ('963', 2.999999999999999), ('1464', 2.999999999999999), ('406', 2.999999999999999), ('442', 2.999999999999999), ('2172', 2.999999999999999), ('2942', 2.999999999999999), ('4877', 2.999999999999999), ('5154', 2.999999999999999), ('7739', 2.999999999999999), ('8535', 2.999999999999999), ('10375', 2.999999999999999), ('11047', 2.999999999999999), ('11090', 2.999999999999999), ('11696', 2.999999999999999), ('13736', 2.999999999999999), ('15471', 2.999999999999999), ('305', 2.999999999999999), ('1307', 2.999999999999999), ('10101', 2.999999999999999), ('12303', 2.999999999999999), ('28', 2.0), ('6720', 2.0), ('12774', 2.0), ('15474', 2.0), ('1700', 2.0), ('2226', 2.0), ('16095', 2.0), ('17345', 2.0), ('1068', 2.0), ('11170', 2.0), ('6255', 2.0), ('8418', 2.0), ('17031', 2.0), ('17251', 2.0), ('331', 2.0), ('2477', 2.0), ('7249', 2.0), ('10947', 2.0), ('13519', 2.0), ('16640', 2.0), ('16859', 2.0), ('468', 1.9999999999999996), ('2856', 1.9999999999999996), ('4733', 1.9999999999999996), ('6084', 1.9999999999999996), ('8824', 1.9999999999999996), ('10078', 1.9999999999999996), ('13565', 1.9999999999999996), ('13855', 1.9999999999999996), ('14440', 1.9999999999999996), ('14898', 1.9999999999999996), ('15608', 1.9999999999999996), ('16603', 1.9999999999999996), ('16730', 1.9999999999999996), ('17704', 1.9999999999999996), ('9800', 1.9999999999999996), ('658', 1.9999999999999996), ('2391', 1.9999999999999996), ('2486', 1.9999999999999996), ('5837', 1.9999999999999996), ('10775', 1.9999999999999996), ('15777', 1.9999999999999996), ('3314', 1.9999999999999996), ('4590', 1.9999999999999996), ('7521', 1.9999999999999996), ('11065', 1.9999999999999996), ('13043', 1.9999999999999996), ('14389', 1.9999999999999996), ('17387', 1.000000000000001), ('1975', 1.0), ('2361', 1.0), ('4103', 1.0), ('5725', 1.0), ('16145', 1.0), ('191', 1.0), ('6975', 1.0), ('14332', 1.0), ('3713', 1.0), ('7904', 1.0), ('5991', 1.0), ('6596', 1.0), ('1012', 0.9999999999999998), ('2939', 0.9999999999999998), ('7780', 0.9999999999999998), ('3161', 0.9999999999999998), ('13471', 0.9999999999999998), ('14154', 0.9999999999999998)]
开始计算准确率
算法的推荐准确率为: 0.005000000000000001
  1. 总结
    只是抽取的1000个训练,结果并不是很理想,全部训练集基数大,估计可行
    后期有时间放上GPU结果

你可能感兴趣的:(推荐系统实战)