RuntimeWarning:使用惊喜库时在sqrt中遇到无效值

时间:2018-10-15 06:30:04

标签: python-2.7

我正在使用以下代码:

from surprise import Dataset, evaluate
from surprise import KNNBasic
from collections import defaultdict
from surprise import Reader
import os
import time
start=time.time()
print start
file_path = os.path.expanduser('jester_new.txt')
reader = Reader(line_format='user item rating ', sep=',',rating_scale=(1,20))
data=Dataset.load_from_file(file_path,reader)
trainingset=data.build_full_trainset()
sim_options={'name':'pearson','min_support':5,'user_based':True}
algo = KNNBasic(k=25,min_k=5,sim_options=sim_options,verbose=True)
algo.fit(trainingset)
testset=trainingset.build_anti_testset()
predictions=algo.test(testset)

def get_top15_recommendations(predictions, topN=15):
    top_recs = defaultdict(list)
    for uid, iid, true_r, est, _ in predictions:
        top_recs[uid].append((iid, est))
    #print top_recs
    for uid, user_ratings in top_recs.items():
        user_ratings.sort(key=lambda x: x[1], reverse=True)
        top_recs[uid] = user_ratings[:topN]
    #print top_recs
    return top_recs
print "processing"
top15_recommendations = get_top15_recommendations(predictions)
f=open("thresholds_jester.txt",'w')
#f=open("result.txt",'a')
for uid, user_ratings in top15_recommendations.items():
    f.write(str(uid)),f.write(" "),f.write(str(user_ratings[-1])),f.write("\n") 

正在产生此错误:

  

/lib/python2.7/site-packages/surprise/prediction_algorithms/algo_base.py:294:   RuntimeWarning:在sqrt中遇到无效值sim =   construction_func [name](* args)。

有帮助吗?? 数据集位于:https://github.com/ngovind93/Recommender

0 个答案:

没有答案