コード例 #1
0
ファイル: recommender.py プロジェクト: aneeshnema/binge
 def restart():
     print("RESTART RECOMMENDATION ENGINE", file=stderr)
     Recommender.mat = generate_mat()
     Recommender.tmat = Recommender.mat.transpose()
     Recommender.model = NMSLibAlternatingLeastSquares()
     Recommender.model.fit(Recommender.mat)
     Recommender.last_restart = datetime.utcnow()
     Recommender.count = Review.query.count()
コード例 #2
0
    def fromds(cls, ds):
        DEFAULT = {
            'factors': 40,
            'regularization': 0.01,
            'iterations': 10,
        }

        coo, users, movies = ds.model_input
        attrs = {
            'ds': ds,
            'model': NMSLibAlternatingLeastSquares(**DEFAULT),
            'config': hashlib.md5(str(DEFAULT).encode()).hexdigest(),
            '_fit': False,
            'data': coo,
            'user_lookup': users,
            'movie_lookup': movies,
            'redis': Redis().redis
        }
        return cls(**attrs)
コード例 #3
0
 def _get_model(self):
     return NMSLibAlternatingLeastSquares(factors=2,
                                          regularization=0,
                                          index_params={"post": 2},
                                          random_state=23)
コード例 #4
0
 def _get_model(self):
     return NMSLibAlternatingLeastSquares(factors=2, regularization=0,
                                          index_params={'post': 2})
コード例 #5
0
        train_user_small.append(train_user[idx]); train_music_small.append(train_music[idx]); train_count_small.append(train_count[idx])
        train_user[idx] = 0; train_music[idx] = 0; train_count[idx] = 0
'''
train = coo_matrix((train_count, (train_user, train_music))).tocsr()
#train_small = coo_matrix((train_count_small, (train_user_small, train_music_small))).tocsr()
test = coo_matrix((test_count, (test_user, test_music)))

ex_train_user = sorted(set(train_user))
ex_train_music = sorted(set(train_music))
#del ex_train_user[0]; del ex_train_music[0]
#ex_train_user_small = sorted(set(train_user_small))
#ex_train_music_small = sorted(set(train_music_small))
ex_test_user = sorted(set(test_user))
ex_test_music = sorted(set(test_music))

print("Status : Train data loaded. CV ready.")

# WMF 모델 생성
#model = wmf(factors=NO_COMPONENT, regularization=REGULARIZATION)
#model.fit(train.transpose() * ALPHA)

# NMSLIB 모델 생성
model_nmslib = NMSLIB()
model_nmslib.fit(train.transpose() * ALPHA)

print(
    "Status : Model trained. (No. users = %d, No. component = %d, Regularization = %.2f, Top K = %d)"
    % (len(ex_train_user), NO_COMPONENT, REGULARIZATION, TOP_K))

ndcg_score(model_nmslib, test, ex_test_user, ex_test_music, TOP_K)
#ndcg_score(model_nmslib, test, ex_train_user_small, ex_train_music_small, TOP_K)
コード例 #6
0
 def _get_model(self):
     return NMSLibAlternatingLeastSquares(factors=2, regularization=0)