-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNeuralNetwork.py
More file actions
27 lines (22 loc) · 900 Bytes
/
Copy pathNeuralNetwork.py
File metadata and controls
27 lines (22 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import tensorflow as tf
from keras import layers
import random
# Training data
randInt = random.randint(0,1)
x_train = [[randInt, randInt], [randInt, randInt], [randInt, randInt], [randInt, randInt]]
y_train = [[randInt], [randInt], [randInt], [randInt]]
# Validation data
x_val = [[1, 1], [1, 1], [1, 1], [1, 1]]
y_val = [[1], [1], [1], [1]]
# Define the neural network architecture
model = tf.keras.Sequential([
layers.Dense(32, activation='relu', input_shape=(2,)),
layers.Dense(16, activation='sigmoid', input_shape=(2,)),
layers.Dense(1)
])
# Compile the model with the loss function, optimizer, and metrics
model.compile(optimizer=tf.keras.optimizers.Adam(0.001),
loss=tf.keras.losses.BinaryCrossentropy(from_logits=False),
metrics=['accuracy'])
# Train the model on the training data
model.fit(x_train, y_train, epochs=50, validation_data=(x_val, y_val))