88from matplotlib .ticker import AutoMinorLocator
99import MySQLdb as mdb
1010
11- def computeexpectationvalue (draftpositions ):
12- #Compute the number of players taken at each draft position:
13- numperposition = np .bincount (draftpositions )[1 :]#the [1:] gets rid of zeroth pick, which is used for undrafted players.
14- positions = np .arange (1 ,len (numperposition )+ 1 )
15- probabilities = np .cumsum (numperposition [::- 1 ])[::- 1 ]/ float (np .sum (numperposition ))
16- expectationvalue = np .sum (probabilities )
17- return expectationvalue
18-
11+ def computeexpectationvalues (draftdata ,poslist = None ):
12+ if poslist == None :
13+ poslist = ['QB' ,'RB' ,'WR' ,'TE' ,'OL' ,'DL' ,'LB' ,'DB' ,'K' ]
14+ expectationvals = np .zeros (len (poslist ),dtype = np .float )
15+ for i in range (len (poslist )):
16+ draftpositions = draftdata [(draftdata [:,0 ]== poslist [i ]),1 ].astype (np .int )
17+ #Compute the number of players taken at each draft position:
18+ numperposition = np .bincount (draftpositions )[1 :]#the [1:] gets rid of zeroth pick, which is used for undrafted players.
19+ positions = np .arange (1 ,len (numperposition )+ 1 )
20+ probabilities = np .cumsum (numperposition [::- 1 ])[::- 1 ]/ float (np .sum (numperposition ))
21+ expectationvals [i ] = np .sum (probabilities )
22+ return poslist ,expectationvals
1923
24+ def bootstrapexpectations (draftdata ,numboot ):
25+ poslist = ['QB' ,'RB' ,'WR' ,'TE' ,'OL' ,'DL' ,'LB' ,'DB' ,'K' ]
26+ expectations = np .zeros ((len (poslist ),numboot ))
27+ resampindices = np .random .randint (0 ,draftdata .shape [0 ],(draftdata .shape [0 ],numboot ))
28+ for i in range (numboot ):
29+ #permute data:
30+ tempdata = draftdata [resampindices [:,i ],:]
31+ expectations [:,i ] = computeexpectationvalues (tempdata ,poslist = poslist )[1 ]
32+ print expectations .shape
33+ stds = np .std (expectations ,axis = 1 ,ddof = 1 )
34+ return stds
35+
2036con = ''
2137data = []
2238
@@ -28,19 +44,12 @@ def computeexpectationvalue(draftpositions):
2844 #Get the table:
2945 cur .execute ('select roster.pos1,roster.dpos from roster where roster.dpos > 0 and roster.start > 2001' )
3046 data = np .array (cur .fetchall ())
31-
47+
3248 #Compute the expectation value of each position:
33- qbexpectation = computeexpectationvalue (data [(data [:,0 ]== 'QB' ),1 ].astype (np .int ))
34- rbexpectation = computeexpectationvalue (data [(data [:,0 ]== 'RB' ),1 ].astype (np .int ))
35- wrexpectation = computeexpectationvalue (data [(data [:,0 ]== 'WR' ),1 ].astype (np .int ))
36- teexpectation = computeexpectationvalue (data [(data [:,0 ]== 'TE' ),1 ].astype (np .int ))
37- olexpectation = computeexpectationvalue (data [(data [:,0 ]== 'OL' ),1 ].astype (np .int ))
38- dlexpectation = computeexpectationvalue (data [(data [:,0 ]== 'DL' ),1 ].astype (np .int ))
39- dbexpectation = computeexpectationvalue (data [(data [:,0 ]== 'DB' ),1 ].astype (np .int ))
40- lbexpectation = computeexpectationvalue (data [(data [:,0 ]== 'LB' ),1 ].astype (np .int ))
41- kexpectation = computeexpectationvalue (data [(data [:,0 ]== 'K' ),1 ].astype (np .int ))
42- print "QB: {0:.2f}, RB: {1:.2f}, WR: {2:.2f}, TE: {3:.2f}, OL: {4:.2f}" .format (qbexpectation ,rbexpectation ,wrexpectation ,teexpectation ,olexpectation )
43- print "DL: {0:.2f}, LB: {1:.2f}, DB: {2:.2f}, K: {3:.2f}" .format (dlexpectation ,lbexpectation ,dbexpectation ,kexpectation )
49+ poslist ,expectationvalues = computeexpectationvalues (data )
50+ stds = bootstrapexpectations (data ,100000 )
51+ for i in range (len (poslist )):
52+ print "{0:s}: {1:.2f} +/- {2:.3f}" .format (poslist [i ],expectationvalues [i ],stds [i ])
4453
4554 #Make some histogram plots:
4655 bins = np .arange (1 ,250 ,10 )
0 commit comments