Created
April 8, 2014 19:20
-
-
Save danstowell/10174964 to your computer and use it in GitHub Desktop.
Empirical plot of the chance values attained for the "Mean Average Precision" statistic
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
# understanding chance level in MAP calculation | |
import ml_metrics | |
import numpy as np | |
import matplotlib.pyplot as plt | |
results = np.zeros((100,100)) | |
data = np.zeros((100, 10)) | |
# no need to shuffle the annots since the groundtruth will be randomly generated | |
annots = [range(100)] * 10 | |
for posness in range(results.shape[0]): | |
print(posness) | |
posprob = float(posness) / (results.shape[0]-1) | |
for mapat_n in range(results.shape[0]): | |
if mapat_n==0: | |
results[posness, mapat_n] = 1 | |
else: | |
gt = [list(row) for row in ((np.random.uniform(size=np.shape(annots)) < posprob) * 1)] | |
results[posness, mapat_n] = ml_metrics.mapk(gt, annots, mapat_n) | |
plt.imshow(results * 100, origin='lower', interpolation='nearest') | |
plt.xlabel("Num positives in groundtruth") | |
plt.ylabel("map_at_what") | |
plt.title("Chance levels for Mean Avg Precision") | |
plt.colorbar() | |
#plt.show() | |
plt.savefig("mapatchance.png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment