Demo entry 6734698

金王震

   

Submitted by anonymous on Apr 21, 2018 at 13:55
Language: Python 3. Code size: 1.0 kB.

def  build_dataSet(all_data):
    print("Building data set..")
    for index, row in all_data.iterrows():
        Wteam = row['WTeam']
        Lteam = row['LTeam']
        team1_elo = get_elo(Wteam)
        team2_elo = get_elo(Lteam)
        if row['WLoc'] == 'H':
            team1_elo += 100
        else:
            team2_elo += 100
        team1_features = [team1_elo]
        team2_features = [team2_elo]
        for key, value in team_stats.loc[Wteam].iteritems():
            team1_features.append(value)
        for key, value in team_stats.loc[Lteam].iteritems():
            team2_features.append(value)
        if random.random() > 0.5:
            X.append(team1_features + team2_features)
            y.append(0)
        else:
            X.append(team2_features + team1_features)
            y.append(1)
        new_winner_rank, new_loser_rank = calc_elo(Wteam, Lteam)
        team_elos[Wteam] = new_winner_rank
        team_elos[Lteam] = new_loser_rank

    return np.nan_to_num(X), np.array(y)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).