From 2db99536014fa207982074b94702197fb7683dea Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 18 Sep 2025 19:18:43 +0000 Subject: [PATCH] Adding the initial neuralnet files --- main.py | 2 + neuralnet/nerulnetdata.py | 160 +++++++++++++++++++++++++++++++++++++ neuralnet/neuralnetwork.py | 26 ++++++ 3 files changed, 188 insertions(+) create mode 100644 neuralnet/nerulnetdata.py create mode 100644 neuralnet/neuralnetwork.py diff --git a/main.py b/main.py index f63fc0e..87ebfb5 100644 --- a/main.py +++ b/main.py @@ -26,6 +26,8 @@ if __name__ == '__main__': for game in all_games: game_result, training_data = pull_training_data(db_conn, str(game[0]), game[1], game[2]) + + """ build_db_path = "./data/sql/build_db.sql" fill_parks_path = "./data/sql/prefill_parks.sql" diff --git a/neuralnet/nerulnetdata.py b/neuralnet/nerulnetdata.py new file mode 100644 index 0000000..f9848e6 --- /dev/null +++ b/neuralnet/nerulnetdata.py @@ -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 + +""" \ No newline at end of file diff --git a/neuralnet/neuralnetwork.py b/neuralnet/neuralnetwork.py new file mode 100644 index 0000000..7b6c502 --- /dev/null +++ b/neuralnet/neuralnetwork.py @@ -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) \ No newline at end of file