def get_match_probabilities(match_fixtures): feature_vectors = [] net = NeuralNet() for fixture in tqdm(match_fixtures, desc='Getting match probabilities...'): home_team, away_team = fixture['home team'], fixture['away team'] feature_vectors.append( np.hstack((PREDICTED_LINEUPS[home_team], PREDICTED_LINEUPS[away_team])).reshape((1, 36))) predictions = net.predict(np.vstack((x for x in feature_vectors))) match_probabilities = [x for x in predictions] return match_probabilities
global is_drawing if event == cv2.EVENT_LBUTTONDOWN: if is_drawing: start_point = (x, y) elif event == cv2.EVENT_MOUSEMOVE: if is_drawing: end_point = (x, y) draw_line(canvas, start_point, end_point) start_point = end_point elif event == cv2.EVENT_LBUTTONUP: is_drawing = False cv2.namedWindow("Test Canvas") cv2.setMouseCallback("Test Canvas", on_mouse_events) while (True): cv2.imshow("Test Canvas", canvas) key = cv2.waitKey(1) & 0xFF if key == ord('q'): break elif key == ord('s'): is_drawing = True elif key == ord('c'): canvas[100:500, 100:500] = 0 elif key == ord('p'): image = canvas[100:500, 100:500] result = net.predict(image) print("PREDICTION : ", result) cv2.destroyAllWindows()
def main(): bet_tracker = BetTracker() match_data = read_match_data(season='2017-2018') player_data = read_player_data(season='2017-2018') net = NeuralNet() bank = [100] all_odds = [] for match in match_data: print(match['info']['date'], match['info']['home team'], match['info']['away team']) home_players_matched = match_lineups_to_fifa_players( match['info']['home lineup 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) away_players_matched = match_lineups_to_fifa_players( match['info']['away lineup 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) 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_vector = normalise_features(feature_vector) probabilities = net.predict(feature_vector) pred_home_odds, pred_draw_odds, pred_away_odds = [ 1 / x for x in probabilities[0] ] 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 <= probabilities[0][ 0] - 1 / home_odds: stake = calculate_stake(home_odds, probability=1 / pred_home_odds, method='kelly') * 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 <= probabilities[0][ 2] - 1 / away_odds: stake = calculate_stake(away_odds, probability=1 / pred_away_odds, method='kelly') * 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
elif event == cv2.EVENT_LBUTTONUP: is_drawing = False cv2.namedWindow("Test Canvas") cv2.setMouseCallback("Test Canvas", on_mouse_events) counter = 0 while (True): cv2.imshow("Test Canvas", canvas) key = cv2.waitKey(1) & 0xFF if counter == 0: print( "Press <q> to exit, <p> to predict, <c> to clear, <mouse left> to draw" ) counter = 1 if key == ord('q'): break elif key == ord('c'): canvas[100:500, 100:500] = 0 elif key == ord('p'): image = canvas[100:500, 100:500] result_cnn = net.predict(image) result_rnn = net.predict_rnn(image) print("CNN PREDICTION : ", result_cnn) print("RNN PREDICTION : ", result_rnn) cv2.destroyAllWindows()
with our neural network """ import numpy as np from model import NeuralNet from generate_data import inputs, labels # Min is 1 and max is 1024 first = 101 last = 1024 X = inputs(first, last) y = labels(first, last) model = NeuralNet(input_shape=(10, )) model.compile(lr=0.001) model.train(X, y, batch_size=32, epochs=1000) first_test = 1 last_test = 100 X_test = inputs(first_test, last_test) y_pred = model.predict(X_test) iter = range(first_test, last_test + 1) for i in range(last_test - first_test + 1): if y_pred[i] == 0: pred = i + 1 elif y_pred[i] == 1: pred = "fizz" elif y_pred[i] == 2: pred = "buzz" else: pred = "fizzbuzz" print("{}: {}".format(i + 1, pred))