def run(): print('Start..') start = time.time() movies = UserCf().calculate() for movie in movies: print(movie) print('Cost time: %f' % (time.time() - start))
def run(): assert os.path.exists('data/ratings.csv'), FILE_NOT_EXIT print('Start..') start = time.time() movies = UserCf().calculate() for movie in movies: print(movie) print('Cost time: %f' % (time.time() - start))
def run(): assert os.path.exists('data/ratings.csv'), \ 'File not exists in path, run preprocess.py before this.' print('Start..') start = time.time() movies = UserCf().calculate() for movie in movies: print(movie) print('Cost time: %f' % (time.time() - start))
def run(user_id, topItems): assert os.path.exists('data/ratings.csv'), \ 'File not exists in path, run preprocess.py before this.' print('Start..') start = time.time() movies = UserCf().calculate(target_user_id=user_id, top_n=topItems) for movie in movies: print(movie) return movies print('Cost time: %f' % (time.time() - start))
def run(input_user_id=1, input_top_n=10): assert os.path.exists('data/ratings.csv'), \ 'File not exists in path, run preprocess.py before this.' print('Start..') print("用户ID:", input_user_id) start = time.time() movies = UserCf().calculate(target_user_id=input_user_id, top_n=input_top_n) for movie in movies: print(movie) print('用时: %f' % (time.time() - start))
count = {} for i in range(len(pd)): if pd.iloc[i, 2] not in count: count[pd.iloc[i, 2]] = 1 else: count[pd.iloc[i, 2]] += 1 max = 0 max_id = 0 for i in count: if count[i] > max: max_id = i max = count[i] print(max, max_id) prdict_csv = open('./data/predict.csv', 'w', encoding='UTF-8') prdict_csv.write("user_id,product_id\n") if arg == "cf": for id in tqdm(set(user_id)): product = UserCf().calculate(target_user_id=id) if product[1] == 0: recommond = max_id else: recommond = product[0] prdict_csv.write(str(id) + ',' + str(recommond) + '\n') if arg == 'normal': for id in tqdm(set(user_id)): recommond = Normal().predict(user_id=id) print(recommond) prdict_csv.write(str(id) + ',' + str(recommond) + '\n') prdict_csv.close()