Пример #1
0
def test_item_avg():
    iavg = pyreclab.ItemAvg(dataset='dataset/u1.base',
                            dlmchar=b'\t',
                            header=False,
                            usercol=0,
                            itemcol=1,
                            ratingcol=2)

    iavg.train()

    pred = iavg.predict('457', '443')
    assert abs(pred - expected_prediction) < prediction_epsilon

    ranking = iavg.recommend('457', 5, includeRated=False)
    assert ranking == expected_ranking

    predlist, mae, rmse = iavg.test(input_file='dataset/u1.test',
                                    dlmchar=b'\t',
                                    header=False,
                                    usercol=0,
                                    itemcol=1,
                                    ratingcol=2,
                                    output_file='predictions.csv')

    assert abs(mae - expected_mae) < mae_epsilon
    assert abs(rmse - expected_rmse) < rmse_epsilon
Пример #2
0
def main():
    iavg = pyreclab.ItemAvg(dataset='dataset/u1.base',
                            dlmchar=b'\t',
                            header=False,
                            usercol=0,
                            itemcol=1,
                            ratingcol=2)

    print('-> training model')
    start = time.clock()
    iavg.train()
    end = time.clock()
    print('training time: ' + str(end - start))

    print('-> individual test')
    pred = iavg.predict('457', '443')
    print('user 457, item 443, prediction ' + str(pred))

    ranking = iavg.recommend('457', 5, includeRated=False)
    print('recommendation for user 457: ' + str(ranking))

    print('-> prediction test')
    start = time.clock()
    predlist, mae, rmse = iavg.test(input_file='dataset/u1.test',
                                    dlmchar=b'\t',
                                    header=False,
                                    usercol=0,
                                    itemcol=1,
                                    ratingcol=2,
                                    output_file='predictions.csv')
    end = time.clock()
    print('prediction time: ' + str(end - start))

    print('MAE: ' + str(mae))
    print('RMSE: ' + str(rmse))

    print('-> recommendation test')
    start = time.clock()
    recommendList = iavg.testrec(input_file='dataset/u1.test',
                                 dlmchar=b'\t',
                                 header=False,
                                 usercol=0,
                                 itemcol=1,
                                 ratingcol=2,
                                 topn=10,
                                 output_file='ranking.json',
                                 includeRated=False)
    end = time.clock()
    print('recommendation time: ' + str(end - start))
Пример #3
0
import time
import pyreclab

if __name__ == '__main__':

    iavg = pyreclab.ItemAvg(dataset='dataset/u1.base',
                            dlmchar=b'\t',
                            header=False,
                            usercol=0,
                            itemcol=1,
                            ratingcol=2)

    print('-> training model')
    start = time.clock()
    iavg.train()
    end = time.clock()
    print('training time: ' + str(end - start))

    print('-> individual test')
    pred = iavg.predict('457', '443')
    print('user 457, item 443, prediction ' + str(pred))

    ranking = iavg.recommend('457', 5, includeRated=False)
    print('recommendation for user 457: ' + str(ranking))

    print('-> prediction test')
    start = time.clock()
    predlist, mae, rmse = iavg.test(input_file='dataset/u1.test',
                                    dlmchar=b'\t',
                                    header=False,
                                    usercol=0,