Пример #1
0
def main():
    print("Setting up dataset and evaluator...")
    # Setup dataset and 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)
    ev = Evaluator(seed=False)
    ev.cross_validation(5, dataset.train_final.copy())

    for i in range(0, 5):
        print("Training models for fold {}-th".format(i))
        train_models(dataset, ev, n_clusters=20)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
def main(n_evaluations):
    print("Setting up dataset...")
    # Setup dataset and 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)

    # Run mAP evaluation a number of times to reduce the variance
    # of the results
    n_clusters = 20
    best = np.zeros((4, n_clusters), dtype=int)
    for i in range(n_evaluations):
        print("Running cross validation no. {}".format(i))
        print("Setting up the Evaluator...")
        ev = Evaluator(seed=False)
        ev.cross_validation(5, dataset.train_final.copy())
        folding_best = train_models(dataset, ev,
                                    n_folds=5, n_clusters=n_clusters)
        best += folding_best
        top = top_over_cluster(best)
        _print_top(top)
Пример #5
0
        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)