# How tensorflow understand accuracy and loss of training data?

Code :-

models = keras.Sequential(
[
keras.Input(shape=(28*28)),
layers.Dense(512,activation = 'relu'),
layers.Dense(256,activation = 'relu'),
layers.Dense(10),
]
)

models.compile(
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics = ["accuracy"]
)

models.fit(x_train,y_train,batch_size=32,epochs=5,verbose=2)


Output:-

Epoch 1/5
1875/1875 - 8s - loss: 0.1854 - accuracy: 0.9450
Epoch 2/5
1875/1875 - 11s - loss: 0.0790 - accuracy: 0.9760
Epoch 3/5
1875/1875 - 7s - loss: 0.0561 - accuracy: 0.9822
Epoch 4/5
1875/1875 - 6s - loss: 0.0423 - accuracy: 0.9865
Epoch 5/5
1875/1875 - 6s - loss: 0.0329 - accuracy: 0.9893

<tensorflow.python.keras.callbacks.History at 0x7efda0e109a0>


While learning TensorFlow, My first doubt was what is accuracy and loss? By google, I Learned:- Loss value implies how poorly or well a model behaves after each iteration of optimization. An accuracy metric is used to measure the algorithm's performance in an interpretable way. The accuracy of a model is usually determined after the model parameters and is calculated in the form of a percentage.

But my doubt is how TF knows about accuracy as we pass only training data, not Test Data. To calculate accuracy I think test data needed. Is TF split train data into another train and test data?

• "To calculate accuracy I think test data needed" - this is just wrong; depending on the dataset used, there is the training accuracy and the test (or validation) accuracy, and what TF reports here is obviously the former. Had you passed also a validation set to model.fit(), you would get two more reported quantities, val_loss and val_accuracy in the output. Feb 13, 2021 at 12:52