def evaluateMap(): from src.utils.evaluator import Evaluator dataset = Dataset(load_tags=True, filter_tag=False, weight_tag=False) dataset.set_track_attr_weights_2(2.0, 2.0, 0.0, 0.0, 0.0, 2.0, 2.0, 0.0, 0.0) # seed = 0xcafebabe # print("Evaluating with initial seed: {}".format(seed)) ev = Evaluator(seed=False) ev.cross_validation(5, dataset.train_final.copy()) cbf = ContentBasedFiltering() for i in range(0, 5): urm, tg_tracks, tg_playlist = ev.get_fold(dataset) cbf.fit(urm, list(tg_playlist), list(tg_tracks), dataset) recs = cbf.predict() ev.evaluate_fold(recs) map_at_five = ev.get_mean_map() print("MAP@5 ", map_at_five)
def evaluateMap(): from src.utils.evaluator import Evaluator dataset = Dataset(load_tags=True, filter_tag=False, weight_tag=False) dataset.set_track_attr_weights_2(1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0) dataset.set_playlist_attr_weights(1, 1, 1, 0, 0) ev = Evaluator() ev.cross_validation(5, dataset.train_final.copy()) cbf = ContentBasedFiltering(alfa=0.999) for i in range(0, 5): urm, tg_tracks, tg_playlist = ev.get_fold(dataset) cbf.fit(urm, list(tg_playlist), list(tg_tracks), dataset) recs = cbf.predict() ev.evaluate_fold(recs) map_at_five = ev.get_mean_map() print("MAP@5 ", map_at_five)
return self.R_hat def get_model(self): """ Returns the complete R_hat """ return self.R_hat.copy() if __name__ == '__main__': ds = Dataset(load_tags=True, filter_tag=True) ds.set_track_attr_weights_2(1, 1, 1, 1, 1, num_rating_weight=1, inferred_album=1, inferred_duration=1, inferred_playcount=1) ev = Evaluator() ev.cross_validation(5, ds.train_final.copy()) for i in range(0, 5): fm = FM() urm, tg_tracks, tg_playlist = ev.get_fold(ds) fm.fit(urm, list(tg_playlist), list(tg_tracks), ds) recs = fm.predict() ev.evaluate_fold(recs) map_at_five = ev.get_mean_map() print("MAP@5 Final", map_at_five)