Initial setup for training
This commit is contained in:
56
main.py
56
main.py
@@ -1,11 +1,16 @@
|
||||
import numpy as np # helps with the math
|
||||
import matplotlib.pyplot as plt # to plot error during training
|
||||
import tensorflow as tf
|
||||
|
||||
from data.get_data import pull_training_data
|
||||
from rich.progress import Progress
|
||||
|
||||
from data.get_data import pull_training_data, normalize_training_data
|
||||
from data.db_connect import Database
|
||||
from data.build_weather import get_weather, get_sun_and_moon_phase
|
||||
from data.stats_importer import Importer
|
||||
|
||||
from neuralnet.neuralnetwork import NeuralNetwork
|
||||
|
||||
# input data
|
||||
inputs = np.array([[0, 0, 1, 0],
|
||||
[0, 0, 1, 1],
|
||||
@@ -23,13 +28,54 @@ if __name__ == '__main__':
|
||||
query = "SELECT game_date, game_number, park_id FROM games ORDER BY game_date"
|
||||
all_games = db_conn.selectall(query)
|
||||
|
||||
for game in all_games:
|
||||
game_result, training_data = pull_training_data(db_conn, str(game[0]), game[1], game[2])
|
||||
|
||||
compiled_training_data = None
|
||||
compiled_training_results = None
|
||||
|
||||
with Progress() as p_bar:
|
||||
p_bar_val = p_bar.add_task("Getting Data ...", total=len(all_games))
|
||||
for game in all_games:
|
||||
p_bar.update(p_bar_val, advance=1)
|
||||
game_result, training_data = pull_training_data(db_conn, str(game[0]), game[1], game[2])
|
||||
|
||||
training_data = normalize_training_data(training_data)
|
||||
|
||||
if compiled_training_results is None:
|
||||
compiled_training_data = np.array([training_data])
|
||||
compiled_training_results = np.array([game_result])
|
||||
else:
|
||||
compiled_training_data = np.append(compiled_training_data, np.array([training_data]), axis=0)
|
||||
compiled_training_results = np.append(compiled_training_results, np.array([game_result]), axis=0)
|
||||
|
||||
ctd_len = len(compiled_training_data)
|
||||
ctr_len = len(compiled_training_results)
|
||||
|
||||
td = compiled_training_data[:ctd_len-100]
|
||||
tdt = compiled_training_data[ctd_len-100:]
|
||||
|
||||
tr = compiled_training_results[:ctr_len-100]
|
||||
trt = compiled_training_results[ctr_len-100:]
|
||||
|
||||
nn = NeuralNetwork(len(compiled_training_data[0]))
|
||||
nn.train(td, tr)
|
||||
nn.summary()
|
||||
predictions = nn.predict(np.array(tdt))
|
||||
|
||||
total_num = 0
|
||||
accurate_num = 0
|
||||
for pred, act in zip(predictions, trt):
|
||||
total_num += 1
|
||||
pred = round(pred[0] * 1000) / 1000.0
|
||||
guess = round(pred)
|
||||
print(f"Pred: {pred} -> Gue: {guess} -> Res: {act} -> Cor: {guess == act}")
|
||||
|
||||
accurate_num += int(guess==act)
|
||||
|
||||
print(f"Total: {total_num} -> Accu: {accurate_num} -> Perc: {accurate_num/total_num}")
|
||||
#for index in range(len(trt)):
|
||||
# print(f"pred: {nn.predict(np.array([tdt[index]]))} : act : {trt[index]}")
|
||||
|
||||
"""
|
||||
build_db_path = "./data/sql/build_db.sql"
|
||||
build_db_path = "./data/sql/build_db .sql"
|
||||
fill_parks_path = "./data/sql/prefill_parks.sql"
|
||||
fill_teams_path = "./data/sql/prefill_teams.sql"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user