Skip to content

Commit a7c6c77

Browse files
committed
merge roster
1 parent f3a907e commit a7c6c77

File tree

6 files changed

+1017
-938
lines changed

6 files changed

+1017
-938
lines changed

best_roster.ipynb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@
406406
"source": [
407407
"plt.style.use('fivethirtyeight')\n",
408408
"plt.style.use('seaborn-white')\n",
409-
"plt.scatter(dt['ovr'],dt['pts'],s=3,alpha=0.8)\n",
409+
"plt.scatter(dt['ovr'],dt['pts']/50,s=1,alpha=0.4)\n",
410410
"plt.xlabel('overall (min weighted)')\n",
411411
"plt.ylabel('point margin')\n",
412412
"plt.title('r squared: {:.3f}'.format(scipy.stats.pearsonr(dt['ovr']/50,dt['pts'])[0]**2))\n",
413-
"plt.grid(True)"
413+
"plt.grid(True)\n"
414414
]
415415
},
416416
{
@@ -421,11 +421,13 @@
421421
"source": [
422422
"plt.style.use('fivethirtyeight')\n",
423423
"plt.style.use('seaborn-white')\n",
424-
"plt.scatter(dt['pts']/50,clf_res.predict(),s=3,alpha=0.8)\n",
424+
"plt.scatter(dt['pts']/50,clf_res.predict(),s=1,alpha=0.4)\n",
425425
"plt.xlabel('actual margin')\n",
426426
"plt.ylabel('predicted margin')\n",
427427
"plt.title('r squared: {:.3f}'.format(scipy.stats.pearsonr(dt['pts']/50,clf_res.predict())[0]**2))\n",
428-
"plt.grid(True)"
428+
"plt.grid(True)\n",
429+
"plt.xlim(-40,40)\n",
430+
"plt.ylim(-40,40)"
429431
]
430432
},
431433
{

fetch_cbb.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"from bs4 import BeautifulSoup\n",
1111
"import re\n",
1212
"import subprocess\n",
13-
"import pandas as pd\n",
13+
"import pandas as pdz\n",
1414
"schools = ['youngstown-state','yale','xavier','wyoming','wright-state','wofford','wisconsin','winthrop','william-mary','wichita-state','western-michigan','western-kentucky','western-illinois','western-carolina','west-virginia','weber-state','washington-state','washington','wake-forest','wagner','virginia-tech','virginia-military-institute','virginia-commonwealth','virginia','villanova','vermont','vanderbilt','valparaiso','utah-valley','utah','utah-state','california','ucla','california-santa-barbara','california-riverside','california-irvine','california-davis','tulsa','tulane','troy','towson','toledo','texas-san-antonio','texas-pan-american','texas-el-paso','texas-arlington','texas-tech','texas-state','texas-southern','texas','texas-christian','texas-am-corpus-christi','texas-am','tennessee-martin','tennessee','tennessee-tech','tennessee-state','temple','syracuse','stony-brook','stetson','stephen-f-austin','stanford','st-johns-ny','st-francis-ny','st-bonaventure','southern-utah','southern-mississippi','southern-methodist','southern','southern-illinois-edwardsville','southern-illinois','southern-california','southeastern-louisiana','southeast-missouri-state','south-florida','south-dakota-state','south-dakota','south-carolina-upstate','south-carolina-state','south-carolina','south-alabama','siena','seton-hall','seattle','savannah-state','santa-clara','san-jose-state','san-francisco','san-diego','san-diego-state','samford','sam-houston-state','saint-peters','saint-marys-ca','saint-louis','saint-josephs','saint-francis-pa','sacred-heart','sacramento-state','rutgers','robert-morris','rider','richmond','rice','rhode-island','radford','quinnipiac','ipfw','purdue','providence','princeton','presbyterian','prairie-view','portland-state','portland','pittsburgh','pepperdine','pennsylvania','penn-state','pacific','oregon-state','oregon','oral-roberts','nebraska-omaha','old-dominion','oklahoma-state','oklahoma','ohio-state','ohio','oakland','notre-dame','northwestern','northwestern-state','northern-kentucky','northern-iowa','northern-illinois','northern-colorado','northern-arizona','northeastern','north-texas','north-florida','north-dakota-state','north-dakota','north-carolina-wilmington','north-carolina-greensboro','north-carolina-asheville','north-carolina','north-carolina-state','north-carolina-central','north-carolina-at','north-alabama','norfolk-state','njit','nicholls-state','niagara','new-orleans','new-mexico-state','new-mexico','new-hampshire','nevada-las-vegas','nevada','nebraska','navy','murray-state','mount-st-marys','morgan-state','morehead-state','montana-state','montana','monmouth','missouri-kansas-city','missouri','missouri-state','mississippi-valley-state','mississippi-state','mississippi','minnesota','milwaukee','middle-tennessee','michigan','michigan-state','miami-oh','miami-fl','mercer','memphis','mcneese-state','massachusetts-lowell','massachusetts','maryland-eastern-shore','maryland-baltimore-county','maryland','marshall','marquette','marist','manhattan','maine','loyola-marymount','loyola-md','loyola-il','louisville','louisiana-monroe','louisiana-tech','louisiana-state','louisiana-lafayette','longwood','long-island-university','long-beach-state','arkansas-little-rock','lipscomb','liberty','lehigh','lamar','lafayette','la-salle','kentucky','kent-state','kennesaw-state','kansas-state','kansas','james-madison','jacksonville-state','jacksonville','jackson-state','iupui','iowa-state','iowa','iona','indiana-state','indiana','incarnate-word','illinois-chicago','illinois-state','illinois','idaho','idaho-state','howard','houston','houston-baptist','holy-cross','hofstra','high-point','hawaii','harvard','hartford','hampton','green-bay','grand-canyon','grambling','gonzaga','georgia-tech','georgia-state','georgia-southern','georgia','georgetown','george-washington','george-mason','gardner-webb','furman','fresno-state','fordham','florida-state','florida-international','florida-gulf-coast','florida','florida-atlantic','florida-am','fairleigh-dickinson','fairfield','evansville','elon','eastern-washington','eastern-michigan','eastern-kentucky','eastern-illinois','east-tennessee-state','east-carolina','duquesne','duke','drexel','drake','detroit-mercy','depaul','denver','delaware-state','delaware','dayton','davidson','dartmouth','creighton','cornell','coppin-state','connecticut','columbia','colorado-state','colorado','college-of-charleston','colgate','coastal-carolina','cleveland-state','clemson','citadel','cincinnati','chicago-state','chattanooga','charlotte','charleston-southern','central-michigan','central-florida','central-connecticut-state','central-arkansas','canisius','campbell','california-baptist','cal-state-northridge','cal-state-fullerton','cal-state-bakersfield','cal-poly','butler','buffalo','bucknell','bryant','brown','brigham-young','bradley','bowling-green-state','boston-university','boston-college','boise-state','binghamton','bethune-cookman','belmont','baylor','ball-state','austin-peay','auburn','army','arkansas-pine-bluff','arkansas-state','arkansas','arizona','arizona-state','appalachian-state','american','alcorn-state','albany-ny','alabama-birmingham','alabama-state','alabama','alabama-am','akron','air-force','abilene-christian']"
1515
]
1616
},

merge_roster.ipynb

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"outputs": [],
1818
"source": [
1919
"base_roster = 'normed_new.json'\n",
20-
"settings_roster = 'auto_roster_2020.json'\n"
20+
"settings_roster = 'auto_roster_2020.json'\n",
21+
"settings_roster_old = 'auto_roster_2019.json'\n"
2122
]
2223
},
2324
{
@@ -30,9 +31,20 @@
3031
" base = json.load(fp)\n",
3132
"with open(settings_roster) as fp:\n",
3233
" settings = json.load(fp)\n",
34+
"with open(settings_roster_old) as fp:\n",
35+
" settings_old = json.load(fp)\n",
3336
"base['version'] = 36\n"
3437
]
3538
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"born_new = {}"
46+
]
47+
},
3648
{
3749
"cell_type": "code",
3850
"execution_count": null,
@@ -46,13 +58,34 @@
4658
" if nsplit[-1] in ['Jr','Sr','III','II','Jr.','Sr.']:\n",
4759
" name = ' '.join(nsplit[:-1])\n",
4860
" p['name'] = unidecode(name).replace('.','')\n",
61+
" born_new[p['name'].lower()] = p['born']['year']\n",
4962
" if p['name'] in new_settings:\n",
5063
" print(new_settings[p['name']])\n",
5164
" print(p)\n",
5265
" print()\n",
5366
" new_settings[p['name'].lower()] = p"
5467
]
5568
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": null,
72+
"metadata": {},
73+
"outputs": [],
74+
"source": [
75+
"new_settings['stephen curry']\n",
76+
"for p in settings_old['players']:\n",
77+
" name = p['firstName'] + ' ' + p['lastName']\n",
78+
" nsplit = unidecode(name).split(' ')\n",
79+
" if nsplit[-1] in ['Jr','Sr','III','II','Jr.','Sr.']:\n",
80+
" name = ' '.join(nsplit[:-1])\n",
81+
" p['name'] = unidecode(name).replace('.','')\n",
82+
" #print(name)\n",
83+
" if p['name'].lower() == 'stephen curry':\n",
84+
" new_settings[p['name'].lower()]['ratings'] = p['ratings']\n",
85+
" print(p['ratings'])\n",
86+
"new_settings['stephen curry']\n"
87+
]
88+
},
5689
{
5790
"cell_type": "code",
5891
"execution_count": null,
@@ -68,14 +101,14 @@
68101
" nsplit = name.split(' ')\n",
69102
" if nsplit[-1] in ['Jr','Sr','III','II','Jr.','Sr.']:\n",
70103
" name = ' '.join(nsplit[:-1])\n",
71-
" if name.lower() in new_settings :\n",
104+
" if name.lower() in new_settings and abs(born_new.get(name.lower(),0)-p['born']['year']) < 3:\n",
72105
" if new_settings[name.lower()]['tid'] < -1:\n",
73106
" #print('skipped',name)\n",
74-
" print(p['ratings'])\n",
107+
" #print(p['ratings'])\n",
75108
" continue\n",
76109
" p['ratings'] = new_settings[name.lower()]['ratings']\n",
77110
" else:\n",
78-
" print(name)"
111+
" print(name,name.lower() in new_settings,p['name'])"
79112
]
80113
},
81114
{
@@ -84,7 +117,7 @@
84117
"metadata": {},
85118
"outputs": [],
86119
"source": [
87-
"with open('updated_roster20.json','wt') as fp:\n",
120+
"with open('updated_roster.json','wt') as fp:\n",
88121
" json.dump(base,fp)"
89122
]
90123
},
@@ -156,7 +189,7 @@
156189
"name": "python",
157190
"nbconvert_exporter": "python",
158191
"pygments_lexer": "ipython3",
159-
"version": "3.6.8"
192+
"version": "3.6.9"
160193
}
161194
},
162195
"nbformat": 4,

team_win_testing.ipynb

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265
"source": [
266266
"diff_m = sm.OLS(diff_df['MOV'],sm.add_constant(diff_df.drop('MOV',axis=1))).fit()\n",
267267
"diff_m = sm.OLS(diff_df['MOV'],sm.add_constant(diff_df['Ovr'])).fit()\n",
268-
"#diff_m = sm.OLS(diff_df['MOV'],sm.add_constant(diff_df.drop(['MOV','Ovr','Pot'],axis=1))).fit()\n"
268+
"diff_m = sm.OLS(diff_df['MOV'],sm.add_constant(diff_df.drop(['MOV','Ovr','Pot'],axis=1))).fit()\n"
269269
]
270270
},
271271
{
@@ -283,9 +283,100 @@
283283
"metadata": {},
284284
"outputs": [],
285285
"source": [
286-
"plt.scatter(diff_m.predict(),diff_df['MOV'],s=8,alpha=0.1)\n",
287-
"plt.xlabel('Predicted MOV (min-weighted OVR + HFA)')\n",
288-
"plt.ylabel('MOV')"
286+
"import pickle\n",
287+
"res = pickle.load(open('ats_res.pkl','rb'))"
288+
]
289+
},
290+
{
291+
"cell_type": "code",
292+
"execution_count": null,
293+
"metadata": {},
294+
"outputs": [],
295+
"source": [
296+
"plt.scatter(diff_m.predict(),diff_df['MOV'],s=2,alpha=0.2,label='bbgm')\n",
297+
"plt.scatter(res[:,0],res[:,1],s=10,alpha=0.6,label='19/20 NBA')\n",
298+
"\n",
299+
"plt.xlabel('Predicted MOV')\n",
300+
"plt.ylabel('MOV')\n",
301+
"plt.legend(markerscale=5)\n",
302+
"plt.tight_layout()\n",
303+
"plt.xlim(-20,20)\n",
304+
"plt.ylim(-50,50)"
305+
]
306+
},
307+
{
308+
"cell_type": "code",
309+
"execution_count": null,
310+
"metadata": {},
311+
"outputs": [],
312+
"source": [
313+
"res2 = np.stack([diff_m.predict(),diff_df['MOV']]).T"
314+
]
315+
},
316+
{
317+
"cell_type": "code",
318+
"execution_count": null,
319+
"metadata": {},
320+
"outputs": [],
321+
"source": [
322+
"covar_nba = res @ res.T"
323+
]
324+
},
325+
{
326+
"cell_type": "code",
327+
"execution_count": null,
328+
"metadata": {},
329+
"outputs": [],
330+
"source": [
331+
"from sklearn.decomposition import PCA"
332+
]
333+
},
334+
{
335+
"cell_type": "code",
336+
"execution_count": null,
337+
"metadata": {},
338+
"outputs": [],
339+
"source": [
340+
"c1 = PCA()\n",
341+
"c1.fit(res)\n",
342+
"c1.mean_,np.sqrt(c1.singular_values_)"
343+
]
344+
},
345+
{
346+
"cell_type": "code",
347+
"execution_count": null,
348+
"metadata": {},
349+
"outputs": [],
350+
"source": [
351+
"c2 = PCA()\n",
352+
"c2.fit(res2)\n",
353+
"c2.mean_,np.sqrt(c2.singular_values_)"
354+
]
355+
},
356+
{
357+
"cell_type": "code",
358+
"execution_count": null,
359+
"metadata": {},
360+
"outputs": [],
361+
"source": [
362+
"d1 = res[np.where((res[:,0] <55.1) & (res[:,0] > 9.9))][:,1]\n",
363+
"d2 = res2[np.where((res2[:,0] <55.1) & (res2[:,0] > 9.9))][:,1]\n",
364+
"plt.hist(d1,20,alpha=0.5,label='NBA 19/20',density=True)\n",
365+
"plt.hist(d2,20,alpha=0.5,label='BBGM',density=True)\n",
366+
"plt.grid('True')\n",
367+
"plt.title('Games with Spread 10 or more')\n",
368+
"plt.xlabel('MOV')\n",
369+
"plt.legend()\n",
370+
"plt.tight_layout()"
371+
]
372+
},
373+
{
374+
"cell_type": "code",
375+
"execution_count": null,
376+
"metadata": {},
377+
"outputs": [],
378+
"source": [
379+
"(d1 > 0).sum()/d1.shape[0],(d2 > 0).sum()/d2.shape[0]"
289380
]
290381
},
291382
{

0 commit comments

Comments
 (0)