def main(alpha, beta, URM_train, URM_test): ICM = load_icm() cf = GeneralEnsemble(URM_train, ICM, 50, epsilon=beta) cf.fit(alpha) target = pd.read_csv('../../data/target_playlists.csv', index_col=False) recommended = cf.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]) res_fin.append(res) i = i + 1 d = {'playlist_id': playlists, 'track_ids': res_fin} df = pd.DataFrame(data=d, index=None) df.to_csv("./results/resultsEnsembleAll.csv", index=None) return evaluate_csv(URM_test, "./results/resultsEnsembleAll.csv")
def write_results(id, urm_test, dict, data_frame, component_attributes, encoder=None): if encoder is None: encoder = json.JSONEncoder() filename = "../results/P3_ALPHA/result_{0}.csv".format(id) data_frame.to_csv(filename, index=None) eval = evaluate_csv(urm_test, filename) eval_json = encoder.encode(eval) param_json = encoder.encode(dict) param_file = open('../results/P3_ALPHA/params_{0}.json'.format(id), mode='w') param_file.write(param_json) param_file.close() param_attributes_json = encoder.encode(component_attributes) param_attributes_file = open( '../results/P3_ALPHA/param_attributes_{0}.json'.format(id), mode='w') param_attributes_file.write(param_attributes_json) param_attributes_file.close() eval_file = open('../results/P3_ALPHA/eval_{0}.json'.format(id), mode='w') eval_file.write(eval_json) eval_file.close() return eval
def main( write=True): 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 = load_random_urms() icm = load_icm() general = GeneralEnsemble(URM, urm_test, icm, recommendation_mode='linComb') # alpha=alpha, # beta=beta, # gamma=gamma, # epsilon=epsilon, general.fit(0.001) target = pd.read_csv('./data/target_playlists.csv', index_col=False) #evaluator_MF = SequentialEvaluator(URM_test_list=urm_test, cutoff_list=[10]) #print(evaluator_MF.evaluateRecommender(general)) if write is True: recommended = general.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]) res_fin.append(res) i = i + 1 d = {'playlist_id': playlists, 'track_ids': res_fin} df = pd.DataFrame(data=d, index=None) df.to_csv("./results/TESTING_GENERAL_ENSEMBLE17_nocf.csv", index=None) del general return evaluate_csv(urm_test, "./results/TESTING_GENERAL_ENSEMBLE17_nocf.csv")
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]) res_fin.append(res) i = i + 1 d = {'playlist_id': playlists, 'track_ids': res_fin} df = pd.DataFrame(data=d, index=None) df.to_csv("./results/lightfm_test.csv", index=None) evaluate_csv(test, "./results/lightfm_test.csv")