WIP: Train the AI #15

Draft
paul wants to merge 2 commits from 6-train-ai into main
3 changed files with 188 additions and 0 deletions
Showing only changes of commit 2db9953601 - Show all commits

View File

@@ -26,6 +26,8 @@ if __name__ == '__main__':
for game in all_games: for game in all_games:
game_result, training_data = pull_training_data(db_conn, str(game[0]), game[1], game[2]) game_result, training_data = pull_training_data(db_conn, str(game[0]), game[1], game[2])
""" """
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_parks_path = "./data/sql/prefill_parks.sql"

160
neuralnet/nerulnetdata.py Normal file
View File

@@ -0,0 +1,160 @@
"""
Data to use:
Previous Game 2
game_date
day_of_week
day_night
park
length_in_minutes
score
line_score
at_bats
hits
doubles
triples
homeruns
rbis
sacrifice_hits
sacrifice_flies
hit_by_pitch
walks
intentional_walks
strikeouts
stolen_bases
caught_stealing
grounded_double
interference
left_on_base
pitchers_used
individual_earned_runs
earned_runs
wild_pitches
assits
errors
double_play
triple_play
starting_1_id
starting_1_position
starting_2_id
starting_2_position
starting_3_id
starting_3_position
starting_4_id
starting_4_position
starting_5_id
starting_5_position
starting_6_id
starting_6_position
starting_7_id
starting_7_position
starting_8_id
starting_8_position
starting_9_id
starting_9_position
Previous Game 1
game_date
day_of_week
day_night
park
length_in_minutes
score
line_score
at_bats
hits
doubles
triples
homeruns
rbis
sacrifice_hits
sacrifice_flies
hit_by_pitch
walks
intentional_walks
strikeouts
stolen_bases
caught_stealing
grounded_double
interference
left_on_base
pitchers_used
individual_earned_runs
earned_runs
wild_pitches
assits
errors
double_play
triple_play
starting_1_id
starting_1_position
starting_2_id
starting_2_position
starting_3_id
starting_3_position
starting_4_id
starting_4_position
starting_5_id
starting_5_position
starting_6_id
starting_6_position
starting_7_id
starting_7_position
starting_8_id
starting_8_position
starting_9_id
starting_9_position
Predicted Game
game_date
day_of_week
day_night
park_id
home_plate_ump_id
b1_ump_id
b2_ump_id
b3_ump_id
lf_fence_distance
lf_fence_height
ct_fence_distance
ct_fence_height
rf_fence_distance
rf_fence_height
has_roof
latitude
longitude
elevation
starting_1_id
starting_1_position
starting_2_id
starting_2_position
starting_3_id
starting_3_position
starting_4_id
starting_4_position
starting_5_id
starting_5_position
starting_6_id
starting_6_position
starting_7_id
starting_7_position
starting_8_id
starting_8_position
starting_9_id
starting_9_position
temperature
humidity
dew_point
apparent_temperature
air_pressure
percipitation
rain
snowfall
cloud_cover
wind_speed
wind_direction
wind_gusts
sun_rise
sun_set
moon_phase
"""

View File

@@ -0,0 +1,26 @@
import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
# create NeuralNetwork class
class NeuralNetwork:
def __init__(self, inputs_len: int):
# Setup checkpoint
self.checkpoint_path = "./training/cp.ckpt"
self.cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_path, save_weights_only=True, verbose=1)
# Setup model
self.model = Sequential()
self.model.add(Dense(12, input_shape=(inputs_len,), activation='relu'))
self.model.add(Dense(8, activation='relu'))
self.model.add(Dense(1, activation='sigmoid'))
self.model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
if os.path.isfile(self.checkpoint_path):
self.model.load_weights(self.checkpoint_path)
def train(inputs :list, outputs :list):
self.model.fit(inputs, outputs, epochs=150, batch_size=10, callbacks=[self.cp_callback])
def predict(self, new_input):
return self.model.predict(new_input)