1

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) ```

arc31
  • 11
  • 2
  • What are you trying to do in that ā€œiā€ loop? – Dave Apr 19 '21 at 23:39
  • @Dave Generating random numbers and their squares and then adding them to the input and target arrays respectively. – arc31 Apr 19 '21 at 23:46

0 Answers0