Exemplo n.º 1
0
 def gen_factorizations(stats, wk):
     '''
     Input:  List - stats to factorize, Int - week to factorize stats until
     
     Generates DataFrames with factorized stats from input list for each player that week,
     includes their position, team, the week number, their factorized skill, the skill of 
     the defense they played that week for that position, and the fantasy points they 
     actually produced that week.
     '''
     for_nmf_df = get_yr_until_wk(year, wk, nfl_frames) 
     for stat in stats:
         stat_cols = ['{}_factorized_{}'.format(ball_side, stat) for ball_side in ['off', 'def']]
         cols_to_keep = cols + stat_cols
         decomp_off_stat, decomp_def_stat = nmf_all_positions(stat, for_nmf_df)
         week_df = nfl_frames.get_year_week_frame(year, wk)
         stat_df = week_df.merge(decomp_off_stat, on='player_id')
         stat_opp_df = stat_df.merge(decomp_def_stat, how='left', on=['opponent', 'position'])
         yield stat_opp_df[cols_to_keep]
Exemplo n.º 2
0
def check_nmf_model(nfl_frames, year, week, position='All'):
    '''
    Input:  NFLFrames, Int, Int, Str
    Output: None

    Prints comparison of standard deviation in fanduel points versus RMSE in predictions.
    '''
    fp_stat = 'fanduel_points'
    historical_data = get_yr_until_wk(year, week, nfl_frames)
    offense, defense = nmf_all_positions(fp_stat, historical_data)
    all_week_actuals_df = nfl_frames.get_year_week_frame(year, week)
    preds_to_make = get_preds_to_make(year, week + 1, nfl_frames)
    for_preds_df = merge_factorizations_to_main_df(preds_to_make, offense, defense)
    if position is not 'All':
        week_actuals = all_week_actuals_df.query('position == @position')
        for_preds = for_preds_df.query('position == @position')
    else:
        week_actuals = all_week_actuals_df
        for_preds = for_preds_df
    preds = preds_from_factorized_skills(for_preds)
    my_rmse = year_week_rmse(week_actuals, preds)
    
    check_model_string = 'STD in fanduel points:\t{}\nRMSE in predictions:\t{}'
    print(check_model_string.format(week_actuals.fanduel_points.std(), my_rmse))