Skip to content

Instantly share code, notes, and snippets.

@mattdodge
Created March 19, 2013 16:50
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 mattdodge/5197813 to your computer and use it in GitHub Desktop.
Save mattdodge/5197813 to your computer and use it in GitHub Desktop.
Run a Bayesian analysis on matchup probabilities for an NCAA bracket. This will spit out the probability that each seed makes it to a given round
'''
Created on Mar 18, 2013
@author: Matt Dodge
'''
'''
You can put your own probabilities here. It is a dict where the key is the lower seed
(lower by number, not by rank) followed by the higher seed, separated by comma, no space.
The value is the probability that the lower seed beats the higher seed.
You will need to have one for every matchup.
'''
west = {"1,8": 0.6333333333333333, "1,9": 0.76, "1,6": 0.675, "1,7": 0.7333333333333333, "1,4": 0.6816666666666668, "1,5": 0.65, "1,2": 0.565, "1,3": 0.635, "5,8": 0.49666666666666665, "5,9": 0.6066666666666667, "3,8": 0.51, "3,9": 0.6216666666666666, "3,4": 0.5283333333333333, "3,5": 0.47, "3,6": 0.5133333333333333, "3,7": 0.575, "5,6": 0.5533333333333333, "5,7": 0.585, "15,16": 0.6583333333333333, "3,16": 0.9333333333333332, "3,14": 0.8533333333333333, "3,15": 0.8333333333333333, "3,12": 0.665, "3,13": 0.705, "3,10": 0.615, "3,11": 0.6933333333333332, "5,14": 0.835, "5,15": 0.835, "5,16": 0.9333333333333332, "5,10": 0.6283333333333334, "5,11": 0.6866666666666668, "5,12": 0.67, "5,13": 0.7333333333333333, "14,16": 0.655, "14,15": 0.495, "2,9": 0.7083333333333333, "11,12": 0.465, "11,13": 0.5483333333333333, "11,14": 0.685, "11,15": 0.69, "11,16": 0.815, "2,8": 0.5733333333333334, "10,16": 0.855, "10,15": 0.725, "10,14": 0.7433333333333333, "10,13": 0.585, "10,12": 0.5233333333333333, "10,11": 0.5633333333333334, "6,9": 0.57, "6,8": 0.45833333333333337, "6,7": 0.545, "6,15": 0.81, "6,14": 0.7966666666666667, "6,16": 0.9033333333333333, "6,11": 0.6516666666666667, "6,10": 0.5733333333333334, "6,13": 0.6766666666666667, "6,12": 0.615, "8,9": 0.6416666666666667, "12,13": 0.5616666666666666, "12,15": 0.7166666666666667, "12,14": 0.72, "12,16": 0.8433333333333333, "4,9": 0.55, "4,8": 0.45666666666666667, "1,10": 0.785, "1,11": 0.8283333333333333, "1,12": 0.81, "1,13": 0.8366666666666667, "1,14": 0.9233333333333333, "1,15": 0.7516666666666667, "1,16": 0.9833333333333333, "2,5": 0.5433333333333333, "2,4": 0.605, "2,7": 0.6716666666666667, "2,6": 0.6333333333333333, "2,3": 0.5683333333333334, "4,7": 0.5383333333333333, "4,6": 0.5, "4,5": 0.43833333333333335, "2,11": 0.7766666666666667, "2,10": 0.7316666666666667, "2,13": 0.795, "2,12": 0.7483333333333333, "2,15": 0.9233333333333333, "2,14": 0.9083333333333333, "2,16": 0.8, "8,13": 0.715, "8,12": 0.6683333333333333, "8,11": 0.6966666666666668, "8,10": 0.6416666666666667, "8,16": 0.9166666666666667, "8,15": 0.84, "8,14": 0.8333333333333333, "7,12": 0.5583333333333333, "7,13": 0.6266666666666666, "7,10": 0.5283333333333333, "7,11": 0.5983333333333334, "7,16": 0.885, "7,14": 0.7683333333333333, "7,15": 0.75, "4,16": 0.9216666666666667, "4,15": 0.8333333333333333, "4,14": 0.8166666666666668, "4,13": 0.7066666666666667, "4,12": 0.615, "4,11": 0.66, "4,10": 0.595, "13,15": 0.61, "7,8": 0.415, "7,9": 0.51, "13,16": 0.7816666666666667, "13,14": 0.6316666666666666, "9,10": 0.505, "9,11": 0.555, "9,12": 0.5416666666666666, "9,13": 0.5983333333333334, "9,14": 0.735, "9,15": 0.7433333333333333, "9,16": 0.8583333333333333}
east = {"1,8": 0.7483333333333333, "1,9": 0.815, "1,6": 0.7616666666666667, "1,7": 0.7733333333333333, "1,4": 0.6366666666666666, "1,5": 0.735, "1,2": 0.64, "1,3": 0.6916666666666668, "5,8": 0.5066666666666666, "5,9": 0.6033333333333334, "3,8": 0.5233333333333333, "3,9": 0.6283333333333334, "3,4": 0.42666666666666664, "3,5": 0.515, "3,6": 0.5583333333333333, "3,7": 0.5616666666666666, "5,6": 0.565, "5,7": 0.565, "15,16": 0.5816666666666667, "3,16": 0.9066666666666667, "3,14": 0.73, "3,15": 0.8416666666666667, "3,12": 0.6533333333333333, "3,13": 0.8433333333333333, "3,10": 0.625, "3,11": 0.6783333333333332, "5,14": 0.695, "5,15": 0.81, "5,16": 0.8816666666666667, "5,10": 0.5966666666666667, "5,11": 0.64, "5,12": 0.6283333333333334, "5,13": 0.8133333333333332, "14,16": 0.7183333333333333, "14,15": 0.6683333333333333, "2,9": 0.69, "11,12": 0.4683333333333334, "11,13": 0.7133333333333333, "11,14": 0.5433333333333333, "11,15": 0.7216666666666667, "11,16": 0.7683333333333333, "2,8": 0.5933333333333334, "10,16": 0.7783333333333333, "10,15": 0.71, "10,14": 0.5766666666666667, "10,13": 0.7233333333333333, "10,12": 0.5066666666666666, "10,11": 0.5283333333333333, "6,9": 0.5583333333333333, "6,8": 0.435, "6,7": 0.49, "6,15": 0.765, "6,14": 0.645, "6,16": 0.845, "6,11": 0.595, "6,10": 0.5433333333333333, "6,13": 0.7666666666666667, "6,12": 0.5683333333333334, "8,9": 0.6066666666666667, "12,13": 0.6916666666666668, "12,15": 0.67, "12,14": 0.5633333333333334, "12,16": 0.755, "4,9": 0.6716666666666667, "4,8": 0.5816666666666667, "1,10": 0.815, "1,11": 0.85, "1,12": 0.84, "1,13": 0.9416666666666668, "1,14": 0.9016666666666667, "1,15": 0.775, "1,16": 0.9683333333333333, "2,5": 0.5783333333333334, "2,4": 0.505, "2,7": 0.6666666666666667, "2,6": 0.64, "2,3": 0.57, "4,7": 0.6283333333333334, "4,6": 0.6216666666666666, "4,5": 0.565, "2,11": 0.7433333333333333, "2,10": 0.6983333333333333, "2,13": 0.8916666666666667, "2,12": 0.7266666666666667, "2,15": 0.89, "2,14": 0.8083333333333332, "2,16": 0.7716666666666667, "8,13": 0.805, "8,12": 0.6383333333333333, "8,11": 0.6316666666666666, "8,10": 0.605, "8,16": 0.8616666666666667, "8,15": 0.805, "8,14": 0.665, "7,12": 0.5733333333333334, "7,13": 0.7583333333333333, "7,10": 0.5333333333333333, "7,11": 0.5833333333333334, "7,16": 0.825, "7,14": 0.615, "7,15": 0.7366666666666667, "4,16": 0.93, "4,15": 0.8866666666666667, "4,14": 0.785, "4,13": 0.89, "4,12": 0.6833333333333332, "4,11": 0.7116666666666667, "4,10": 0.6933333333333332, "13,15": 0.5083333333333333, "7,8": 0.43, "7,9": 0.545, "13,16": 0.59, "13,14": 0.335, "9,10": 0.5016666666666666, "9,11": 0.5183333333333333, "9,12": 0.5133333333333333, "9,13": 0.72, "9,14": 0.585, "9,15": 0.7266666666666667, "9,16": 0.79}
south = {"1,8": 0.71, "1,9": 0.7783333333333333, "1,6": 0.725, "1,7": 0.7133333333333333, "1,4": 0.6016666666666667, "1,5": 0.6883333333333332, "1,2": 0.5833333333333334, "1,3": 0.47833333333333333, "5,8": 0.51, "5,9": 0.62, "3,8": 0.705, "3,9": 0.7766666666666667, "3,4": 0.595, "3,5": 0.6783333333333332, "3,6": 0.7283333333333333, "3,7": 0.7116666666666667, "5,6": 0.5433333333333333, "5,7": 0.5383333333333333, "15,16": 0.555, "3,16": 0.955, "3,14": 0.9433333333333332, "3,15": 0.9416666666666668, "3,12": 0.8266666666666667, "3,13": 0.8833333333333333, "3,10": 0.7733333333333333, "3,11": 0.7516666666666667, "5,14": 0.8433333333333333, "5,15": 0.8583333333333333, "5,16": 0.9066666666666667, "5,10": 0.6183333333333334, "5,11": 0.5766666666666667, "5,12": 0.72, "5,13": 0.7833333333333333, "14,16": 0.585, "14,15": 0.5116666666666666, "2,9": 0.72, "11,12": 0.5916666666666667, "11,13": 0.7116666666666667, "11,14": 0.7683333333333333, "11,15": 0.7883333333333333, "11,16": 0.845, "2,8": 0.6383333333333333, "10,16": 0.8, "10,15": 0.7383333333333333, "10,14": 0.7266666666666667, "10,13": 0.6683333333333333, "10,12": 0.5333333333333333, "10,11": 0.44333333333333336, "6,9": 0.5566666666666666, "6,8": 0.45666666666666667, "6,7": 0.485, "6,15": 0.8016666666666667, "6,14": 0.7833333333333333, "6,16": 0.8583333333333333, "6,11": 0.47, "6,10": 0.5566666666666666, "6,13": 0.7066666666666667, "6,12": 0.595, "8,9": 0.615, "12,13": 0.6316666666666666, "12,15": 0.7183333333333333, "12,14": 0.695, "12,16": 0.765, "4,9": 0.7133333333333333, "4,8": 0.595, "1,10": 0.7883333333333333, "1,11": 0.7383333333333333, "1,12": 0.835, "1,13": 0.915, "1,14": 0.94, "1,15": 0.7883333333333333, "1,16": 0.975, "2,5": 0.6216666666666666, "2,4": 0.51, "2,7": 0.6616666666666667, "2,6": 0.6716666666666667, "2,3": 0.41666666666666663, "4,7": 0.6233333333333334, "4,6": 0.635, "4,5": 0.615, "2,11": 0.68, "2,10": 0.7416666666666667, "2,13": 0.87, "2,12": 0.7766666666666667, "2,15": 0.9333333333333332, "2,14": 0.9183333333333333, "2,16": 0.785, "8,13": 0.74, "8,12": 0.6366666666666666, "8,11": 0.52, "8,10": 0.5966666666666667, "8,16": 0.8733333333333333, "8,15": 0.835, "8,14": 0.81, "7,12": 0.62, "7,13": 0.7233333333333333, "7,10": 0.5766666666666667, "7,11": 0.5166666666666666, "7,16": 0.8666666666666667, "7,14": 0.7866666666666667, "7,15": 0.8083333333333332, "4,16": 0.945, "4,15": 0.9183333333333333, "4,14": 0.8966666666666667, "4,13": 0.8633333333333333, "4,12": 0.7516666666666667, "4,11": 0.6533333333333333, "4,10": 0.705, "13,15": 0.5716666666666667, "7,8": 0.47, "7,9": 0.5716666666666667, "13,16": 0.6533333333333333, "13,14": 0.555, "9,10": 0.5083333333333333, "9,11": 0.43833333333333335, "9,12": 0.5283333333333333, "9,13": 0.6516666666666667, "9,14": 0.7183333333333333, "9,15": 0.7466666666666667, "9,16": 0.795}
midwest = {"1,8": 0.7766666666666667, "1,9": 0.7783333333333333, "1,6": 0.7516666666666667, "1,7": 0.7383333333333333, "1,4": 0.7316666666666667, "1,5": 0.7333333333333333, "1,2": 0.5966666666666667, "1,3": 0.64, "5,8": 0.5533333333333333, "5,9": 0.5083333333333333, "3,8": 0.6516666666666667, "3,9": 0.6333333333333333, "3,4": 0.5783333333333334, "3,5": 0.6, "3,6": 0.6083333333333334, "3,7": 0.5783333333333334, "5,6": 0.5066666666666666, "5,7": 0.45666666666666667, "15,16": 0.61, "3,16": 0.9633333333333333, "3,14": 0.8316666666666667, "3,15": 0.9166666666666667, "3,12": 0.7116666666666667, "3,13": 0.8216666666666668, "3,10": 0.655, "3,11": 0.67, "5,14": 0.7116666666666667, "5,15": 0.8716666666666667, "5,16": 0.94, "5,10": 0.5283333333333333, "5,11": 0.545, "5,12": 0.5916666666666667, "5,13": 0.7683333333333333, "14,16": 0.795, "14,15": 0.6966666666666668, "2,9": 0.6816666666666668, "11,12": 0.5666666666666667, "11,13": 0.6766666666666667, "11,14": 0.66, "11,15": 0.8116666666666668, "11,16": 0.8883333333333333, "2,8": 0.6833333333333332, "10,16": 0.8833333333333333, "10,15": 0.7966666666666667, "10,14": 0.67, "10,13": 0.685, "10,12": 0.545, "10,11": 0.49166666666666664, "6,9": 0.53, "6,8": 0.5483333333333333, "6,7": 0.47, "6,15": 0.8633333333333333, "6,14": 0.7183333333333333, "6,16": 0.9283333333333332, "6,11": 0.5416666666666666, "6,10": 0.5583333333333333, "6,13": 0.745, "6,12": 0.59, "8,9": 0.44333333333333336, "12,13": 0.6683333333333333, "12,15": 0.7783333333333333, "12,14": 0.6183333333333334, "12,16": 0.8716666666666667, "4,9": 0.5683333333333334, "4,8": 0.605, "1,10": 0.7816666666666667, "1,11": 0.8016666666666667, "1,12": 0.845, "1,13": 0.925, "1,14": 0.9116666666666667, "1,15": 0.8033333333333332, "1,16": 0.985, "2,5": 0.6416666666666667, "2,4": 0.625, "2,7": 0.6383333333333333, "2,6": 0.6466666666666667, "2,3": 0.555, "4,7": 0.515, "4,6": 0.535, "4,5": 0.5216666666666666, "2,11": 0.71, "2,10": 0.7066666666666667, "2,13": 0.875, "2,12": 0.775, "2,15": 0.9533333333333333, "2,14": 0.86, "2,16": 0.81, "8,13": 0.705, "8,12": 0.5216666666666666, "8,11": 0.4716666666666666, "8,10": 0.48333333333333334, "8,16": 0.9083333333333333, "8,15": 0.8216666666666668, "8,14": 0.645, "7,12": 0.6233333333333334, "7,13": 0.7566666666666667, "7,10": 0.605, "7,11": 0.585, "7,16": 0.93, "7,14": 0.7316666666666667, "7,15": 0.8733333333333333, "4,16": 0.95, "4,15": 0.895, "4,14": 0.7566666666666667, "4,13": 0.8066666666666668, "4,12": 0.6233333333333334, "4,11": 0.6, "4,10": 0.5766666666666667, "13,15": 0.6316666666666666, "7,8": 0.5833333333333334, "7,9": 0.55, "13,16": 0.7733333333333333, "13,14": 0.43833333333333335, "9,10": 0.54, "9,11": 0.5133333333333333, "9,12": 0.5783333333333334, "9,13": 0.7333333333333333, "9,14": 0.685, "9,15": 0.8316666666666667, "9,16": 0.9033333333333333}
'''
Pick the list/division that you want to run the analysis for
'''
l = midwest
def not_(val):
return 1.0 - val
def matchup(seed1, seed2):
if (seed1 > seed2):
return not_(l[str(seed2) + ',' + str(seed1)])
else:
return l[str(seed1) + ',' + str(seed2)]
def matchups(seed, round):
if round == 32:
return [17 - seed]
elif round == 16:
minSeed = min(seed, 17-seed)
return [9-minSeed, 8+minSeed]
elif round == 8:
if seed in [1,16,8,9]:
return [5,12,4,13]
elif seed in [5,12,4,13]:
return [1,16,8,9]
elif seed in [6,11,3,14]:
return [7,10,2,15]
else:
return [6,11,3,14]
elif round == 4:
if seed in [1,16,8,9,5,12,4,13]:
return [6,11,3,14,7,10,2,15]
else:
return [1,16,8,9,5,12,4,13]
return []
# Defines the probability that a seed MAKES IT TO the round
def probOfRound(seed, round):
if round > 32:
return 1
possibleOpps = matchups(seed, round)
curProb = 0.0
for opp in possibleOpps:
curProb += matchup(seed, opp) * probOfRound(opp, round * 2)
return curProb * probOfRound(seed, round*2)
if __name__ == '__main__':
for seed in range(1,17):
print '{0}\t{1}\t{2}\t{3}\t{4}'.format(seed,
probOfRound(seed, 32),
probOfRound(seed, 16),
probOfRound(seed, 8),
probOfRound(seed, 4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment