Skip to content

Commit

Permalink
Merge pull request #12 from KOSASIH/deepsource-transform-7b23a73a
Browse files Browse the repository at this point in the history
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
  • Loading branch information
KOSASIH authored May 11, 2024
2 parents c5a058f + 52b2a2e commit 5b720c8
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions models/ai_models/neural_networks.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 5b720c8

Please sign in to comment.