def process_svd(preload):
    if preload:
        svd = SVD(filename='./data/svd-all') # Loading already computed SVD model
    else:
        print "Reading data..."
        svdlibc = SVDLIBC('./data/behavior-ml-score.csv')
        svdlibc.to_sparse_matrix(sep=',', format={'col':0, 'row':1, 'value':2, 'ids': str})
        k=100
        print "Computing SVD..."
        svdlibc.compute(k)
        svd = svdlibc.export()
        svd.save_model('./data/svd-all', options={'k': k})
    #svd.predict('TV268', 9, 1, 3)
    return svd
示例#2
0
def setup():
    global svdlibc
    svdlibc = SVDLIBC(os.path.join(MOVIELENS_DATA_PATH, 'ratings.dat'))
示例#3
0
ITEMID = 1
USERID = 1
print svd.predict(ITEMID, USERID, MIN_RATING, MAX_RATING)
print svd.get_matrix().value(ITEMID, USERID)

#HACUIENDO RECOMENDACIONES AL USUARIO Y POR TITEM
print svd.recommend(
    USERID,
    is_row=False)  #cols are users and rows are items, thus we set is_row=False
print svd.recommend(ITEMID)
print "se deben mostrar 5 recomendaciones para el item 1"
print svd.recommend(USERID, n=5, only_unknowns=True, is_row=False)

#usando la matriz que ya esta generada
from recsys.utils.svdlibc import SVDLIBC

svdlibc = SVDLIBC('./data/ratings.dat')
svdlibc.to_sparse_matrix(sep='::',
                         format={
                             'col': 0,
                             'row': 1,
                             'value': 2,
                             'ids': int
                         })
svdlibc.compute(k=100)
svd = svdlibc.export()
print "hallando similitud con el itemd1"
print svd.similar(
    ITEMID1
)  # results might be different than example 4. as there's no min_values=10 set here
示例#4
0
import sys
import recsys.algorithm
recsys.algorithm.VERBOSE = True
from recsys.utils.svdlibc import SVDLIBC

movielens = sys.argv[1] #ratings.dat movielens file path here
svdlibc = SVDLIBC(movielens)
svdlibc.to_sparse_matrix(sep='::', format={'col':0, 'row':1, 'value':2, 'ids': int})
svdlibc.compute()
svd = svdlibc.export()
svdlibc.remove_files()
MOVIEID = 1
print svd.similar(MOVIEID)
print svd.recommend(MOVIEID)