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