def buildModel(optimizer):
model = tf.keras.models.Sequential([
Dense(100, activation = 'relu'),
Dense(82, activation = 'relu'),
Dense(20, activation = 'relu'),
Dense(6, activation = 'relu'),
Dense(20, activation = 'softmax')
])
model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics=['accuracy'])
return model
tf.keras.optimizers.legacy.Adam()
model = buildModel('adam')
history = model.fit(train_x,train_y_lst, validation_data=(test_x, test_y_lst),epochs = 50,batch_size = 32,verbose = 0)
Plotting
plt.figure()
plt.plot(history.history['loss'], label='Training Loss')
plt.plot(history.history['val_loss'], label='Validation Loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.title('Training and Validation Loss Curves')
plt.legend()
# Plot training and validation accuracy
plt.figure()
plt.plot(history.history['accuracy'], label='Training Accuracy')
plt.plot(history.history['val_accuracy'], label='Validation Accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.title('Training and Validation Accuracy Curves')
plt.legend()
plt.show()
Accuracy for test is also bad
Any suggestions where i may be going wrong, I am new?
I was expecting for test loss to decrease just like train loss.
My test_x lookes like this
-0.84335711]
[-0.1898388 -1.4177287 0.24718753 ... -0.33010045 0.77921928
-1.56813293]
[ 0.51887204 -1.34965479 0.19069737 ... 0.56236361 -0.03741466
-0.24596578]
...
[-0.11631875 0.46366703 -1.04400684 ... 0.23282911 -2.10649511
-0.41883463]
[-1.03632829 0.05419996 -2.22371652 ... 0.47133847 -1.70391277
-1.42387687]
[-0.12011524 -0.72294703 -0.74587529 ... 0.11331488 -1.81362912
-0.11828704]]
test_y_lst
array([[1, 0, 0, ..., 0, 0, 0],
[1, 0, 0, ..., 0, 0, 0],
[1, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]])
Multi classification problem.
Since it looks like that you are new to the concept, I will tell you some ways you can improve your result here or in general using NeuralNets.
Your model is overfitting to the input train data. to avoid:
for start try to scale your input data between (0,1) and use dropout for one or two of your layers and see the result.