def one_match_simulator(
    home_goalkeeper,
    home_defenders,
    home_midfielders,
    home_forwards,
    away_goalkeeper,
    away_defenders,
    away_midfielders,
    away_forwards,
    model_name='/Users/bgrantham/Documents/Personal/fifa-ratings-predictor/fifa_ratings_predictor'
    '/deep-models'
    '-all/deep'):
    home_defenders = home_defenders + [0] * (6 - len(home_defenders))
    away_defenders = away_defenders + [0] * (6 - len(away_defenders))
    home_midfielders = home_midfielders + [0] * (7 - len(home_midfielders))
    away_midfielders = away_midfielders + [0] * (7 - len(away_midfielders))
    home_forwards = home_forwards + [0] * (4 - len(home_forwards))
    away_forwards = away_forwards + [0] * (4 - len(away_forwards))

    home_feature_vector = home_goalkeeper + home_defenders + home_midfielders + home_forwards
    away_feature_vector = away_goalkeeper + away_defenders + away_midfielders + away_forwards

    feature_vector = normalise_features(
        np.array(home_feature_vector + away_feature_vector)).reshape(1, 36)

    net = NeuralNet()
    probability = net.predict(feature_vector, model_name)

    return probability[0]
Exemplo n.º 2
0
    def get_match_probabilities(self, match_fixtures, verbose=False):
        feature_vectors = []

        net = NeuralNet()

        for fixture in tqdm(match_fixtures,
                            desc='Getting match probabilities...',
                            disable=not verbose):
            home_team, away_team = fixture['home team'], fixture['away team']
            feature_vectors.append(
                np.hstack((self.predicted_lineups[home_team],
                           self.predicted_lineups[away_team])).reshape(
                               (1, 36)))

        predictions = net.predict(np.vstack((x for x in feature_vectors)),
                                  model_name=self.model_path)

        match_probabilities = [x for x in predictions]

        return match_probabilities
Exemplo n.º 3
0
def one_match_simulator(home_goalkeeper, home_defenders, home_midfielders, home_forwards, away_goalkeeper,
                        away_defenders, away_midfielders, away_forwards,
                        model_name='/Users/offera/Desktop/Personal Projects/betPredictor/pl-predictions-using-fifa/fifa_ratings_predictor'
                                   '/models/E0'
                                   '/deep'):
    home_defenders = home_defenders + [0] * (6 - len(home_defenders))
    away_defenders = away_defenders + [0] * (6 - len(away_defenders))
    home_midfielders = home_midfielders + [0] * (7 - len(home_midfielders))
    away_midfielders = away_midfielders + [0] * (7 - len(away_midfielders))
    home_forwards = home_forwards + [0] * (4 - len(home_forwards))
    away_forwards = away_forwards + [0] * (4 - len(away_forwards))

    home_feature_vector = home_goalkeeper + home_defenders + home_midfielders + home_forwards
    away_feature_vector = away_goalkeeper + away_defenders + away_midfielders + away_forwards

    feature_vector = normalise_features(np.array(home_feature_vector + away_feature_vector)).reshape(1, 36)

    net = NeuralNet()
    probability = net.predict(feature_vector, model_name)

    return probability[0]
Exemplo n.º 4
0
def main():
    bet_tracker = BetTracker()

    league = 'E0'

    match_data = read_match_data(season='2016-2017', league=league)

    match_data = assign_odds_to_match(match_data, read_all_football_data(league=league))

    player_data = read_player_data(season='2016-2017')

    net = NeuralNet()

    bank = [100]

    all_odds = []

    errors = []

    cached_players = {}

    feature_vectors = []

    for match in match_data:

        try:

            home_players_matched, cached_players = match_lineups_to_fifa_players(match['info']['home lineup names'],
                                                                                 match['info']['home lineup raw names'],
                                                                                 match['info']['home lineup numbers'],
                                                                                 match['info'][
                                                                                     'home lineup nationalities'],
                                                                                 constants.LINEUP_TO_PLAYER_TEAM_MAPPINGS[
                                                                                     'ALL'][
                                                                                     match['info']['home team']],
                                                                                 match['info']['season'],
                                                                                 player_data, cached_players)

            away_players_matched, cached_players = match_lineups_to_fifa_players(match['info']['away lineup names'],
                                                                                 match['info']['away lineup raw names'],
                                                                                 match['info']['away lineup numbers'],
                                                                                 match['info'][
                                                                                     'away lineup nationalities'],
                                                                                 constants.LINEUP_TO_PLAYER_TEAM_MAPPINGS[
                                                                                     'ALL'][
                                                                                     match['info']['away team']],
                                                                                 match['info']['season'],
                                                                                 player_data, cached_players)

            home_feature_vector = create_feature_vector_from_players(home_players_matched)
            away_feature_vector = create_feature_vector_from_players(away_players_matched)

            feature_vector = np.array(home_feature_vector + away_feature_vector).reshape(-1, 36)

            feature_vectors.append(normalise_features(feature_vector))

        except Exception as exception:
            print(match['info']['date'], match['info']['home team'], match['info']['away team'])
            print(exception)
            errors.append(match['match number'])

    feature_vectors = np.vstack((x for x in feature_vectors))

    probabilities = net.predict(feature_vectors, model_name='./models/' + league + '/deep')

    match_data = [match for match in match_data if match['match number'] not in errors]

    for match, probability in zip(match_data, probabilities):

        # print(match['info']['date'], match['info']['home team'], match['info']['away team'])

        pred_home_odds, pred_draw_odds, pred_away_odds = [1 / x for x in probability]

        home_odds, draw_odds, away_odds = match['info']['home odds'], match['info']['draw odds'], match['info'][
            'away odds']

        all_odds.append((pred_home_odds, home_odds))
        all_odds.append((pred_away_odds, away_odds))

        if pred_home_odds < home_odds < 3.2 and 0.02 <= probability[0] - 1 / home_odds:
            stake = calculate_stake(home_odds, probability=1 / pred_home_odds, method='kelly',
                                    constant_profit=20) * bet_tracker.bankroll
            profit = stake * home_odds - stake
            bet = Bet(true_odds=home_odds, predicted_odds=pred_home_odds, stake=stake, profit=profit, match=match,
                      type='home')
            bet_tracker.make_bet(bet)
            if match['info']['home goals'] > match['info']['away goals']:
                bet_tracker.bet_won()
            else:
                bet_tracker.bet_lost()
            bank.append(bet_tracker.bankroll)
        elif pred_away_odds < away_odds < 3.2 and 0.02 <= probability[2] - 1 / away_odds:
            stake = calculate_stake(away_odds, probability=1 / pred_away_odds, method='kelly',
                                    constant_profit=20) * bet_tracker.bankroll
            profit = stake * away_odds - stake
            bet = Bet(true_odds=away_odds, predicted_odds=pred_away_odds, stake=stake, profit=profit, match=match,
                      type='away')
            bet_tracker.make_bet(bet)
            if match['info']['home goals'] < match['info']['away goals']:
                bet_tracker.bet_won()
            else:
                bet_tracker.bet_lost()
            bank.append(bet_tracker.bankroll)

    return bet_tracker, bank, all_odds