1
I’ve researched, but I couldn’t quite understand what the benefit of using validation_data is. And it’s only used for test samples?
history = model.fit(X_train, Y_train, validation_data=(X_test, Y_test))
1
I’ve researched, but I couldn’t quite understand what the benefit of using validation_data is. And it’s only used for test samples?
history = model.fit(X_train, Y_train, validation_data=(X_test, Y_test))
2
The validation_data
It is only used for the test samples, it is not used to train the model. That is, it is not done backpropagation with this data. Its main function is to help find the point where your model is trained at the ideal point, without underfit (could have learned more) or overfit (learned more than he should).
In practice, be your model defined as:
model.compile(loss='mean_squared_error', optimizer=Adam(lr=0.0001), metrics=['accuracy'])
The test data is used to calculate, at the end of each season, the error and accuracy of your model.
Keeping these values for each season:
history = model.fit( x = X_train, y = y_train,
validation_data=(X_val, y_val),
[...]
)
The variable history.history
keeps the values of loss and accuracy of each season:
>>> history.history.keys()
dict_keys(['loss', 'accuracy', 'val_loss', 'val_accuracy'])
And you can view this data as follows:
import matplotlib.pyplot as plt
plt.plot(history.history['loss'], label='loss')
plt.plot(history.history['val_loss'], label='val_loss')
plt.title("Loss")
plt.legend(loc='best')
plt.show()
Or change the 'loss'
and 'val_loss'
for 'accuracy'
and 'val_accuracy'
.
Through these graphs, we were able to decide the best number of seasons to train the model, seeing when the value of the loss in the validation data (val_loss
) begins to grow and when accuracy in validation data (val_acc
) begin to decrease.
Browser other questions tagged python keras
You are not signed in. Login or sign up in order to post.
The right would not be the val_loss smaller and the val_acc bigger and bigger?
– Ronaldo Souza
At the beginning of the training, yes. After several seasons, the model is skewed to the training data and, as a result, starts to miss the validation.
– AlexCiuffa