Beispiel #1
0
def predict_games(t_teams, clf, outfile_fn, out):
    pred_fd = open(outfile_fn, 'w')
    header = "id,pred\n"
    pred_fd.write(header)

    prediction_dict = {}

    # For producing submissions
    for season in t_teams:
        #print "Key : ",key
        t_teams[season].sort()

        game_vect = []

        # Begin with first team of season - iterate over all remaining
        while len(t_teams[season]) > 1:
            lower_team = t_teams[season].pop(0)
            for opponent in t_teams[season]:
                # Predict percentage for 'lower team', or team with
                this_game = vectorize(teams[lower_team].game_queue[season],
                                      teams[opponent].game_queue[season],
                                      teams[lower_team].wlp[season],
                                      teams[opponent].wlp[season])

                game_key = Game.create_game_str(season, lower_team, opponent)

                predict_probability = clf.predict_proba(this_game)
                predict_binary = clf.predict(this_game)

                prediction_dict[game_key] = Game(game_key, lower_team,
                                                 opponent, predict_binary,
                                                 predict_probability)

                pred_fd.write(prediction_dict[game_key].to_prediction())
                game_vect.append(this_game)
        print "Predictions for tournament season", season

    pred_fd.close()

    return prediction_dict
Beispiel #2
0
def get_results(results_fn, game_dict):
    results_fd = open(results_fn)

    # For testing
    for result in results_fd:
        split_res = result.split(',')
        season = split_res[0].strip()
        if season not in predict_season:
            continue
        winner = split_res[2].strip()
        loser = split_res[4].strip()
        if winner < loser:
            game_str = Game.create_game_str(season, winner, loser)

            # Game considered win
            game_dict[game_str].actual_result(1.)

        else:
            game_str = Game.create_game_str(season, loser, winner)

            # Game considered loss
            game_dict[game_str].actual_result(0.)

    results_fd.close()
Beispiel #3
0
def get_results(results_fn, game_dict):
    results_fd = open(results_fn)

    # For testing
    for result in results_fd:
        split_res = result.split(',')
        season = split_res[0].strip()
        if season not in predict_season :
            continue
        winner = split_res[2].strip()
        loser = split_res[4].strip()
        if winner < loser :
            game_str = Game.create_game_str(season, winner, loser)

            # Game considered win            
            game_dict[game_str].actual_result(1.)

        else :
            game_str = Game.create_game_str(season, loser, winner)

            # Game considered loss  
            game_dict[game_str].actual_result(0.)

    results_fd.close()
Beispiel #4
0
def predict_games(t_teams, clf, outfile_fn, out):
    pred_fd = open(outfile_fn, 'w')    
    header = "id,pred\n"        
    pred_fd.write(header)
                   
    prediction_dict = {}
   
    # For producing submissions
    for season in t_teams:
        #print "Key : ",key
        t_teams[season].sort()
        
        game_vect = []
        
        # Begin with first team of season - iterate over all remaining
        while len(t_teams[season]) > 1 :
            lower_team = t_teams[season].pop(0)
            for opponent in t_teams[season] :
                # Predict percentage for 'lower team', or team with 
                this_game = vectorize(teams[lower_team].game_queue[season], teams[opponent].game_queue[season], 
                        teams[lower_team].wlp[season], teams[opponent].wlp[season])

                game_key = Game.create_game_str(season, lower_team, opponent)

                predict_probability = clf.predict_proba(this_game)
                predict_binary = clf.predict(this_game)

                prediction_dict[game_key] = Game(game_key, lower_team, opponent, predict_binary, predict_probability)
                
                pred_fd.write(prediction_dict[game_key].to_prediction())
                game_vect.append(this_game)
        print "Predictions for tournament season", season

    pred_fd.close()
    
    return prediction_dict