|
19 | 19 | "metadata": {},
|
20 | 20 | "outputs": [],
|
21 | 21 | "source": [
|
22 |
| - "df = pd.read_csv('BBGM_League_1_all_seasons_Average_Stats.csv')" |
| 22 | + "df = pd.read_csv('BBGM_League_109_all_seasons_Average_Stats.csv')\n", |
| 23 | + "df = df[df['MP']*df['G'] > 10]" |
23 | 24 | ]
|
24 | 25 | },
|
25 | 26 | {
|
|
46 | 47 | "metadata": {},
|
47 | 48 | "outputs": [],
|
48 | 49 | "source": [
|
49 |
| - "stats_to_est = ['FT','FTA','FG','FGA','ORB','DRB','AST','TOV','STL','Blk','PF','PTS','3P','3PA','BA']\n", |
50 |
| - "sT = [_ +'p36' for _ in stats_to_est]" |
| 50 | + "plt.hist(df['+/-'])" |
51 | 51 | ]
|
52 | 52 | },
|
53 | 53 | {
|
|
56 | 56 | "metadata": {},
|
57 | 57 | "outputs": [],
|
58 | 58 | "source": [
|
| 59 | + "# full\n", |
| 60 | + "stats_to_est = [ 'FG', 'FGA', '3P', '3PA', '2P', '2PA', 'FT', 'FTA', 'ORB', 'DRB', 'TRB', 'AST', 'TOV', 'STL', 'BLK', 'BA', 'PF', 'PTS']\n", |
| 61 | + "# pruned by hand based on t-values, R^2 = .804\n", |
| 62 | + "stats_to_est = [ '3PA', '2PA', 'FTA', 'TRB', 'AST', 'TOV', 'STL', 'BLK', 'PF', 'PTS']\n", |
| 63 | + "#R^2 = .773 w/o +/-, 0.788 with\n", |
| 64 | + "stats_to_est = [ 'TRB', 'AST', 'TOV', 'STL', 'BLK', 'PF', 'PTS', '+/-']\n", |
| 65 | + "\n", |
| 66 | + "sT = [_ +'p36' for _ in stats_to_est]\n" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": null, |
| 72 | + "metadata": {}, |
| 73 | + "outputs": [], |
| 74 | + "source": [ |
| 75 | + "p_36_stats = []\n", |
59 | 76 | "for s in stats_to_est:\n",
|
60 |
| - " df[s + 'p36'] = 36*df[s]/np.maximum(df['MP'],1e-6)" |
| 77 | + " df[s + 'p36'] = 36*df[s]/np.maximum(df['MP'],1)\n", |
| 78 | + " p_36_stats.append(s+'p36')\n", |
| 79 | + "p_36_stats = p_36_stats #+['+/-']#+ ['TS%']" |
61 | 80 | ]
|
62 | 81 | },
|
63 | 82 | {
|
|
66 | 85 | "metadata": {},
|
67 | 86 | "outputs": [],
|
68 | 87 | "source": [
|
69 |
| - "dfs = df[df.MP*df.G > 850]\n", |
70 |
| - "res = sm.RLM(dfs['Ovr'],sm.add_constant(dfs[stats_to_est])).fit()\n", |
71 |
| - "res.summary()" |
| 88 | + "res = sm.WLS(df['Ovr'],sm.add_constant(df[p_36_stats]),df['MP']*df['G']).fit()\n", |
| 89 | + "res.summary() # -6.7306e+05 1.346e+06 1.005e+05" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": null, |
| 95 | + "metadata": { |
| 96 | + "scrolled": true |
| 97 | + }, |
| 98 | + "outputs": [], |
| 99 | + "source": [ |
| 100 | + "import sklearn.linear_model as linear_model\n", |
| 101 | + "clf = linear_model.RidgeCV(np.logspace(-3,3,101))\n", |
| 102 | + "p = 1\n", |
| 103 | + "clf.fit(df[p_36_stats],(df['Ovr'])**p,df['MP']*df['G'])\n", |
| 104 | + "df['sOVR'] = np.maximum(0,clf.predict(df[p_36_stats]))**(1/p)\n", |
| 105 | + "plt.scatter(df['Ovr'],df['sOVR'],s=5,alpha=0.5)\n" |
72 | 106 | ]
|
73 | 107 | },
|
74 | 108 | {
|
|
77 | 111 | "metadata": {},
|
78 | 112 | "outputs": [],
|
79 | 113 | "source": [
|
80 |
| - "plt.scatter(dfs['Ovr'],res.predict(),s=5,alpha=0.5)" |
| 114 | + "plt.scatter(df['Ovr'],res.predict(),s=5,alpha=0.5)" |
81 | 115 | ]
|
82 | 116 | },
|
83 | 117 | {
|
|
86 | 120 | "metadata": {},
|
87 | 121 | "outputs": [],
|
88 | 122 | "source": [
|
89 |
| - "dfs['sOVR'] = res.predict()\n", |
90 |
| - "dfs['PS'] = dfs['Ovr']/dfs['sOVR']" |
| 123 | + "df['sOVR'] = clf.predict(df[p_36_stats])**(1/p)#res.predict()\n", |
| 124 | + "df['PS'] = df['Ovr']/df['sOVR']" |
91 | 125 | ]
|
92 | 126 | },
|
93 | 127 | {
|
|
105 | 139 | "metadata": {},
|
106 | 140 | "outputs": [],
|
107 | 141 | "source": [
|
108 |
| - "plt.plot(dfs[['Age','PS','Ovr','sOVR']].groupby('Age').mean()['PS'])\n", |
| 142 | + "plt.plot(df[['Age','PS','Ovr','sOVR']].groupby('Age').mean()['PS'])\n", |
109 | 143 | "plt.xlim(20,44)\n",
|
110 | 144 | "plt.ylabel('Ovr ÷ sOVR')\n",
|
111 | 145 | "plt.xlabel('Age')"
|
|
138 | 172 | "metadata": {},
|
139 | 173 | "outputs": [],
|
140 | 174 | "source": [
|
141 |
| - "#dft = dfs.groupby(['pid','Age']).mean()\n", |
142 |
| - "df['sOVR'] = res.predict(sm.add_constant(df[stats_to_est]))\n", |
143 | 175 | "dft = df.groupby(['pid','Age']).mean()"
|
144 | 176 | ]
|
145 | 177 | },
|
|
176 | 208 | "metadata": {},
|
177 | 209 | "outputs": [],
|
178 | 210 | "source": [
|
179 |
| - "print('4 year value by age\\nage [pot ovr]')\n", |
| 211 | + "print('5 year value by age\\nage scale [pot ovr]')\n", |
| 212 | + "sA = []\n", |
| 213 | + "sB = []\n", |
180 | 214 | "for age in sorted(p_y.keys()):\n",
|
181 | 215 | " Xy = np.array(p_y[age])\n",
|
182 | 216 | " if (Xy[:,0] == Xy[:,1]).all():\n",
|
183 | 217 | " Xy = Xy[:,1:]\n",
|
184 | 218 | " res2 = sm.OLS(Xy[:,-1],Xy[:,:-1]).fit()\n",
|
185 |
| - " print(age,np.round(res2.params,2))" |
| 219 | + " v = res2.params\n", |
| 220 | + " vS = sum(v)\n", |
| 221 | + " sA.append((age,vS))\n", |
| 222 | + " sB.append((age,v[0]/vS))\n", |
| 223 | + " print(age,np.round(vS,2),np.round(v/vS,2))" |
| 224 | + ] |
| 225 | + }, |
| 226 | + { |
| 227 | + "cell_type": "code", |
| 228 | + "execution_count": null, |
| 229 | + "metadata": {}, |
| 230 | + "outputs": [], |
| 231 | + "source": [ |
| 232 | + "sA = np.array(sA)\n", |
| 233 | + "plt.plot(sA[:,0],sA[:,1])\n", |
| 234 | + "plt.xlim(20,40)\n", |
| 235 | + "plt.xlabel('age')\n", |
| 236 | + "plt.ylabel('multi-year value')\n", |
| 237 | + "plt.title('4 year [reg tree]')" |
| 238 | + ] |
| 239 | + }, |
| 240 | + { |
| 241 | + "cell_type": "code", |
| 242 | + "execution_count": null, |
| 243 | + "metadata": {}, |
| 244 | + "outputs": [], |
| 245 | + "source": [ |
| 246 | + "sB = np.array(sB)\n", |
| 247 | + "plt.plot(sB[:,0],sB[:,1])\n", |
| 248 | + "plt.xlim(20,28)\n", |
| 249 | + "plt.xlabel('age')\n", |
| 250 | + "plt.ylabel('potential weight')\n", |
| 251 | + "plt.title('4 year [reg tree]')" |
186 | 252 | ]
|
187 | 253 | }
|
188 | 254 | ],
|
189 | 255 | "metadata": {
|
190 | 256 | "kernelspec": {
|
191 |
| - "display_name": "Python 3", |
| 257 | + "display_name": "Python 3 (ipykernel)", |
192 | 258 | "language": "python",
|
193 | 259 | "name": "python3"
|
194 | 260 | },
|
|
202 | 268 | "name": "python",
|
203 | 269 | "nbconvert_exporter": "python",
|
204 | 270 | "pygments_lexer": "ipython3",
|
205 |
| - "version": "3.7.3" |
| 271 | + "version": "3.9.12" |
206 | 272 | }
|
207 | 273 | },
|
208 | 274 | "nbformat": 4,
|
|
0 commit comments