예제 #1
0
def basic_usage_large_dataset():
    from recommender_metrics import calculate_metrics
    from recommender_metrics import generate_random_data
    import json

    groups, scores, labels = generate_random_data(n_users=50000)
    print("Larger data:")
    print("  #groups:", len(groups))
    print("  #scores:", len(scores))
    print("  #labels:", len(labels))
    print()

    metrics = calculate_metrics(group_ids=groups, scores=scores, labels=labels)
    print("Metrics:")
    print(json.dumps(metrics, indent=2))
    print("\n\n\n")
예제 #2
0
def basic_usage_group_filttering():
    from recommender_metrics import calculate_metrics
    from recommender_metrics import generate_random_data
    import json

    print("Running example3")

    groups, scores, labels = generate_random_data()
    print("Data:")
    print("  #groups:", len(groups))
    print("  #scores:", len(scores))
    print("  #labels:", len(labels))
    print()

    metrics = calculate_metrics(group_ids=groups,
                                scores=scores,
                                labels=labels,
                                remove_empty=True)
    print("Metrics:")
    print(json.dumps(metrics, indent=2))
    print("\n\n\n")
    def test_empty(self):
        target = {
            "mAP@1": 0.2631578947368421,
            "precision@1": 0.2631578947368421,
            "recall@1": 0.07631578947368421,
            "mAP@5": 0.5046783625730993,
            "precision@5": 0.3140350877192983,
            "recall@5": 0.45743525480367586,
            "mAP@10": 0.4538314536340852,
            "precision@10": 0.2941520467836258,
            "recall@10": 0.6738512949039264,
            "mAP@20": 0.424754158736318,
            "precision@20": 0.33355881010883454,
            "recall@20": 1.0,
        }

        groups, scores, labels = recommender_metrics.generate_random_data()
        metrics = recommender_metrics.calculate_metrics(group_ids=groups,
                                                        scores=scores,
                                                        labels=labels,
                                                        remove_empty=True)
        self.dict_vals_all_close(target=target,
                                 pred=metrics,
                                 desc=f"Removal of empty group labels")
예제 #4
0
def basic_usage_custom_metrics_k():
    from recommender_metrics import calculate_metrics
    from recommender_metrics import generate_random_data
    import json

    print("Running example4")

    groups, scores, labels = generate_random_data()
    print("Data:")
    print("  #groups:", len(groups))
    print("  #scores:", len(scores))
    print("  #labels:", len(labels))
    print()

    metrics = calculate_metrics(
        group_ids=groups,
        scores=scores,
        labels=labels,
        k_list=[1, 2, 4, 8, 16],
        metrics=["mAP", "precision", "recall", "ndcg", "auroc"],
    )
    print("Metrics:")
    print(json.dumps(metrics, indent=2))
    print("\n\n\n")
         "recall@1": 0.1,
         "mAP@5": 0.8041666666666667,
         "precision@5": 0.8,
         "recall@5": 0.4,
         "mAP@10": 0.8121315192743763,
         "precision@10": 0.7,
         "recall@10": 0.7,
         "mAP@20": 0.7555050505050506,
         "precision@20": 0.5,
         "recall@20": 1.0,
     },
 ),
 dict(
     kwargs=dict(
         zip(("group_ids", "scores", "labels"),
             recommender_metrics.generate_random_data())),
     name="Bigger random sample",
     targets={
         "mAP@1": 0.25,
         "precision@1": 0.25,
         "recall@1": 0.12250000000000001,
         "mAP@5": 0.47944444444444434,
         "precision@5": 0.2983333333333334,
         "recall@5": 0.4845634920634921,
         "mAP@10": 0.4311398809523809,
         "precision@10": 0.2794444444444445,
         "recall@10": 0.69015873015873,
         "mAP@20": 0.4035164507995021,
         "precision@20": 0.3168808696033928,
         "recall@20": 1.0,
     },