From 52b2a2e697b20af2bc93ec85f77ef5785b47d9a5 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Sat, 11 May 2024 07:05:06 +0000 Subject: [PATCH] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 918e5b0 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- models/ai_models/neural_networks.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/models/ai_models/neural_networks.py b/models/ai_models/neural_networks.py index ff533b5..e5e0f67 100644 --- a/models/ai_models/neural_networks.py +++ b/models/ai_models/neural_networks.py @@ -1,9 +1,11 @@ # Import necessary libraries import tensorflow as tf -from tensorflow import keras from sklearn.preprocessing import StandardScaler +from tensorflow import keras # Define a class for neural networks + + class NeuralNetwork: def __init__(self, input_shape, output_shape, hidden_layers): self.input_shape = input_shape @@ -16,14 +18,22 @@ def _create_model(self): model = keras.Sequential() model.add(keras.layers.InputLayer(input_shape=self.input_shape)) for layer in self.hidden_layers: - model.add(keras.layers.Dense(layer, activation='relu')) - model.add(keras.layers.Dense(self.output_shape, activation='softmax')) - model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']) + model.add(keras.layers.Dense(layer, activation="relu")) + model.add(keras.layers.Dense(self.output_shape, activation="softmax")) + model.compile( + optimizer="adam", loss="categorical_crossentropy", metrics=["accuracy"] + ) return model def train(self, X_train, y_train, X_test, y_test): # Train the neural network model - self.model.fit(X_train, y_train, epochs=10, batch_size=128, validation_data=(X_test, y_test)) + self.model.fit( + X_train, + y_train, + epochs=10, + batch_size=128, + validation_data=(X_test, y_test), + ) def predict(self, X): # Make predictions using the trained model @@ -34,7 +44,10 @@ def evaluate(self, X_test, y_test): loss, accuracy = self.model.evaluate(X_test, y_test) return accuracy + # Define a function to load a neural network model + + def load_neural_network(model_path): # Load the neural network model from a file model = tf.keras.models.load_model(model_path)