3
\$\begingroup\$

I've been working on trying to predict fantasy performance of players in this upcoming NFL season based on projections from several experts/sources. I trained the data on projections from last year and performed cross validation using the actual fantasy points that each player ended up scoring. I was just wondering if I could get some feedback on this little project of mine. I don't have any specific questions. Just point out anything I may have overlooked. Here's the code and also the input data:

import pandas as pd
import os
import sklearn.linear_model as linear_model
from sklearn.grid_search import GridSearchCV
from sklearn.preprocessing import StandardScaler

def ridge_pipeline(df,df_2017):
     x_unscaled=df.filter(regex=('.*_proj_pts'))
     x=StandardScaler().fit_transform(x_unscaled)
     y=df.actual_points
     param_grid={'alpha':[0.0001,0.001,0.1,1,10,100,500,1000]}
     grid = GridSearchCV(linear_model.Ridge(), param_grid, cv=10,n_jobs=-1)
     grid.fit(x, y)
     best_alph=grid.best_params_['alpha']
     if best_alph in [0.0001,1000]:
         return 'WARNING: best_alph at endpoint'+': '+str(best_alph)
     else:
         ridge=linear_model.Ridge(alpha=best_alph).fit(x,y)
         x_2017=df_2017.loc[:,list(x_unscaled)]
         x_2017=StandardScaler().fit_transform(x_2017)
         df_2017['my_proj']=ridge.predict(x_2017)
         return df_2017.loc[:,['player','position',
              'my_proj']].sort_values('my_proj',ascending=False)

 df_2017=pd.read_csv('2017_projections.csv')
 masterDf=pd.read_csv('2016_actual_and_proj.csv')
 d={}
 for pos in ['DST','QB','RB','WR','TE']:
      result=ridge_pipeline(masterDf.loc[masterDf
           ['position']==pos],df_2017.loc[df_2017['position']==pos])
      d[pos]=result
 myProjDf=pd.concat([df for df in d.values()],ignore_index=True)
 myProjDf.to_csv('my_projections.csv',index=False)

2016_actual_and_proj

2017_projections

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.