def run():
    assert os.path.exists('data/ratings.csv'), \
        'File not exists in path, run preprocess.py before this.'
    print('Start..')
    start = time.time()
    if not os.path.exists('data/lfm_items.dict'):
        Corpus.pre_process()
    if not os.path.exists('data/lfm.model'):
        LFM().train()
    movies = LFM().predict(user_id=1)
    for movie in movies:
        print(movie)
    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:%s' % input_user_id)

    start = time.time()
    if not os.path.exists('data/lfm_items.dict'):
        Corpus.pre_process()
    if not os.path.exists('data/lfm.model'):
        LFM().train()
    movies = LFM().predict(user_id=input_user_id, top_n=input_top_n)
    for movie in movies:
        print(movie)
    print('用时: %f' % (time.time() - start))
def run():
    assert os.path.exists('data/user/user_follows.csv'), \
        'File not exists in path, run preprocess.py before this.'
    print('Start..')
    start = time.time()
    if not os.path.exists('data/lfm_model/lfm_items.dict'):
        Corpus.pre_process()
    if not os.path.exists('data/lfm_model/lfm.model'):
        LFM().train()
    uids = [2005098, 6083125955935600644, 6099765861231362052]
    lfm = LFM()
    for uid in uids:
        movies = lfm.predict(user_id=uid)
        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()
    if not os.path.exists('data/lfm_items.dict'):
        print('Start to Generate lfm_items.dict.')
        Corpus.pre_process()
        print('Generate lfm_items.dict ok.')
    if not os.path.exists('data/lfm.model'):
        print('Start to Generate lfm.model.')
        LFM().train()
        print('Generate lfm.model ok.')
    movies = LFM().predict(user_id=1)
    for movie in movies:
        print(movie)
    print('Cost time: %f' % (time.time() - start))
示例#5
0
def run(user_id):
    '''
    调试lfm模型
    :param user_id:
    :return:
    '''
    assert os.path.exists('data/ratings.csv'), \
        'File not exists in path, run preprocess.py before this.'
    print('Start..')
    start = time.time()
    if not os.path.exists('data/lfm_items.dict'):
        Corpus.pre_process()
    if not os.path.exists('data/lfm.model'):
        LFM().train()
    movies = LFM().predict(user_id)
    movies_list = list(map(lambda x:x[0], movies))
    print(movies_list)
    print('End.')
    print('Cost Time:', time.time()-start)
def predict(user_id):
    cars = LFM().predict(user_id)
    return cars