Created
April 24, 2014 15:43
-
-
Save arjoly/11259383 to your computer and use it in GitHub Desktop.
Benchmark for ranking metrics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import division | |
| from __future__ import print_function | |
| from timeit import timeit | |
| from functools import partial | |
| # from sklearn.metrics import roc_auc_score | |
| # from sklearn.metrics import average_precision_score | |
| from sklearn.metrics import label_ranking_average_precision_score | |
| import numpy as np | |
| METRICS = { | |
| "lrap": label_ranking_average_precision_score | |
| } | |
| np.random.seed(0) | |
| n_samples = 10000 | |
| n_labels = 500 | |
| y_true = np.random.uniform(size=(n_samples, n_labels)) >= 0.9 | |
| y_score = np.random.uniform(size=(n_samples, n_labels)) | |
| for order in ("C", ): | |
| print("{} array order".format(order)) | |
| print("-------------") | |
| chrono = dict() | |
| if order == "C": | |
| y_true = np.ascontiguousarray(y_true) | |
| y_score = np.ascontiguousarray(y_score) | |
| elif order == "F": | |
| y_true = np.asfortranarray(y_true) | |
| y_score = np.asfortranarray(y_score) | |
| prefix = order + "-" | |
| for name in METRICS: | |
| print("{0}...".format(prefix + name), end="") | |
| metric = METRICS[name] | |
| chrono[prefix + name] = timeit(partial(metric, y_true, y_score), number=1) | |
| print("ok", end="\n") | |
| for name in sorted(chrono, key=chrono.get): | |
| print("{0}s \t= {1}".format(chrono[name], name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment