In [1]:

```
import numpy as np
import matplotlib.pyplot as plot
import seaborn as sb
import h5py as h5
%matplotlib inline
```

Load in the 3 datafiles, which I downloaded (and modified) from https://www.indatabet.com/free.html

In [2]:

```
football = h5.File('football.h5')
basketball = h5.File('basketball.h5')
hockey = h5.File('hockey.h5')
```

In [14]:

```
totalScoresFootball = (football['Hgoals'])[...]+(football['Agoals'])[...]
footballMean = np.mean(totalScoresFootball)
totalScoresHockey = (hockey['Hgoals'])[...]+(hockey['Agoals'])[...]
noOvertimeMask = ~(hockey['overtimeOrPenalties'])[...]
hockeyMean = np.mean(totalScoresHockey[noOvertimeMask])
totalScoresBasketball = ((basketball['Hscore'])[...]+(basketball['Ascore'])[...])/3.
basketballMean = np.mean(totalScoresBasketball)
```

In [26]:

```
fig,axs = plot.subplots(1,3)
axs = axs.reshape((-1))
axs[0].hist(totalScoresFootball,bins=15,normed=True,color='b',alpha=0.6,histtype='stepfilled',label='Football')
axs[1].hist(totalScoresBasketball,bins=15,normed=True,color='g',alpha=0.6,histtype='stepfilled',label='Basketball')
axs[2].hist(totalScoresHockey[noOvertimeMask],bins=15,normed=True,color='r',alpha=0.6,histtype='stepfilled',range=(0,14),label='Ice Hockey')
axs[0].axvline(footballMean,color='k',label='Mean = '+str(footballMean))
axs[1].axvline(basketballMean,color='k',label='Mean = '+str(basketballMean))
axs[2].axvline(hockeyMean,color='k',label='Mean = '+str(hockeyMean))
for ax in axs:
ax.legend()
ax.set_xlabel('Scoring Events',size=14)
fig.set_size_inches(18,5)
```

In [67]:

```
def countUnexpectedResults(homeOdds,awayOdds,homeScore,awayScore):
expectedHomeWin = 3.*homeOdds < awayOdds
expectedAwayWin = homeOdds > 3.*awayOdds
homeWin = homeScore > awayScore
awayWin = homeScore < awayScore
unexpectedResult = (expectedHomeWin & awayWin) | (expectedAwayWin & homeWin)
return np.count_nonzero(unexpectedResult)
```

In [68]:

```
nUnexpectedFootball = countUnexpectedResults((football['Hodds'])[...],
(football['Aodds'])[...],
(football['Hgoals'])[...],
(football['Agoals'])[...])
nUnexpectedBasketball = countUnexpectedResults((basketball['Hodds'])[...],
(basketball['Aodds'])[...],
(basketball['Hscore'])[...],
(basketball['Ascore'])[...])
nUnexpectedHockey = countUnexpectedResults((hockey['Hodds'])[...],
(hockey['Aodds'])[...],
(hockey['Hgoals'])[...],
(hockey['Agoals'])[...])
```

In [69]:

```
nTotalFootball = len(totalScoresFootball)
nTotalBasketball = len(totalScoresBasketball)
nTotalHockey = len(totalScoresHockey)
rateUnexpectedFootball = nUnexpectedFootball/float(nTotalFootball)
rateUnexpectedBasketball = nUnexpectedBasketball/float(nTotalBasketball)
rateUnexpectedHockey = nUnexpectedHockey/float(nTotalHockey)
ruFootballError = np.sqrt(nUnexpectedFootball)/float(nTotalFootball)
ruBasketballError = np.sqrt(nUnexpectedBasketball)/float(nTotalBasketball)
ruHockeyError = np.sqrt(nUnexpectedHockey)/float(nTotalHockey)
```

In [75]:

```
fig,ax = plot.subplots(1,1)
ax.errorbar([0],[rateUnexpectedFootball],[ruFootballError],color='b',fmt='|',linewidth=8)
ax.errorbar([1],[rateUnexpectedBasketball],[ruBasketballError],color='g',fmt='|',linewidth=8)
ax.errorbar([2],[rateUnexpectedHockey],[ruHockeyError],color='r',fmt='|',linewidth=8)
plot.ylabel('Probability of Unexpected Result',size=15)
plot.xticks(range(3),['Football','Basketball','Hockey'],size=15)
fig.set_size_inches(18,5)
```