Last active
December 8, 2017 13:14
-
-
Save myyc/ee71f89c3dd523a2fe1d1b0aae46d47b to your computer and use it in GitHub Desktop.
chelsea is 66.667% fucked
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
import pandas as pd | |
import numpy as np | |
import seaborn as sns | |
from ipywidgets import interact, RadioButtons as RB | |
fs = [("Barcelona", "ESP","D"), ("Beşiktaş", "TUR","G"), | |
("Liverpool", "ENG","E"), | |
("City", "ENG","F"), ("Man U", "ENG","A"), | |
("PSG","FRA","B"), ("Roma", "ITA","C"), | |
("Tottenham", "ENG","H")] | |
sn = [("Basel","SWI","A"), ("Chelsea","ENG","C"), | |
("Juventus","ITA","D"), ("Porto","POR","G"), | |
("Real Madrid","ESP","H"), ("Sevilla","ESP","E"), | |
("Shakhtar","UKR","F"), | |
("Bayern","GER","B")] | |
mt = {u[0]: {v[0]: 0 for v in sn} for u in fs} | |
# can be optimised | |
N = 10000000 | |
for i in range(N): | |
u = fs[np.random.randint(8)] | |
v = sn[np.random.randint(8)] | |
M = 1 | |
m = N | |
if u[1]!=v[1] and u[2]!=v[2]: | |
mt[u[0]][v[0]] += 1 | |
if mt[u[0]][v[0]] < m and mt[u[0]][v[0]] > 0: | |
m = mt[u[0]][v[0]] | |
for k in mt: | |
for j in mt[k]: | |
if mt[k][j] == 0: | |
mt[k][j] = np.nan | |
@interact(norm=RB(options=["none", "x", "y"])) | |
def _p(norm): | |
df = pd.DataFrame(mt) | |
if norm == "y": | |
df = 100*df/df.sum() | |
t = "Probability of `y` facing `x`" | |
elif norm == "x": | |
df = 100*df.apply(lambda x: x/df.sum(axis=1)) | |
t = "Probability of `x` facing `y`" | |
else: | |
t = "# simulations" | |
ax = sns.heatmap(df, annot=(norm != "none"), | |
vmin=None if norm == "none" else 0, | |
cbar=(norm == "none"), fmt=".1f") | |
ax.set_title(t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment