Пример #1
0
def load_data():
    URM_text = np.loadtxt('../data/train.csv', delimiter=',', dtype=int, skiprows=1)
    user_list, item_list = zip(*URM_text)
    rating_list = np.ones(len(user_list))
    URM = sps.csr_matrix((rating_list, (user_list, item_list)))
    urm_train, urm_test = train_test_holdout(URM)
    icm = load_icm()
    return { "URM_complete" : URM, "URM_test" : urm_test, "URM_train" : urm_train, "ICM" : icm}
Пример #2
0
def before():
    model = LightFM(loss='warp')
    train, test = train_test_holdout(load_urm())
    model.fit(train, epochs=3, num_threads=2)

    pid_array = np.arange(test.shape[1], dtype=np.int32)
    a = model.predict(7, pid_array)
    print(a)
    test_auc = auc_score(model, test, train_interactions=train, num_threads=2).mean()
    print(test_auc)
Пример #3
0
def load_data():
    URM_text = np.loadtxt('../data/train.csv', delimiter=',', dtype=int, skiprows=1)
    user_list, item_list = zip(*URM_text)
    rating_list = np.ones(len(user_list))
    URM = sps.csr_matrix((rating_list, (user_list, item_list)))
    urm_train, urm_test = train_test_holdout(urm_all=URM)
    topPop = create_top_pop_list()
    urm_train.tocoo()
    j = 0
    for i in topPop:
        # factor = (len(topPop)-j)**POPULARITY_SCALING_EXP
        factor = (j)**POPULARITY_SCALING_EXP
        urm_train[:,i].multiply(1/(1+factor))
        j += 1
    urm_train.tocsr()
    icm = load_icm()
    return { "URM_complete" : URM, "URM_test" : urm_test, "URM_train" : urm_train, "ICM" : icm}
Пример #4
0

def before():
    model = LightFM(loss='warp')
    train, test = train_test_holdout(load_urm())
    model.fit(train, epochs=3, num_threads=2)

    pid_array = np.arange(test.shape[1], dtype=np.int32)
    a = model.predict(7, pid_array)
    print(a)
    test_auc = auc_score(model, test, train_interactions=train, num_threads=2).mean()
    print(test_auc)


if __name__ == '__main__':
    train, test = train_test_holdout(load_urm())
    recsys = LightFM_Recommender(train, load_icm(), 200)
    target = pd.read_csv('./data/target_playlists.csv', index_col=False)

    recsys.fit(epochs=100)

    recommended = recsys.recommendALL(target.values)

    playlists = recommended[:, 0]
    recommended = np.delete(recommended, 0, 1)
    i = 0
    res_fin = []
    for j in recommended:
        res = ''
        for k in range(0, len(j)):
            res = res + '{0} '.format(j[k])