def brier(model, surface, sy, ey, ts, r):
    matches = db_conn.all_matches_year(sy, ey, surface)
    c = 0
    prob = 0
    for match in matches:
        end_date = match[3] + datetime.timedelta(days=-1)
        start_date = end_date + datetime.timedelta(days=-r)
        if not Player.end_year == end_date.__str__():
            Player.start_year = start_date.__str__()
            Player.end_year = end_date.__str__()
            Player.surface = surface
            Player.clean_cached_players()

        p = Prediction(match[0], match[1], model, bo=3, ts=ts)
        p.predict_set_score()

        pbp = match[5]
        pbp = pbp.split('.')
        actual_length = 0
        for pbp_ in pbp:
            actual_length += pbp_.split(';').__len__()

        if p.match_winner_prob['p1'] > 1 or p.match_winner_prob['p1'] < 0:
            continue
        if not np.isnan(p.match_winner_prob['p1']):
            c += 1
            prob += (p.match_length_mean - actual_length)**2

    return [c, prob]
Example #2
0
def brier(models, surface, sy, ey, ts, r):
    matches = db_conn.all_matches_year(sy, ey, surface)
    rs = {}
    for model in models:
        rs[model] = [0, 0, 0]

    for match in matches:
        end_date = match[3] + datetime.timedelta(days=-1)
        start_date = end_date + datetime.timedelta(days=-r)
        if not Player.end_year == end_date.__str__():
            Player.start_year = start_date.__str__()
            Player.end_year = end_date.__str__()
            Player.surface = surface
            Player.clean_cached_players()

        for model in models:
            p = Prediction(match[0], match[1], model, bo=3, ts=ts)
            p.predict_set_score()

            if p.match_winner_prob['p1'] > 1 or p.match_winner_prob['p1'] < 0:
                print p.match_winner_prob['p1']
                continue
            if not np.isnan(p.match_winner_prob['p1']):
                rs[model][0] += 1
                if match[2] == 1:
                    if p.match_winner_prob['p1'] > 0.5:
                        rs[model][1] += 1
                    rs[model][2] += (1 - p.match_winner_prob['p1'])**2
                else:
                    if p.match_winner_prob['p2'] > 0.5:
                        rs[model][1] += 1
                    rs[model][2] += (1 - p.match_winner_prob['p2'])**2

    return rs
Example #3
0
def brier(model, surface, sy, ey, mixture, ts):
    matches = db_conn.all_matches_year(sy, ey, surface)
    c = 0
    prob = 0
    right = 0
    for match in matches:
        end_date = match[3] + datetime.timedelta(days=-1)
        start_date = end_date + datetime.timedelta(days=-365)
        if not Player.end_year == end_date.__str__():
            Player.start_year = start_date.__str__()
            Player.end_year = end_date.__str__()
            Player.surface = surface
            Player.clean_cached_players()

        p = PredictionSetend(match[0],
                             match[1],
                             model,
                             points_played=match[5],
                             mixture=mixture,
                             ts=ts)
        p.predict_set_score()
        # print p.match_winner_prob['p1'], p.match_winner_prob['p2'], match
        if not np.isnan(p.match_winner_prob['p1']):
            c += 1
            if match[2] == 1:
                if p.match_winner_prob['p1'] > 0.5:
                    right += 1
                prob += (1 - p.match_winner_prob['p1'])**2
            else:
                if p.match_winner_prob['p2'] > 0.5:
                    right += 1
                prob += (1 - p.match_winner_prob['p2'])**2

    return [c, right, prob]
Example #4
0
def brier(model, surface, sy, ey, ts, r):
    matches = db_conn.all_matches_year(sy, ey, surface)
    c = 0
    prob = 0
    right = 0
    for match in matches:
        end_date = match[3] + datetime.timedelta(days=-1)
        start_date = end_date + datetime.timedelta(days=-r)
        if not Player.end_year == end_date.__str__():
            Player.start_year = start_date.__str__()
            Player.end_year = end_date.__str__()
            Player.surface = surface
            Player.clean_cached_players()

        winner = match[2]
        score = match[4]
        set_length = score.split().__len__()

        ms = ''
        if winner == 1:
            if set_length == 3:
                ms = '2:1'
            else:
                ms = '2:0'
        else:
            if set_length == 3:
                ms = '1:2'
            else:
                ms = '0:2'

        p = Prediction(match[0], match[1], model, bo=3, ts=ts)
        p.predict_set_score()

        ms_20 = p.match_score_prob['2:0']
        ms_21 = p.match_score_prob['2:1']
        ms_02 = p.match_score_prob['0:2']
        ms_12 = p.match_score_prob['1:2']

        if not np.isnan(p.match_winner_prob['p1']):
            c += 1
            prob += (1 - p.match_score_prob[ms])**2
            if ms == '2:0' and ms_20 >= ms_21 and ms_20 >= ms_02 and ms_20 >= ms_12:
                right += 1
            if ms == '2:1' and ms_21 >= ms_20 and ms_21 >= ms_02 and ms_21 >= ms_12:
                right += 1
            if ms == '1:2' and ms_12 >= ms_21 and ms_12 >= ms_02 and ms_12 >= ms_20:
                right += 1
            if ms == '0:2' and ms_02 >= ms_20 and ms_02 >= ms_21 and ms_02 >= ms_12:
                right += 1

    return [c, right, prob]
Example #5
0
Player.surface = 'hard'

match_baseline_s = []
match_impact_s = []
set_baseline_s = []
set_impact_s = []

match_baseline_r = []
match_impact_r = []
set_baseline_r = []
set_impact_r = []


Player.end_year = '2012-12-31'
Player.start_year = '2012-01-01'
Player.clean_cached_players()
p = Player(player)
Player.calculate_all_ts()

match_baseline_s.append(p.match_baseline_ts.serv_mean)
match_impact_s.append(p.match_impact_ts.serv_mean)
set_baseline_s.append(p.set_baseline_3_ts[set_level].serv_mean)
set_impact_s.append(p.set_impact_3_ts[set_level].serv_mean)

match_baseline_r.append(p.match_baseline_ts.retn_mean)
match_impact_r.append(p.match_impact_ts.retn_mean)
set_baseline_r.append(p.set_baseline_3_ts[set_level].retn_mean)
set_impact_r.append(p.set_impact_3_ts[set_level].retn_mean)

Player.end_year = '2013-12-31'
Player.start_year = '2013-01-01'