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
def readDat(): global svd global svdlibc global tree global similar_title svdlibc = SVDLIBC(ratings) svdlibc.to_sparse_matrix(sep='::', \ format={'col':0, 'row':1, 'value':2, 'ids': int}) svdlibc.compute(k=100) svd = svdlibc.export() tree.append(svd.similar(ITEMID1)) for name in tree: for n in name[1:]: similar_title.append(n[0]) if svd.similar(n[0]) not in tree: tree.append(svd.similar(n[0])) movie_similarity[name[0][0]] = similar_title similar_title = []
# perform singular value decomposition on the ratings table import recsys.algorithm from recsys.utils.svdlibc import SVDLIBC recsys.algorithm.VERBOSE = True svdlibc = SVDLIBC('ml-10M100K/ratings.dat') svdlibc.to_sparse_matrix(sep='::', format={'col':0, 'row':1, 'value':2, 'ids': int}) svdlibc.compute(k=100) svd = svdlibc.export() svd.save_model('svd-10M-k100')
def setup(): global svdlibc svdlibc = SVDLIBC(os.path.join(MOVIELENS_DATA_PATH, 'ratings.dat'))
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
def __init__(self): svdlibc = SVDLIBC('../../datasets/ratings.dat') svdlibc.to_sparse_matrix(sep='::', format={'col':0, 'row':1, 'value':2, 'ids': int}) svdlibc.compute(k=100) svd = svdlibc.export() self.svd = svd
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)