Example #1
0
File: lfm.py Project: atm1992/LFM
def analysis_recom_result(train_data, userId, recom_result):
    """分析指定用户userId的推荐结果。train_data是用于获取该用户之前感兴趣的item"""
    item_info = read.get_item_info("../data/movies.csv")
    for user_id, movieId, label in train_data:
        if user_id == userId and label == 1:
            print(item_info[movieId])
    print("recom_result")
    for item in recom_result:
        print(item_info[item[0]])
Example #2
0
def ana_recom_result(train_data, userid, recom_list):

    item_info = read.get_item_info("../data/movies.txt")
    for data_instance in train_data:
        tmp_userid, itemid, label = data_instance
        if label == 1 and tmp_userid == userid:
            print(item_info)
    print("recom result")
    for zuhe in recom_list:
        print(item_info[zuhe[0]])
Example #3
0
def ana_recom_result(train_data, userid, recom_list):  # 分析评估推荐结果
    """
    :param train_data: train data for lfm model
    :param userid: fix userid
    :param recom_list: reeom result by lfm
    """
    item_info = read.get_item_info("../data/mymovies.txt")
    for data_instance in train_data:
        tmp_userid, itemid, label = data_instance
        if tmp_userid == userid and label == 1:  # 训练集中,该user喜欢的电影详情
            print(item_info[itemid])
        print("recom result")
        for zuhe in recom_list:  # 组合是元组
            print(item_info[zuhe[0]])  # 打印 推荐列表的电影详情
Example #4
0
def ana_recom_result(train_data, userid, recom_list):
    item_info = read.get_item_info(
        os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) +
        "\\recommender\\data\\ml-latest-small\\movies.csv")
    for data_ins in train_data:
        tmp_userid, itemid, label = data_ins
        if tmp_userid == userid and label == 1:
            print(item_info[itemid])

    print("rec")

    for rec in recom_list:
        print(item_info[rec[0]])
def ana_recom_result(train_data, userid, recom_list):
    """
    :param train_data: train data for lfm model
    :param userid: fix userid
    :param recom_list: recom result by lfm
    """
    item_info = read.get_item_info("../data/movies.txt")
    for data_instance in train_data:
        tmp_userid, itemid, label = data_instance
        if tmp_userid == userid and label == 1:
            print(item_info[itemid])
    print("recom result")
    for zuhe in recom_list:
        print(item_info[zuhe[0]])
def ana_recom_result(train_data, userid, recom_list):
    """
    debug recom result for userid 此函数用来评价推荐结果的好坏
    :param train_data: 训练数据,我们想展示一下之前用户对哪些Item感兴趣
    :param userid: 分析哪个用户的推荐结果
    :param recom_list: 模型给出的推荐结果
    """
    item_info = read.get_item_info("../data/movies.txt")
    for data_instance in train_data:
        tmp_userid, itemid, label = data_instance
        if tmp_userid == userid and label == 1:
            print(item_info[itemid])
    print("recom_result")
    for zuhe in recom_list:
        print(item_info[zuhe[0]])
Example #7
0
def ana_recom_result(train_data, userid, recom_list):
    """
    debug recom result for userid
    Args:
        train_data: train data for lfm model
        userid:fix userid
        recom_list: recom result by lfm
    """
    item_info = read.get_item_info("../data/movies.txt")
    for data_instance in train_data:
        tmp_userid, itemid, label = data_instance
        if tmp_userid == userid and label == 1:
            print item_info[itemid]
    print "recom result"
    for zuhe in recom_list:
        print item_info[zuhe[0]]
def ana_recom_result(train_data,userid,recom_list):
    '''
    对算法推荐给用户的item进行分析
    :param train_data:
    :param userid:
    :param recom_list:
    :return:
    '''
    item_info=read.get_item_info('../data/movies.txt')
    for data_distance in train_data:
        tmp_userid,itemid,label=data_distance
        if tmp_userid==userid and label==1:
            print('user like:',item_info[itemid])
    print('recom result')
    for combination in recom_list:
        print(item_info[combination[0]])
Example #9
0
def get_one_user_recom():
    """
    give fixed_user recom result
    """
    user = "******"
    alpha = 0.8
    graph = read.get_graph_from_data("../data/ratings.dat")
    iter_num = 100
    recom_result = personal_rank(graph, user, alpha, iter_num, 100)
    item_info = read.get_item_info("../data/movies.dat")
    for itemid in graph[user]:
        pure_itemid = itemid.split("_")[1]
        print(item_info[pure_itemid])
    print("----------")
    for itemid in recom_result:
        pure_itemid = itemid.split("_")[1]
        print(item_info[pure_itemid], recom_result[itemid])
def ana_recom_result(train_data, userid, recom_list):
	"""
	debug recom result for userid
	Args:
		train_data
		userid
		recom_list
	Return:
		
	"""
	item_info = get_item_info('../data/ml-latest-small/movies.csv')
	for data_instance in train_data:
		temp_userid,itemid,label = data_instance
		if temp_userid == userid and label == 1:
			print(item_info[itemid])
	print('recom result:')
	for value in recom_list:
		print(item_info[value[0]])
def ana_recom_result(train_data, userid, recom_list):
    """
    debug recom result for userid
    :param train_data: train data for userid
    :param userid: fix userid
    :param recom_list: recom result by lfm
    :return: no return
    """
    # item_info = read.get_item_info("../data/ml-1m/movies.txt")
    item_info = read.get_item_info("../data/movies.txt")
    print("该用户曾给过好评的电影如下:")
    for data_instance in train_data:
        tmp_userid, itemid, label = data_instance
        if tmp_userid == userid and label == 1:
            print(item_info[itemid])
    print("前n个推荐电影为:")
    cnt = 1
    for zuhe in recom_list:
        print(cnt, item_info[zuhe[0]])
        cnt += 1
def get_one_user_recom():
    """
    give one fix_user recom result
    :return:
    """
    user = "******"
    alpha = 0.6
    graph = read.get_graph_from_data("../data/rating.txt")
    iter_num = 100
    recom_result = personal_rank(graph, user, alpha, iter_num)
    item_info = read.get_item_info("../data/movies.txt")
    for itemid in graph[user]:
        pure_itemid = itemid.split("_")[1]
        print(item_info[pure_itemid])
    print("result---")
    for itemid in recom_result:
        pure_itemid = itemid.split("_")[1]
        print(item_info[pure_itemid])
        print(recom_result[itemid])
    return recom_result
                              reverse=True)[:recom_num]:
        point, score = combination[0], combination[1]
        recom_dict[point] = score
    return recom_dict


def get_one_user_by_matrix():
    user = '******'
    alpha = 0.8
    graph = read.get_graph_from_data('../data/ratings.txt')
    recom_result = personal_rank_matrix(graph, user, alpha, 100)
    return recom_result


if __name__ == '__main__':
    item_info = read.get_item_info('../data/movies.txt')
    recom_result_base = get_one_user_recom()
    recom_result_matrix = get_one_user_by_matrix()
    #测试部分1:观察推荐内容
    '''
    for itemid in recom_result_base:
        pure_itemid=itemid.split('_')[1]
        print(item_info[pure_itemid])
        print(recom_result_base[itemid])
    print('----------------')
    
    for itemid in recom_result_matrix:
        pure_itemid=itemid.split('_')[1]
        print(item_info[pure_itemid])
        print(recom_result_matrix[itemid])
    '''