I don't get why it is so hard to get my neural network to learn such a simple function. I've tried all sorts of combinations of layer numbers, number of neurons but it doesn't seem to want to learn. Any suggestions would be greatly appreciated! Here is my code:
import numpy as np
import numpy
from tensorflow import keras
from tensorflow.keras import layers
import random
inputs = keras.Input(shape=(1,))
dense = layers.Dense(50, activation="relu")
x = dense(inputs)
x = layers.Dense(50, activation="relu")(x)
x = layers.Dense(50, activation="relu")(x)
x = layers.Dense(50, activation="relu")(x)
x = layers.Dense(50, activation="relu")(x)
outputs = layers.Dense(1)(x)
model = keras.Model(inputs=inputs, outputs=outputs, name="kinetic_energy")
adam = keras.optimizers.Adam(lr=0.0002,beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False,)
model.compile(
loss='mean_squared_error',
optimizer='adam',
metrics=["mean_squared_error"],
)
for j in range(10):
x = np.array([])
y = np.array([])
for i in range(1000):
randint = random.randint(0, 10000)
square = randint * randint
x = numpy.append(x, randint)
y = numpy.append(y, square)
model.fit(x, y, epochs = 100)
x = np.array([20])
z = model.predict(x)
print (z)
```