MMMC the 2015 update

See the original blog post for details and history. Here's the short story: in my Statistical and Thermal Physics class, we want to use Monte Carlo simulations to generate brackets for March Madness. There are at least two obvious ways to go about this:

  1. Make some function that tells us the chance that team A beats team B, then flip coins for each matchup. That gets you one bracket. Repeat 100,000 times, collect statistics. This is the way Nate Silver's 538.com handles simulations for basketball, elections, etc, and I should probably implement it (note to self/motivated students: it's as easy as just generating 100,000 new brackets at a given temperature).

  2. Generate one bracket, then do a Monte-Carlo walk through bracket space. This is tougher. We have to figure out how to make a move in bracket space, which is part of the fun of Monte Carlo simulations in general. To see how this is done, check out the code in Bracket.swap and Brackets.simulate.

As you can tell, we take option 2 above. I've made things a bit nicer from a user standpoint this year; here's a walkthrough. First, load up our standard IPython setup

In [1]:
from __future__ import division
%matplotlib inline
import seaborn as sns
sns.set_style('darkgrid')
import numpy as np
from matplotlib import pyplot as plt
from IPython.display import HTML

The basics

make me a single bracket at a given temperature

In [2]:
import MarchMadnessMonteCarlo as MMMC
teams = MMMC.teams['south']
b = MMMC.Bracket(teams=teams,T=0.5)
print b
Duke (1)                                                     
Robert Morris (16)        Duk (1)                            
San Diego St. (8)                                            
St. John's (9)            San (8)  Duk (1)                   
Utah (5)                                                     
Stephen F. Austin (12)    Ste (12)                           
Georgetown (4)                                               
Eastern Washington (13)   Geo (4)  Ste (12) Ste (12)         
SMU (6)                   UCL (11) UCL (11) UCL (11) Ste (12)
UCLA (11)                                                    
Iowa St. (3)              Iow (3)                            
UAB (14)                                                     
Iowa (7)                  Iow (7)  Iow (7)                   
Davidson (10)                                                
Gonzaga (2)               Gon (2)                            
North Dakota St. (15)                                        
Total bracket energy: -17.4533174222

Now, instead of asking for all of the teams in the South, make up a set of Final Four teams, and run 1000 simulations. Show some statistics

In [3]:
sr = MMMC.simulate(1000,['Kentucky','Wisconsin','Villanova','Duke'],0.5)
MMMC.showstats(sr,newfig=True)
Lowest energy bracket
Kentucky (1)                               
Wisconsin (1)             Ken (1)          
Villanova (1)             Vil (1)  Ken (1) 
Duke (1)                                   
Total bracket energy: -3.05919025906

Most common bracket (159)
Kentucky (1)                               
Wisconsin (1)             Ken (1)          
Villanova (1)             Duk (1)  Ken (1) 
Duke (1)                                   
Total bracket energy: -3.04122415391

As you can see, we fully sample bracket space pretty quickly (look at the graph in the top right, with the unique brackets shown).

What should our temperature be?

If we had chosen option 1 at the top, we'd just flip coins with a given probability of winning. Here (and this may be a questionable decision), we need to set an overall temperature for our simulation. Intuitively, the higher the temperature, the closer we come to a random outcome. The lower the temperature, the closer we come to a "best seed always wins" bracket. If we're going to make sense of temperature, we should pick a reasonable energy function.

We can use KenPom's log5 defined as

def log5_energy_game(winner, loser):
    A,B = strength[winner],strength[loser]
    # see http://207.56.97.150/articles/playoff2002.htm
    win_pct = (A-A*B)/(A+B-2*A*B)
    return -win_pct

Conveniently, that's coded up for you in MarchMadnessMonteCarlo.examples.

Later on, we could make a fancy energy function with, e.g., a weighted average of KenPom, Jeff Sagarin, and the NCAA rankings.

In [4]:
import MarchMadnessMonteCarlo.examples
MMMC.set_energy_function(MarchMadnessMonteCarlo.examples.log5_energy_game)

Now, what should our actual temperature be? Historically, we know that an 8 seed vs. a 9 seed should essentially be a tossup. So, as a proxy here, we could just look at the chance of an 8 seed winning over a range of temperatures, and pick the point where it's pretty close to 0.5.

In [5]:
def winpct8(team8,team9,T,numtrials=10000):
    results = [MMMC.playgame(team8,team9,T)[0] == team8 for i in range(numtrials)]
    return np.average(results)
def plotwins(team8,team9,numtrials=10000):
    Ts = np.linspace(0,3,100)
    pct = [winpct8(team8,team9,T,numtrials) for T in Ts]
    plt.plot(Ts,pct,label='{t1} vs. {t2}'.format(t1=team8,t2=team9))
    plt.xlabel('T')
    plt.ylabel('winpct')

We'll look at it for all four of the 8 vs. 9 matchups

In [6]:
plotwins('Cincinnati','Purdue')
plotwins('Oregon','Oklahoma St.')
plotwins('North Carolina St.','LSU')
plotwins('San Diego St.',"St. John's")
plt.legend()
Out[6]:
<matplotlib.legend.Legend at 0x7fc7e94c7650>

A couple of things jump out. First, the green line: KenPom has Oregon ranked below Oklahoma State, so the curve approaches 50% from below instead of from above.

Second, just eyeballing that, it looks like we could make a legitimate argument for almost anything between T=1.0 and 2.0.

What does that do to "clear" matchups? Well, Kentucky is a big favorite over Kansas with this model:

In [7]:
MarchMadnessMonteCarlo.examples.log5_energy_game('Kentucky','Kansas')
Out[7]:
-0.8176307825952608
In [8]:
plotwins('Kentucky','Kansas')

If I pick T=1.5, I get Kentucky, the favorite, winning 60% of the time. You can feel free to choose a "saner" temperature, but I'm rooting for KU here!

Running some brackets!

So what does a bracket happen to look like? Well, in the original blog post, I mentioned that we came up with two different ways to run brackets. It can take a while to run a bracket, so a fast way (implemented as runbracket2) is to run separate brackets for each of the individual regions, then take the winner from each region's most common bracket to form a Final Four. Below, we do just that, running 10,000 trials for each of the regions, and 1000 trials for the Final Four.

In [9]:
results = MMMC.runbracket2(ntrials1=10000,ntrials2=1000,T=1.5)
YOUR LOWEST ENERGY BRACKETS
LOWEST ENERGY BRACKET FOR REGION midwest
Kentucky (1)                                                 
Hampton (16)              Ken (1)                            
Cincinnati (8)                                               
Purdue (9)                Cin (8)  Ken (1)                   
West Virginia (5)                                            
Buffalo (12)              Wes (5)                            
Maryland (4)                                                 
Valparaiso (13)           Mar (4)  Wes (5)  Ken (1)          
Butler (6)                Tex (11) Not (3)  Not (3)  Ken (1) 
Texas (11)                                                   
Notre Dame (3)            Not (3)                            
Northeastern (14)                                            
Wichita St. (7)           Wic (7)  Kan (2)                   
Indiana (10)                                                 
Kansas (2)                Kan (2)                            
New Mexico St. (15)                                          
Total bracket energy: -10.5524230049


LOWEST ENERGY BRACKET FOR REGION west
Wisconsin (1)                                                
Coastal Carolina (16)     Wis (1)                            
Oregon (8)                                                   
Oklahoma St. (9)          Okl (9)  Wis (1)                   
Arkansas (5)                                                 
Wofford (12)              Ark (5)                            
North Carolina (4)                                           
Harvard (13)              Nor (4)  Nor (4)  Wis (1)          
Xavier (6)                Xav (6)  Bay (3)  Ari (2)  Ari (2) 
Mississippi (11)                                             
Baylor (3)                Bay (3)                            
Georgia St. (14)                                             
VCU (7)                   Ohi (10) Ari (2)                   
Ohio St. (10)                                                
Arizona (2)               Ari (2)                            
Texas Southern (15)                                          
Total bracket energy: -10.8592988759


LOWEST ENERGY BRACKET FOR REGION south
Duke (1)                                                     
Robert Morris (16)        Duk (1)                            
San Diego St. (8)                                            
St. John's (9)            San (8)  Duk (1)                   
Utah (5)                                                     
Stephen F. Austin (12)    Uta (5)                            
Georgetown (4)                                               
Eastern Washington (13)   Geo (4)  Uta (5)  Duk (1)          
SMU (6)                   SMU (6)  Iow (3)  Gon (2)  Gon (2) 
UCLA (11)                                                    
Iowa St. (3)              Iow (3)                            
UAB (14)                                                     
Iowa (7)                  Iow (7)  Gon (2)                   
Davidson (10)                                                
Gonzaga (2)               Gon (2)                            
North Dakota St. (15)                                        
Total bracket energy: -10.5015086048


LOWEST ENERGY BRACKET FOR REGION east
Villanova (1)                                                
Lafayette (16)            Vil (1)                            
North Carolina St. (8)                                       
LSU (9)                   Nor (8)  Vil (1)                   
Northern Iowa (5)                                            
Wyoming (12)              Nor (5)                            
Louisville (4)                                               
UC Irvine (13)            Lou (4)  Nor (5)  Vil (1)          
Providence (6)            Pro (6)  Okl (3)  Vir (2)  Vir (2) 
Dayton (11)                                                  
Oklahoma (3)              Okl (3)                            
Albany (14)                                                  
Michigan St. (7)          Mic (7)  Vir (2)                   
Georgia (10)                                                 
Virginia (2)              Vir (2)                            
Belmont (15)                                                 
Total bracket energy: -10.8839299775


LOWEST ENERGY BRACKET FOR FINAL FOUR
Kentucky (1)                               
Wisconsin (1)             Ken (1)          
Utah (5)                  Vir (2)  Ken (1) 
Virginia (2)                               
Total bracket energy: -1.95692907302

YOUR MOST COMMON BRACKETS
MOST COMMON BRACKET FOR REGION midwest
Kentucky (1)                                                 
Hampton (16)              Ken (1)                            
Cincinnati (8)                                               
Purdue (9)                Pur (9)  Ken (1)                   
West Virginia (5)                                            
Buffalo (12)              Wes (5)                            
Maryland (4)                                                 
Valparaiso (13)           Mar (4)  Mar (4)  Ken (1)          
Butler (6)                Tex (11) Not (3)  Kan (2)  Ken (1) 
Texas (11)                                                   
Notre Dame (3)            Not (3)                            
Northeastern (14)                                            
Wichita St. (7)           Wic (7)  Kan (2)                   
Indiana (10)                                                 
Kansas (2)                Kan (2)                            
New Mexico St. (15)                                          
Total bracket energy: -10.3577160931

number of times this bracket happened: 11


MOST COMMON BRACKET FOR REGION west
Wisconsin (1)                                                
Coastal Carolina (16)     Wis (1)                            
Oregon (8)                                                   
Oklahoma St. (9)          Ore (8)  Wis (1)                   
Arkansas (5)                                                 
Wofford (12)              Ark (5)                            
North Carolina (4)                                           
Harvard (13)              Nor (4)  Nor (4)  Wis (1)          
Xavier (6)                Mis (11) Mis (11) Ohi (10) Wis (1) 
Mississippi (11)                                             
Baylor (3)                Geo (14)                           
Georgia St. (14)                                             
VCU (7)                   Ohi (10) Ohi (10)                  
Ohio St. (10)                                                
Arizona (2)               Tex (15)                           
Texas Southern (15)                                          
Total bracket energy: -9.30614882152

number of times this bracket happened: 13


MOST COMMON BRACKET FOR REGION south
Duke (1)                                                     
Robert Morris (16)        Duk (1)                            
San Diego St. (8)                                            
St. John's (9)            St. (9)  Duk (1)                   
Utah (5)                                                     
Stephen F. Austin (12)    Uta (5)                            
Georgetown (4)                                               
Eastern Washington (13)   Geo (4)  Uta (5)  Uta (5)          
SMU (6)                   UCL (11) UCL (11) Gon (2)  Uta (5) 
UCLA (11)                                                    
Iowa St. (3)              Iow (3)                            
UAB (14)                                                     
Iowa (7)                  Dav (10) Gon (2)                   
Davidson (10)                                                
Gonzaga (2)               Gon (2)                            
North Dakota St. (15)                                        
Total bracket energy: -9.78926932204

number of times this bracket happened: 9


MOST COMMON BRACKET FOR REGION east
Villanova (1)                                                
Lafayette (16)            Vil (1)                            
North Carolina St. (8)                                       
LSU (9)                   LSU (9)  Vil (1)                   
Northern Iowa (5)                                            
Wyoming (12)              Nor (5)                            
Louisville (4)                                               
UC Irvine (13)            Lou (4)  Lou (4)  Vil (1)          
Providence (6)            Day (11) Okl (3)  Vir (2)  Vir (2) 
Dayton (11)                                                  
Oklahoma (3)              Okl (3)                            
Albany (14)                                                  
Michigan St. (7)          Geo (10) Vir (2)                   
Georgia (10)                                                 
Virginia (2)              Vir (2)                            
Belmont (15)                                                 
Total bracket energy: -10.5204279257

number of times this bracket happened: 11


MOST COMMON BRACKET FOR FINAL FOUR
Kentucky (1)                               
Wisconsin (1)             Ken (1)          
Utah (5)                  Uta (5)  Ken (1) 
Virginia (2)                               
Total bracket energy: -1.78538460124

number of times this bracket happened: 176

So, not looking so hot for my Kansas, but the code is working.

Let's visualize the results, then make a table of results, as per 538.

In [10]:
# Basic visualization
for region in 'midwest west east south'.split():
    MMMC.showstats(results[region],description=region,newfig=True)

Here you can see the classic reason to do Monte Carlo samping in the first place: we're absolutely nowhere near fully sampling bracket space. You can tell this from each of the "Unique brackets over the trajectory" plots, none of which have leveled out.

Further, you can see that the strength distribution in each of the regions is pretty different. Check out the energy distribution histograms for visual proof.

Nice tables

And here's our set of tabulated results. Note that things look a little funny for the Final Four: runbracket2 runs the final four separate from the rest of the tourney. So, only four teams are allowed to have Championship and Win percentages above zero (the final four percentages are taken from the first chunk of the tourney).

In [11]:
h = HTML(MMMC.maketable(results))
h
Out[11]:
TeamRegionRank2nd Round3rd RoundSweet 16Elite 8Final 4ChampionshipWin
Kentuckymidwest1100.065.7449.1836.1625.2955.334.5
Wisconsinwest1100.063.3844.2830.0419.4444.724.2
Virginiaeast2100.064.641.1527.6817.8651.322.4
Utahsouth5100.058.2935.8620.9612.1948.718.9
Arizonawest2100.062.3542.2328.6418.740.00.0
Villanovaeast1100.065.7344.0529.8418.610.00.0
Dukesouth1100.066.0341.6425.215.050.00.0
Gonzagasouth2100.061.6737.1223.5114.220.00.0
Kansasmidwest2100.058.633.7119.1610.310.00.0
Oklahomaeast3100.060.7434.9618.3410.010.00.0
Northern Iowaeast5100.065.2337.5819.729.970.00.0
Notre Damemidwest3100.057.3732.4718.579.650.00.0
Iowa St.south3100.057.0133.2217.329.070.00.0
Baylorwest3100.056.333.2316.778.790.00.0
North Carolinawest4100.061.1535.6317.738.70.00.0
SMUsouth6100.053.228.1614.617.620.00.0
Wichita St.midwest7100.051.5928.3115.417.540.00.0
Georgetownsouth4100.060.9928.7415.087.370.00.0
Michigan St.east7100.055.1725.7314.437.170.00.0
Iowasouth7100.051.1525.9913.766.630.00.0
Louisvilleeast4100.056.6229.314.056.580.00.0
West Virginiamidwest5100.055.7731.5413.36.470.00.0
Providenceeast6100.053.0327.312.586.190.00.0
Butlermidwest6100.053.6127.0313.436.050.00.0
Texasmidwest11100.046.3923.912.465.990.00.0
Xavierwest6100.050.7125.6812.465.950.00.0
Ohio St.west10100.051.6222.2611.195.290.00.0
Arkansaswest5100.057.6728.2211.835.140.00.0
Marylandmidwest4100.055.2525.8411.735.140.00.0
VCUwest7100.048.3821.7811.245.060.00.0
Oklahoma St.west9100.050.1921.5811.314.840.00.0
San Diego St.south8100.047.9223.0410.714.810.00.0
Oregonwest8100.049.8120.6110.424.730.00.0
Cincinnatimidwest8100.049.7419.419.934.720.00.0
Davidsonsouth10100.048.8523.4610.74.540.00.0
LSUeast9100.053.3124.2511.584.530.00.0
North Carolina St.east8100.046.6921.9310.184.350.00.0
Stephen F. Austinsouth12100.041.7121.319.084.30.00.0
UCLAsouth11100.046.821.719.514.220.00.0
St. John'ssouth9100.052.0822.839.844.170.00.0
Purduemidwest9100.050.2619.418.863.760.00.0
Buffalomidwest12100.044.2323.138.763.550.00.0
Georgiaeast10100.044.8319.418.763.530.00.0
Daytoneast11100.046.9722.598.553.520.00.0
Mississippiwest11100.049.2921.459.013.510.00.0
Indianamidwest10100.048.4122.298.573.140.00.0
Valparaisomidwest13100.044.7519.497.863.10.00.0
Georgia St.west14100.043.719.646.962.670.00.0
Harvardwest13100.038.8518.656.982.360.00.0
Woffordwest12100.042.3317.56.842.330.00.0
New Mexico St.midwest15100.041.415.696.32.260.00.0
UC Irvineeast13100.043.3819.576.642.170.00.0
Northeasternmidwest14100.042.6316.66.12.170.00.0
UABsouth14100.042.9916.916.092.020.00.0
Wyomingeast12100.034.7713.555.061.80.00.0
Albanyeast14100.039.2615.154.861.590.00.0
Eastern Washingtonsouth13100.039.0114.095.061.420.00.0
Coastal Carolinawest16100.036.6213.534.851.420.00.0
North Dakota St.south15100.038.3313.434.51.350.00.0
Belmonteast15100.035.413.714.81.280.00.0
Texas Southernwest15100.037.6513.733.731.030.00.0
Robert Morrissouth16100.033.9712.494.071.020.00.0
Hamptonmidwest16100.034.2612.03.40.860.00.0
Lafayetteeast16100.034.279.772.930.840.00.0

Given those concerns, let's just run runbracket1 and look at the results

In [12]:
results = MMMC.runbracket1(ntrials=10000,T=1.5)
Lowest energy bracket
Kentucky (1)                                                                   
Hampton (16)              Ken (1)                                              
Cincinnati (8)                                                                 
Purdue (9)                Cin (8)  Ken (1)                                     
West Virginia (5)                                                              
Buffalo (12)              Wes (5)                                              
Maryland (4)                                                                   
Valparaiso (13)           Mar (4)  Wes (5)  Ken (1)                            
Butler (6)                                                                     
Texas (11)                Tex (11)                                             
Notre Dame (3)                                                                 
Northeastern (14)         Not (3)  Not (3)                                     
Wichita St. (7)                                                                
Indiana (10)              Wic (7)                                              
Kansas (2)                                                                     
New Mexico St. (15)       Kan (2)  Kan (2)  Not (3)  Ken (1)                   
Duke (1)                                                                       
Robert Morris (16)        Duk (1)                                              
San Diego St. (8)                                                              
St. John's (9)            San (8)  Duk (1)                                     
Utah (5)                                                                       
Stephen F. Austin (12)    Uta (5)                                              
Georgetown (4)                                                                 
Eastern Washington (13)   Geo (4)  Uta (5)  Duk (1)                            
SMU (6)                                                                        
UCLA (11)                 SMU (6)                                              
Iowa St. (3)                                                                   
UAB (14)                  Iow (3)  Iow (3)                                     
Iowa (7)                                                                       
Davidson (10)             Iow (7)                                              
Gonzaga (2)                                                                    
North Dakota St. (15)     Gon (2)  Gon (2)  Gon (2)  Gon (2)  Ken (1)          
Wisconsin (1)             Wis (1)  Wis (1)  Wis (1)  Ari (2)  Ari (2)  Ken (1) 
Coastal Carolina (16)                                                          
Oregon (8)                Okl (9)                                              
Oklahoma St. (9)                                                               
Arkansas (5)              Ark (5)  Nor (4)                                     
Wofford (12)                                                                   
North Carolina (4)        Nor (4)                                              
Harvard (13)                                                                   
Xavier (6)                Xav (6)  Bay (3)  Ari (2)                            
Mississippi (11)                                                               
Baylor (3)                Bay (3)                                              
Georgia St. (14)                                                               
VCU (7)                   Ohi (10) Ari (2)                                     
Ohio St. (10)                                                                  
Arizona (2)               Ari (2)                                              
Texas Southern (15)                                                            
Villanova (1)             Vil (1)  Vil (1)  Vil (1)  Vir (2)                   
Lafayette (16)                                                                 
North Carolina St. (8)    Nor (8)                                              
LSU (9)                                                                        
Northern Iowa (5)         Nor (5)  Nor (5)                                     
Wyoming (12)                                                                   
Louisville (4)            Lou (4)                                              
UC Irvine (13)                                                                 
Providence (6)            Pro (6)  Okl (3)  Vir (2)                            
Dayton (11)                                                                    
Oklahoma (3)              Okl (3)                                              
Albany (14)                                                                    
Michigan St. (7)          Mic (7)  Vir (2)                                     
Georgia (10)                                                                   
Virginia (2)              Vir (2)                                              
Belmont (15)                                                                   
Total bracket energy: -44.697443432

Most common bracket (7)
Kentucky (1)                                                                   
Hampton (16)              Ham (16)                                             
Cincinnati (8)                                                                 
Purdue (9)                Cin (8)  Cin (8)                                     
West Virginia (5)                                                              
Buffalo (12)              Wes (5)                                              
Maryland (4)                                                                   
Valparaiso (13)           Mar (4)  Wes (5)  Cin (8)                            
Butler (6)                                                                     
Texas (11)                But (6)                                              
Notre Dame (3)                                                                 
Northeastern (14)         Nor (14) But (6)                                     
Wichita St. (7)                                                                
Indiana (10)              Wic (7)                                              
Kansas (2)                                                                     
New Mexico St. (15)       Kan (2)  Kan (2)  But (6)  But (6)                   
Duke (1)                                                                       
Robert Morris (16)        Rob (16)                                             
San Diego St. (8)                                                              
St. John's (9)            San (8)  San (8)                                     
Utah (5)                                                                       
Stephen F. Austin (12)    Uta (5)                                              
Georgetown (4)                                                                 
Eastern Washington (13)   Geo (4)  Geo (4)  Geo (4)                            
SMU (6)                                                                        
UCLA (11)                 SMU (6)                                              
Iowa St. (3)                                                                   
UAB (14)                  Iow (3)  Iow (3)                                     
Iowa (7)                                                                       
Davidson (10)             Iow (7)                                              
Gonzaga (2)                                                                    
North Dakota St. (15)     Gon (2)  Gon (2)  Gon (2)  Gon (2)  Gon (2)          
Wisconsin (1)             Wis (1)  Ore (8)  Ore (8)  Ari (2)  Ari (2)  Ari (2) 
Coastal Carolina (16)                                                          
Oregon (8)                Ore (8)                                              
Oklahoma St. (9)                                                               
Arkansas (5)              Ark (5)  Nor (4)                                     
Wofford (12)                                                                   
North Carolina (4)        Nor (4)                                              
Harvard (13)                                                                   
Xavier (6)                Xav (6)  Xav (6)  Ari (2)                            
Mississippi (11)                                                               
Baylor (3)                Bay (3)                                              
Georgia St. (14)                                                               
VCU (7)                   Ohi (10) Ari (2)                                     
Ohio St. (10)                                                                  
Arizona (2)               Ari (2)                                              
Texas Southern (15)                                                            
Villanova (1)             Laf (16) Nor (8)  Nor (5)  Mic (7)                   
Lafayette (16)                                                                 
North Carolina St. (8)    Nor (8)                                              
LSU (9)                                                                        
Northern Iowa (5)         Nor (5)  Nor (5)                                     
Wyoming (12)                                                                   
Louisville (4)            UC  (13)                                             
UC Irvine (13)                                                                 
Providence (6)            Pro (6)  Pro (6)  Mic (7)                            
Dayton (11)                                                                    
Oklahoma (3)              Okl (3)                                              
Albany (14)                                                                    
Michigan St. (7)          Mic (7)  Mic (7)                                     
Georgia (10)                                                                   
Virginia (2)              Bel (15)                                             
Belmont (15)                                                                   
Total bracket energy: -38.100050778

In [13]:
h = HTML(MMMC.maketable(results))
h
Out[13]:
TeamRegionRank2nd Round3rd RoundSweet 16Elite 8Final 4ChampionshipWin
Kentuckymidwest1100.058.6944.7732.5823.9816.4110.87
Villanovaeast1100.065.5345.7132.020.8713.778.67
Arizonawest2100.062.5744.5933.5420.7513.118.03
Wisconsinwest1100.067.6743.0227.4218.1211.357.15
Virginiaeast2100.063.7643.6730.8619.0511.086.59
Gonzagasouth2100.057.9839.9525.4615.029.094.78
Utahsouth5100.057.9234.421.0413.196.83.66
Dukesouth1100.060.135.4518.4811.416.733.49
Notre Damemidwest3100.061.1233.9319.411.175.572.8
Oklahomaeast3100.062.037.7417.6410.015.262.64
Kansasmidwest2100.066.5735.8119.029.975.452.59
Northern Iowaeast5100.062.2735.1118.6710.054.822.38
Iowa St.south3100.060.0636.9520.0411.125.242.36
Wichita St.midwest7100.056.9431.9119.068.764.182.17
North Carolinawest4100.058.3532.318.519.544.231.82
SMUsouth6100.055.3529.2616.918.613.791.61
Baylorwest3100.056.6329.5111.827.123.631.56
Georgetownsouth4100.056.7529.5815.757.233.241.42
Texasmidwest11100.058.2827.8914.86.873.31.39
Michigan St.east7100.059.6727.4314.516.412.981.29
Ohio St.west10100.050.423.812.616.463.191.27
West Virginiamidwest5100.058.6633.4113.826.622.971.17
Arkansaswest5100.057.6631.1612.715.342.381.16
Louisvilleeast4100.055.4931.4915.287.183.11.14
Iowasouth7100.055.6825.069.925.492.671.13
Butlermidwest6100.041.7224.0611.136.362.771.12
Xavierwest6100.056.4331.3614.276.712.441.12
San Diego St.south8100.052.1529.1712.836.642.881.03
Cincinnatimidwest8100.050.5820.3612.285.352.380.9
Davidsonsouth10100.044.3215.666.983.121.690.73
VCUwest7100.049.619.038.634.281.810.71
Marylandmidwest4100.050.8722.229.443.61.860.7
Oregonwest8100.058.4124.8910.744.781.740.66
Stephen F. Austinsouth12100.042.0823.611.544.511.720.63
St. John'ssouth9100.047.8518.829.513.971.830.62
Daytoneast11100.048.8121.648.964.311.790.58
Mississippiwest11100.043.5721.868.383.01.410.55
Purduemidwest9100.049.4220.379.73.311.330.53
Buffalomidwest12100.041.3421.687.932.771.190.52
Valparaisomidwest13100.049.1322.699.344.121.490.51
Providenceeast6100.051.1926.6811.184.281.40.48
LSUeast9100.048.8115.797.112.580.920.47
Georgiaeast10100.040.3315.127.582.951.30.46
Oklahoma St.west9100.041.5918.789.243.351.10.45
Woffordwest12100.042.3416.577.372.630.940.44
Indianamidwest10100.043.0618.988.463.721.20.43
UCLAsouth11100.044.6521.48.222.721.260.42
North Carolina St.east8100.051.1922.318.993.551.450.4
Harvardwest13100.041.6519.978.532.490.80.35
UC Irvineeast13100.044.5120.527.192.440.970.26
Coastal Carolinawest16100.032.3313.315.482.240.570.24
Georgia St.west14100.043.3717.276.041.920.470.21
UABsouth14100.039.9412.394.941.570.730.17
Eastern Washingtonsouth13100.043.2512.423.881.270.550.17
Lafayetteeast16100.034.4716.197.112.280.50.15
Wyomingeast12100.037.7312.883.651.120.40.15
Albanyeast14100.038.013.944.571.840.530.11
Robert Morrissouth16100.039.916.566.972.390.50.11
Belmonteast15100.036.2413.784.71.080.310.11
Texas Southernwest15100.037.4312.584.711.270.250.11
Northeasternmidwest14100.038.8814.124.280.990.290.09
Hamptonmidwest16100.041.3114.54.911.250.250.07
North Dakota St.south15100.042.0219.337.531.740.330.05
New Mexico St.midwest15100.033.4313.33.851.160.310.05

That is, indeed, high temperature! Let's try it with a bunch more runs

In [14]:
results = MMMC.runbracket1(ntrials=100000,T=1.5)
Lowest energy bracket
Kentucky (1)                                                                   
Hampton (16)              Ken (1)                                              
Cincinnati (8)                                                                 
Purdue (9)                Cin (8)  Ken (1)                                     
West Virginia (5)                                                              
Buffalo (12)              Wes (5)                                              
Maryland (4)                                                                   
Valparaiso (13)           Mar (4)  Wes (5)  Ken (1)                            
Butler (6)                                                                     
Texas (11)                Tex (11)                                             
Notre Dame (3)                                                                 
Northeastern (14)         Not (3)  Not (3)                                     
Wichita St. (7)                                                                
Indiana (10)              Wic (7)                                              
Kansas (2)                                                                     
New Mexico St. (15)       Kan (2)  Kan (2)  Not (3)  Ken (1)                   
Duke (1)                                                                       
Robert Morris (16)        Duk (1)                                              
San Diego St. (8)                                                              
St. John's (9)            San (8)  Duk (1)                                     
Utah (5)                                                                       
Stephen F. Austin (12)    Uta (5)                                              
Georgetown (4)                                                                 
Eastern Washington (13)   Geo (4)  Uta (5)  Duk (1)                            
SMU (6)                                                                        
UCLA (11)                 SMU (6)                                              
Iowa St. (3)                                                                   
UAB (14)                  Iow (3)  Iow (3)                                     
Iowa (7)                                                                       
Davidson (10)             Iow (7)                                              
Gonzaga (2)                                                                    
North Dakota St. (15)     Gon (2)  Gon (2)  Gon (2)  Gon (2)  Ken (1)          
Wisconsin (1)             Wis (1)  Wis (1)  Wis (1)  Ari (2)  Ari (2)  Ken (1) 
Coastal Carolina (16)                                                          
Oregon (8)                Okl (9)                                              
Oklahoma St. (9)                                                               
Arkansas (5)              Ark (5)  Nor (4)                                     
Wofford (12)                                                                   
North Carolina (4)        Nor (4)                                              
Harvard (13)                                                                   
Xavier (6)                Xav (6)  Bay (3)  Ari (2)                            
Mississippi (11)                                                               
Baylor (3)                Bay (3)                                              
Georgia St. (14)                                                               
VCU (7)                   Ohi (10) Ari (2)                                     
Ohio St. (10)                                                                  
Arizona (2)               Ari (2)                                              
Texas Southern (15)                                                            
Villanova (1)             Vil (1)  Vil (1)  Vil (1)  Vir (2)                   
Lafayette (16)                                                                 
North Carolina St. (8)    Nor (8)                                              
LSU (9)                                                                        
Northern Iowa (5)         Nor (5)  Nor (5)                                     
Wyoming (12)                                                                   
Louisville (4)            Lou (4)                                              
UC Irvine (13)                                                                 
Providence (6)            Pro (6)  Okl (3)  Vir (2)                            
Dayton (11)                                                                    
Oklahoma (3)              Okl (3)                                              
Albany (14)                                                                    
Michigan St. (7)          Mic (7)  Vir (2)                                     
Georgia (10)                                                                   
Virginia (2)              Vir (2)                                              
Belmont (15)                                                                   
Total bracket energy: -44.697443432

Most common bracket (9)
Kentucky (1)                                                                   
Hampton (16)              Ken (1)                                              
Cincinnati (8)                                                                 
Purdue (9)                Cin (8)  Ken (1)                                     
West Virginia (5)                                                              
Buffalo (12)              Buf (12)                                             
Maryland (4)                                                                   
Valparaiso (13)           Val (13) Buf (12) Ken (1)                            
Butler (6)                                                                     
Texas (11)                Tex (11)                                             
Notre Dame (3)                                                                 
Northeastern (14)         Nor (14) Nor (14)                                    
Wichita St. (7)                                                                
Indiana (10)              Wic (7)                                              
Kansas (2)                                                                     
New Mexico St. (15)       Kan (2)  Wic (7)  Wic (7)  Ken (1)                   
Duke (1)                                                                       
Robert Morris (16)        Rob (16)                                             
San Diego St. (8)                                                              
St. John's (9)            St. (9)  St. (9)                                     
Utah (5)                                                                       
Stephen F. Austin (12)    Ste (12)                                             
Georgetown (4)                                                                 
Eastern Washington (13)   Eas (13) Eas (13) St. (9)                            
SMU (6)                                                                        
UCLA (11)                 SMU (6)                                              
Iowa St. (3)                                                                   
UAB (14)                  Iow (3)  Iow (3)                                     
Iowa (7)                                                                       
Davidson (10)             Dav (10)                                             
Gonzaga (2)                                                                    
North Dakota St. (15)     Nor (15) Dav (10) Iow (3)  Iow (3)  Ken (1)          
Wisconsin (1)             Wis (1)  Wis (1)  Ark (5)  Ark (5)  Vir (2)  Vir (2) 
Coastal Carolina (16)                                                          
Oregon (8)                Okl (9)                                              
Oklahoma St. (9)                                                               
Arkansas (5)              Ark (5)  Ark (5)                                     
Wofford (12)                                                                   
North Carolina (4)        Nor (4)                                              
Harvard (13)                                                                   
Xavier (6)                Xav (6)  Bay (3)  Bay (3)                            
Mississippi (11)                                                               
Baylor (3)                Bay (3)                                              
Georgia St. (14)                                                               
VCU (7)                   Ohi (10) Ohi (10)                                    
Ohio St. (10)                                                                  
Arizona (2)               Ari (2)                                              
Texas Southern (15)                                                            
Villanova (1)             Vil (1)  Vil (1)  Lou (4)  Vir (2)                   
Lafayette (16)                                                                 
North Carolina St. (8)    LSU (9)                                              
LSU (9)                                                                        
Northern Iowa (5)         Nor (5)  Lou (4)                                     
Wyoming (12)                                                                   
Louisville (4)            Lou (4)                                              
UC Irvine (13)                                                                 
Providence (6)            Day (11) Alb (14) Vir (2)                            
Dayton (11)                                                                    
Oklahoma (3)              Alb (14)                                             
Albany (14)                                                                    
Michigan St. (7)          Mic (7)  Vir (2)                                     
Georgia (10)                                                                   
Virginia (2)              Vir (2)                                              
Belmont (15)                                                                   
Total bracket energy: -37.1483683417

In [15]:
h = HTML(MMMC.maketable(results))
h
Out[15]:
TeamRegionRank2nd Round3rd RoundSweet 16Elite 8Final 4ChampionshipWin
Kentuckymidwest1100.067.84849.18936.44426.7918.94912.828
Arizonawest2100.064.11442.62829.24818.83812.2567.805
Wisconsinwest1100.063.36842.14628.13117.70511.0836.862
Villanovaeast1100.064.31443.81428.61817.42510.646.365
Virginiaeast2100.062.18939.52226.28517.03810.3216.183
Gonzagasouth2100.061.67238.30524.1714.4178.1494.538
Dukesouth1100.064.40740.26324.7514.9278.0614.37
Oklahomaeast3100.062.25738.00520.22711.5645.9063.04
Utahsouth5100.056.18834.29519.46910.8465.5762.832
Notre Damemidwest3100.060.69233.50418.749.6655.0612.473
Kansasmidwest2100.059.73233.55318.6829.0984.8342.329
Northern Iowaeast5100.058.92834.0617.5099.3024.6042.239
North Carolinawest4100.061.14836.85219.0869.5354.6822.223
Iowa St.south3100.059.58133.40518.1319.5624.6472.206
Baylorwest3100.058.59934.54916.9699.1774.632.202
Wichita St.midwest7100.056.4531.00517.0658.4544.3782.104
Louisvilleeast4100.056.52530.18815.3316.8893.1581.413
Texasmidwest11100.052.78328.18414.6446.6043.1151.372
SMUsouth6100.054.3729.06814.4896.7893.0971.361
Georgetownsouth4100.058.91228.23814.086.9153.0151.311
Michigan St.east7100.055.47725.46712.9986.3722.9511.292
Ohio St.west10100.050.123.61712.1585.8132.8251.18
West Virginiamidwest5100.052.50728.24112.3655.8292.8091.09
Butlermidwest6100.047.21724.42712.4495.5512.471.088
Iowasouth7100.051.02324.91612.8426.022.6411.084
Arkansaswest5100.058.7128.68313.0465.7122.6191.074
San Diego St.south8100.052.82125.26212.2815.7212.5851.026
Xavierwest6100.052.83326.25211.2545.4242.3180.966
VCUwest7100.049.922.65511.0345.3222.2720.915
Davidsonsouth10100.048.97723.74611.6545.3932.2590.887
Marylandmidwest4100.054.29327.84110.9924.692.1240.852
Cincinnatimidwest8100.049.48121.06410.8784.9772.1370.809
Providenceeast6100.050.5223.83910.3794.861.9810.778
North Carolina St.east8100.052.3222.88711.354.8621.8180.717
Oregonwest8100.050.89222.5810.9564.3221.8440.7
St. John'ssouth9100.047.17922.96210.6524.6911.9040.687
Stephen F. Austinsouth12100.043.81222.6669.8374.5511.8590.674
Oklahoma St.west9100.049.10821.69710.9654.4841.7360.666
Georgiaeast10100.044.52321.64710.2374.5231.7230.65
Daytoneast11100.049.4822.9229.9374.0781.6090.594
LSUeast9100.047.6820.729.643.9611.5950.584
UCLAsouth11100.045.6322.2649.2853.9211.5480.559
Mississippiwest11100.047.16720.5228.9753.6841.450.53
Buffalomidwest12100.047.49323.2178.8163.6471.5190.525
Purduemidwest9100.050.51919.5489.3893.9261.5130.503
Indianamidwest10100.043.5519.4878.323.4271.30.446
Valparaisomidwest13100.045.70720.7018.1063.2251.2360.43
Georgia St.west14100.041.40118.6776.872.7880.940.321
Harvardwest13100.038.85217.9127.0322.360.8720.269
UC Irvineeast13100.043.47518.6357.2122.3730.6990.232
Woffordwest12100.041.2916.5535.9622.1690.6860.214
Wyomingeast12100.041.07217.1176.212.1540.6970.194
New Mexico St.midwest15100.040.26815.9555.4281.9080.6040.167
UABsouth14100.040.41915.2634.7571.6490.5450.153
Northeasternmidwest14100.039.30813.8854.6721.410.4790.145
Belmonteast15100.037.81113.3644.8841.7320.5340.144
Albanyeast14100.037.74315.2345.0531.6020.4650.14
Eastern Washingtonsouth13100.041.08814.8015.2691.8610.5440.139
Coastal Carolinawest16100.036.63213.5774.8221.7070.4920.126
North Dakota St.south15100.038.32813.0334.6721.6020.4780.121
Lafayetteeast16100.035.68612.5794.131.2650.310.078
Robert Morrissouth16100.035.59311.5133.6621.1350.330.073
Texas Southernwest15100.035.88611.13.4920.960.2840.066
Hamptonmidwest16100.032.15210.1993.010.7990.2340.056
In [17]:
MMMC.showstats(results['all'],description='full run',newfig=True)

Not bad! (Also, note the shape of the energy distribution, and the fact taht the "Unique brackets" group is still basically linear!)

Who wins?

But let's be honest for a minute. We all know Kansas is going to win. What do the brackets where that happened look like?

In [18]:
goodbrackets = [i for i in results['all'].brackets if i.bracket[-1][0] == 'Kansas']
In [19]:
from MarchMadnessMonteCarlo.Brackets import Stats
lb, mcb, mcb_count, unique_brackets, lowest_sightings = Stats.gather_uniquestats(goodbrackets)
sr = MMMC.SimulationResults(goodbrackets,unique_brackets,lb,lowest_sightings,mcb,mcb_count)
trueresults = {'all':sr}
In [20]:
h = HTML(MMMC.maketable(trueresults))
h
Out[20]:
TeamRegionRank2nd Round3rd RoundSweet 16Elite 8Final 4ChampionshipWin
Kansasmidwest2100.0100.0100.0100.0100.0100.0100.0
Virginiaeast2100.061.74323744139.759553456425.762129669417.13181623019.016745384290.0
Villanovaeast1100.068.0549592147.831687419530.828681837717.38943752688.716187204810.0
Wisconsinwest1100.062.000858737739.501932159724.903392013714.21210820098.24388149420.0
Oklahomaeast3100.063.804207814542.722198368422.413052812413.09574924867.77157578360.0
Arizonawest2100.062.902533276137.569772434524.431086303114.64147702887.728638900820.0
Northern Iowaeast5100.059.553456419137.140403606718.376985830810.51953628175.452984113350.0
Baylorwest3100.055.345641906430.914555603315.54315156729.059682267074.894804637180.0
North Carolinawest4100.058.866466294535.422928295419.3215972529.617861743244.85186775440.0
Michigan St.east7100.057.492486045526.492056676712.79519106916.268784886223.477887505370.0
Louisvilleeast4100.058.308286818429.240017174814.12623443546.826964362393.306139974240.0
Xavierwest6100.050.150279089725.161013310411.97939029637.299270072993.177329325890.0
Oregonwest8100.052.211249463322.455989695112.27994847575.281236582222.91970802920.0
Ohio St.west10100.050.49377415226.835551738913.65392872485.538857878922.790897380850.0
Arkansaswest5100.060.326320309128.982395878111.89351653075.882352941182.705023615290.0
VCUwest7100.049.50622584823.572348647512.10820094465.839416058392.533276084160.0
Providenceeast6100.051.180764276521.42550450849.446114212114.465435809362.447402318590.0
North Carolina St.east8100.055.388578789224.688707599813.0098754834.85186775442.146844139120.0
Mississippiwest11100.049.849720910324.688707599810.94890510954.765993988841.93215972520.0
Daytoneast11100.048.819235723520.00858737669.145556032634.036066981541.93215972520.0
Oklahoma St.west9100.047.788750536722.069557750111.55002146844.207814512671.717475311290.0
Georgia St.west14100.044.654358093619.23572348657.642765135253.821382567631.717475311290.0
Georgiaeast10100.042.507513954520.60970373559.403177329333.606698153711.631601545730.0
Harvardwest13100.041.133533705520.05152425938.415629025333.349076857021.588664662950.0
Woffordwest12100.039.673679690915.54315156725.882352941182.91970802921.373980249030.0
LSUeast9100.044.611421210818.37698583088.759124087593.692571919281.331043366250.0
Belmonteast15100.038.25676255913.13868613146.655216831262.103907256331.073422069560.0
Coastal Carolinawest16100.037.999141262315.9725203955.753542292832.361528553030.9016745384290.0
Wyomingeast12100.040.446543580917.17475311295.58179476171.717475311290.6869901245170.0
UC Irvineeast13100.041.691713181616.44482610565.667668527261.631601545730.5152425933880.0
Texas Southernwest15100.037.097466723912.0223271793.692571919281.20223271790.5152425933880.0
Lafayetteeast16100.031.945040799.102619149853.64963503651.159295835120.4723057106050.0
Albanyeast14100.036.195792185515.84370974674.37956204381.502790897380.4293688278230.0
Dukesouth1100.061.829111206540.145985401522.112494632913.56805495920.00.0
Gonzagasouth2100.055.517389437535.036496350421.468441391210.04723057110.00.0
Utahsouth5100.054.873336195830.18462859615.88664662959.70373550880.00.0
Iowa St.south3100.059.16702447432.54615714917.99055388589.360240446540.00.0
Georgetownsouth4100.058.78059252930.18462859616.10133104348.544439673680.00.0
St. John'ssouth9100.049.033920137423.701159295813.78273937316.869901245170.00.0
Stephen F. Austinsouth12100.045.126663804224.903392013710.2619149856.397595534560.00.0
SMUsouth6100.054.615714899127.651352511813.86861313876.354658651780.00.0
Davidsonsouth10100.048.604551309624.302275654812.0223271795.58179476170.00.0
San Diego St.south8100.050.966079862622.670674109112.27994847575.495920996140.00.0
Iowasouth7100.051.395448690424.474023185912.53756977245.452984113350.00.0
UCLAsouth11100.045.384285100923.100042936911.16358952345.066552168310.00.0
Eastern Washingtonsouth13100.041.21940747114.72735079435.882352941182.490339201370.00.0
North Dakota St.south15100.044.482610562516.18720480896.182911120652.060970373550.00.0
UABsouth14100.040.83297552616.70244740234.765993988841.846285959640.00.0
Robert Morrissouth16100.038.170888793513.48218119363.692571919281.159295835120.00.0
Kentuckymidwest1100.061.74323744139.630742808121.81193645340.00.00.0
Marylandmidwest4100.059.424645770731.215113782716.31601545730.00.00.0
Purduemidwest9100.055.732073851427.479604980713.39630742810.00.00.0
Buffalomidwest12100.047.745813653924.431086303112.27994847570.00.00.0
West Virginiamidwest5100.052.254186346123.744096178611.80764276510.00.00.0
Valparaisomidwest13100.040.575354229320.60970373559.96135680550.00.00.0
Cincinnatimidwest8100.044.267926148620.52382996999.96135680550.00.00.0
Hamptonmidwest16100.038.25676255912.36582224134.465435809360.00.00.0
Texasmidwest11100.051.567196221630.91455560330.00.00.00.0
Notre Damemidwest3100.058.480034349530.22756547870.00.00.00.0
Butlermidwest6100.048.432803778423.01416917130.00.00.00.0
Northeasternmidwest14100.041.519965650515.84370974670.00.00.00.0
Wichita St.midwest7100.055.21683125810.00.00.00.00.0
Indianamidwest10100.044.78316874190.00.00.00.00.0
New Mexico St.midwest15100.00.00.00.00.00.00.0
In [21]:
sr.most_common_bracket
Out[21]:
Kentucky (1)                                                                   
Hampton (16)              Ham (16)                                             
Cincinnati (8)                                                                 
Purdue (9)                Pur (9)  Pur (9)                                     
West Virginia (5)                                                              
Buffalo (12)              Buf (12)                                             
Maryland (4)                                                                   
Valparaiso (13)           Val (13) Buf (12) Pur (9)                            
Butler (6)                                                                     
Texas (11)                Tex (11)                                             
Notre Dame (3)                                                                 
Northeastern (14)         Not (3)  Not (3)                                     
Wichita St. (7)                                                                
Indiana (10)              Ind (10)                                             
Kansas (2)                                                                     
New Mexico St. (15)       Kan (2)  Kan (2)  Kan (2)  Kan (2)                   
Duke (1)                                                                       
Robert Morris (16)        Duk (1)                                              
San Diego St. (8)                                                              
St. John's (9)            St. (9)  Duk (1)                                     
Utah (5)                                                                       
Stephen F. Austin (12)    Ste (12)                                             
Georgetown (4)                                                                 
Eastern Washington (13)   Geo (4)  Ste (12) Ste (12)                           
SMU (6)                                                                        
UCLA (11)                 SMU (6)                                              
Iowa St. (3)                                                                   
UAB (14)                  Iow (3)  SMU (6)                                     
Iowa (7)                                                                       
Davidson (10)             Iow (7)                                              
Gonzaga (2)                                                                    
North Dakota St. (15)     Gon (2)  Gon (2)  Gon (2)  Ste (12) Kan (2)          
Wisconsin (1)             Wis (1)  Okl (9)  Wof (12) Wof (12) Okl (3)  Kan (2) 
Coastal Carolina (16)                                                          
Oregon (8)                Okl (9)                                              
Oklahoma St. (9)                                                               
Arkansas (5)              Wof (12) Wof (12)                                    
Wofford (12)                                                                   
North Carolina (4)        Har (13)                                             
Harvard (13)                                                                   
Xavier (6)                Xav (6)  Bay (3)  Ari (2)                            
Mississippi (11)                                                               
Baylor (3)                Bay (3)                                              
Georgia St. (14)                                                               
VCU (7)                   Ohi (10) Ari (2)                                     
Ohio St. (10)                                                                  
Arizona (2)               Ari (2)                                              
Texas Southern (15)                                                            
Villanova (1)             Laf (16) Nor (8)  Nor (8)  Okl (3)                   
Lafayette (16)                                                                 
North Carolina St. (8)    Nor (8)                                              
LSU (9)                                                                        
Northern Iowa (5)         Wyo (12) Lou (4)                                     
Wyoming (12)                                                                   
Louisville (4)            Lou (4)                                              
UC Irvine (13)                                                                 
Providence (6)            Pro (6)  Okl (3)  Okl (3)                            
Dayton (11)                                                                    
Oklahoma (3)              Okl (3)                                              
Albany (14)                                                                    
Michigan St. (7)          Mic (7)  Mic (7)                                     
Georgia (10)                                                                   
Virginia (2)              Vir (2)                                              
Belmont (15)                                                                   
Total bracket energy: -35.9796902956
In [22]:
sr.most_common_bracket_count
Out[22]:
4

Huh. Well, that's not exactly my pick for best bracket, but there you have it.

Excersizes for the reader:

  • make a better energy function, using maybe a weighted average of different rankings. I slurped in KenPom and Jeff Sagarin, but you could add your own.
  • come up with a better "hometown wins" version. E.g. explicitly check for KU, and tweak the rankings.
In [46]:
from MarchMadnessMonteCarlo import RankingsAndStrength as RAS
strength = RAS.kenpom['Pyth']
jsstrength = RAS.sagarin['Rating']

def weighted_KU_energy_game(winner, loser):
    if winner == 'Kansas':
        win_pct = 0.99
    elif loser == 'Kansas':
        win_pct = 0.01
    else:
        A,B = strength[winner],strength[loser]
        # see http://207.56.97.150/articles/playoff2002.htm
        kenpom = (A-A*B)/(A+B-2*A*B)
        A,B = jsstrength[winner]/100, jsstrength[loser]/100
        A,B = min(A,0.9999),min(B,0.9999)
        sagarin = (A-A*B)/(A+B-2*A*B)
        win_pct = 0.70*kenpom + 0.30*sagarin
    return -win_pct
In [48]:
MMMC.set_energy_function(weighted_KU_energy_game)
In [55]:
results = MMMC.runbracket1(ntrials=100000,T=1.5)
Lowest energy bracket
Kentucky (1)                                                                   
Hampton (16)              Ken (1)                                              
Cincinnati (8)                                                                 
Purdue (9)                Cin (8)  Ken (1)                                     
West Virginia (5)                                                              
Buffalo (12)              Wes (5)                                              
Maryland (4)                                                                   
Valparaiso (13)           Mar (4)  Wes (5)  Ken (1)                            
Butler (6)                                                                     
Texas (11)                Tex (11)                                             
Notre Dame (3)                                                                 
Northeastern (14)         Not (3)  Not (3)                                     
Wichita St. (7)                                                                
Indiana (10)              Wic (7)                                              
Kansas (2)                                                                     
New Mexico St. (15)       Kan (2)  Kan (2)  Kan (2)  Kan (2)                   
Duke (1)                                                                       
Robert Morris (16)        Duk (1)                                              
San Diego St. (8)                                                              
St. John's (9)            San (8)  Duk (1)                                     
Utah (5)                                                                       
Stephen F. Austin (12)    Uta (5)                                              
Georgetown (4)                                                                 
Eastern Washington (13)   Geo (4)  Uta (5)  Duk (1)                            
SMU (6)                                                                        
UCLA (11)                 SMU (6)                                              
Iowa St. (3)                                                                   
UAB (14)                  Iow (3)  Iow (3)                                     
Iowa (7)                                                                       
Davidson (10)             Iow (7)                                              
Gonzaga (2)                                                                    
North Dakota St. (15)     Gon (2)  Gon (2)  Gon (2)  Duk (1)  Kan (2)          
Wisconsin (1)             Wis (1)  Wis (1)  Wis (1)  Ari (2)  Ari (2)  Kan (2) 
Coastal Carolina (16)                                                          
Oregon (8)                Okl (9)                                              
Oklahoma St. (9)                                                               
Arkansas (5)              Ark (5)  Nor (4)                                     
Wofford (12)                                                                   
North Carolina (4)        Nor (4)                                              
Harvard (13)                                                                   
Xavier (6)                Xav (6)  Bay (3)  Ari (2)                            
Mississippi (11)                                                               
Baylor (3)                Bay (3)                                              
Georgia St. (14)                                                               
VCU (7)                   Ohi (10) Ari (2)                                     
Ohio St. (10)                                                                  
Arizona (2)               Ari (2)                                              
Texas Southern (15)                                                            
Villanova (1)             Vil (1)  Vil (1)  Vil (1)  Vir (2)                   
Lafayette (16)                                                                 
North Carolina St. (8)    Nor (8)                                              
LSU (9)                                                                        
Northern Iowa (5)         Nor (5)  Nor (5)                                     
Wyoming (12)                                                                   
Louisville (4)            Lou (4)                                              
UC Irvine (13)                                                                 
Providence (6)            Pro (6)  Okl (3)  Vir (2)                            
Dayton (11)                                                                    
Oklahoma (3)              Okl (3)                                              
Albany (14)                                                                    
Michigan St. (7)          Mic (7)  Vir (2)                                     
Georgia (10)                                                                   
Virginia (2)              Vir (2)                                              
Belmont (15)                                                                   
Total bracket energy: -45.7476455682

Most common bracket (13)
Kentucky (1)                                                                   
Hampton (16)              Ken (1)                                              
Cincinnati (8)                                                                 
Purdue (9)                Pur (9)  Pur (9)                                     
West Virginia (5)                                                              
Buffalo (12)              Buf (12)                                             
Maryland (4)                                                                   
Valparaiso (13)           Mar (4)  Buf (12) Buf (12)                           
Butler (6)                                                                     
Texas (11)                But (6)                                              
Notre Dame (3)                                                                 
Northeastern (14)         Not (3)  Not (3)                                     
Wichita St. (7)                                                                
Indiana (10)              Wic (7)                                              
Kansas (2)                                                                     
New Mexico St. (15)       Kan (2)  Kan (2)  Kan (2)  Kan (2)                   
Duke (1)                                                                       
Robert Morris (16)        Duk (1)                                              
San Diego St. (8)                                                              
St. John's (9)            San (8)  San (8)                                     
Utah (5)                                                                       
Stephen F. Austin (12)    Ste (12)                                             
Georgetown (4)                                                                 
Eastern Washington (13)   Geo (4)  Ste (12) San (8)                            
SMU (6)                                                                        
UCLA (11)                 SMU (6)                                              
Iowa St. (3)                                                                   
UAB (14)                  UAB (14) UAB (14)                                    
Iowa (7)                                                                       
Davidson (10)             Iow (7)                                              
Gonzaga (2)                                                                    
North Dakota St. (15)     Gon (2)  Gon (2)  Gon (2)  Gon (2)  Kan (2)          
Wisconsin (1)             Coa (16) Okl (9)  Nor (4)  Ari (2)  Ari (2)  Kan (2) 
Coastal Carolina (16)                                                          
Oregon (8)                Okl (9)                                              
Oklahoma St. (9)                                                               
Arkansas (5)              Wof (12) Nor (4)                                     
Wofford (12)                                                                   
North Carolina (4)        Nor (4)                                              
Harvard (13)                                                                   
Xavier (6)                Mis (11) Mis (11) Ari (2)                            
Mississippi (11)                                                               
Baylor (3)                Bay (3)                                              
Georgia St. (14)                                                               
VCU (7)                   VCU (7)  Ari (2)                                     
Ohio St. (10)                                                                  
Arizona (2)               Ari (2)                                              
Texas Southern (15)                                                            
Villanova (1)             Vil (1)  Nor (8)  Nor (8)  Nor (8)                   
Lafayette (16)                                                                 
North Carolina St. (8)    Nor (8)                                              
LSU (9)                                                                        
Northern Iowa (5)         Nor (5)  Lou (4)                                     
Wyoming (12)                                                                   
Louisville (4)            Lou (4)                                              
UC Irvine (13)                                                                 
Providence (6)            Pro (6)  Okl (3)  Mic (7)                            
Dayton (11)                                                                    
Oklahoma (3)              Okl (3)                                              
Albany (14)                                                                    
Michigan St. (7)          Mic (7)  Mic (7)                                     
Georgia (10)                                                                   
Virginia (2)              Bel (15)                                             
Belmont (15)                                                                   
Total bracket energy: -38.9077921757

In [56]:
MMMC.showstats(results['all'],description='full run',newfig=True)
In [57]:
h = HTML(MMMC.maketable(results))
h
Out[57]:
TeamRegionRank2nd Round3rd RoundSweet 16Elite 8Final 4ChampionshipWin
Kansasmidwest2100.071.41555.34344.42935.55728.4422.414
Kentuckymidwest1100.069.10750.64437.44618.89113.7889.643
Arizonawest2100.065.02243.25129.62619.51512.8016.535
Wisconsinwest1100.064.47643.06629.0917.77511.2015.467
Virginiaeast2100.065.07642.90128.13117.70610.585.127
Villanovaeast1100.063.79542.21327.54617.29910.2034.848
Dukesouth1100.063.06640.64525.9615.9246.7313.64
Gonzagasouth2100.062.55737.86924.01914.3326.1573.354
Utahsouth5100.054.83133.95818.60310.6844.1712.105
North Carolinawest4100.055.79835.16818.0599.1034.6481.857
Oklahomaeast3100.057.55832.8916.6028.6994.4761.856
Iowa St.south3100.058.43532.38717.0029.0793.5191.74
Baylorwest3100.057.42533.14316.3568.7034.3281.714
Northern Iowaeast5100.058.36233.24616.9668.6874.1481.653
Notre Damemidwest3100.058.97333.14612.235.8883.0641.459
Louisvilleeast4100.056.57230.94815.2017.3493.3291.289
Wichita St.midwest7100.055.02219.55310.7315.0572.6141.235
Michigan St.east7100.053.36525.01213.6426.6373.0411.157
Ohio St.west10100.050.9723.37312.86.2412.8761.053
Georgetownsouth4100.056.35127.24213.7276.7352.3861.046
SMUsouth6100.050.54526.66412.966.3182.1970.98
Iowasouth7100.053.95926.80313.7636.4462.2730.979
Xavierwest6100.054.00225.95811.4225.5322.5410.936
West Virginiamidwest5100.055.43930.48713.0264.7332.1870.896
Providenceeast6100.054.01727.97512.2825.7362.4170.88
Arkansaswest5100.055.04325.75311.9975.2292.2750.845
Texasmidwest11100.051.71325.8289.1074.1721.9380.84
San Diego St.south8100.049.11622.9311.0335.1811.8530.755
VCUwest7100.049.0321.1879.9274.5231.9950.744
Marylandmidwest4100.053.5326.13210.8374.0561.820.735
Butlermidwest6100.048.28723.8388.2273.5931.6880.694
Davidsonsouth10100.046.04121.64610.6424.8711.6830.678
Oklahoma St.west9100.050.85722.45311.3434.6821.870.671
North Carolina St.east8100.051.91422.43911.074.8131.8960.611
St. John'ssouth9100.050.88423.05410.4114.4421.4960.575
Stephen F. Austinsouth12100.045.16922.3679.9574.3681.4390.568
Georgiaeast10100.046.63519.3369.6234.4991.5970.567
Oregonwest8100.049.14320.5189.9074.1441.6780.559
UCLAsouth11100.049.45524.06310.4534.3881.5750.554
LSUeast9100.048.08620.59.8424.1911.7080.551
Mississippiwest11100.045.99821.0018.2993.6231.440.541
Cincinnatimidwest8100.052.30820.08210.1163.181.3820.541
Daytoneast11100.045.98323.1059.3063.8981.6390.495
Purduemidwest9100.047.69218.4078.3112.9911.2160.453
Buffalomidwest12100.044.56122.6168.6812.7641.0990.392
Indianamidwest10100.044.97813.8465.7452.2690.9280.344
Harvardwest13100.044.20221.1217.512.6020.9980.339
Georgia St.west14100.042.57519.8987.4772.8941.1470.321
Valparaisomidwest13100.046.4720.7657.9222.4610.910.286
Wyomingeast12100.041.63818.2847.1232.6520.9270.268
UC Irvineeast13100.043.42817.5226.9752.7260.9650.263
Woffordwest12100.044.95717.9586.9142.2970.810.241
UABsouth14100.041.56516.8866.0772.0330.6730.222
Northeasternmidwest14100.041.02717.1885.2381.8670.6260.182
Eastern Washingtonsouth13100.043.64916.4335.6051.9680.5270.168
New Mexico St.midwest15100.028.58511.2584.2931.5660.4870.165
Albanyeast14100.042.44216.035.1831.7090.5420.151
North Dakota St.south15100.037.44313.6825.0841.7910.4990.145
Lafayetteeast16100.036.20514.8485.2771.5780.4620.142
Belmonteast15100.034.92412.7515.2311.8210.5310.139
Coastal Carolinawest16100.035.52413.9635.181.7460.5380.138
Robert Morrissouth16100.036.93413.3714.7041.440.3720.1
Texas Southernwest15100.034.97812.1894.0931.3910.3930.085
Hamptonmidwest16100.030.89310.8673.6610.9550.2620.069

Looks good! I'm in!