I have been trying to adjust a neural network to a simple function: the mass of an sphere. I have tried with different architectures, for example, a single hidden layer and two hidden layers, always with 128 neurons each, and training them for 5000 epochs. The code is the usual one. Just in case, I publish one of them
model = keras.Sequential([keras.layers.Dense(units=1, input_shape=) ,keras.layers.Dense(128, activation="relu") ,keras.layers.Dense(1, activation="relu")]) model.compile(optimizer='rmsprop', loss='mse', metrics=['mae']) history = model.fit(x, y, validation_split=0.2, epochs=5000)
The results are shown in the graphs.
I suspect that I am making an error somewhere, because I have seen that deep learning is able to match complex functions with much less epochs. I shall appreciate any hint to fix this problem and obtain a good fit with the deep learning function.
In order to make it clear I post the graph's code.
rs =[x for x in range(20)] def masas_circulo(x): masas_circulos = rs =[r for r in range(x)] for r in rs: masas_circulos.append(model.predict([r])) return masas_circulos masas_circulos = masas_circulo(20) masas_circulos esferas = [4/3*np.pi*r**3 for r in range(20)] import matplotlib.pyplot as plt plt.plot(rs,masas_circulos,label="DL") plt.plot(rs,esferas,label="Real"); plt.title("Mass of an sphere.\nDL (1hl,128 n,5000 e) vs ground_truth") plt.xlabel("Radius") plt.ylabel("Sphere") plt.legend();