Skip to content

Instantly share code, notes, and snippets.

@danstowell
Created April 8, 2014 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danstowell/10174964 to your computer and use it in GitHub Desktop.
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
# 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