Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras - What is the difference between model.evaluate() and model.predict()

Tags:

keras

I have two questions :

1/ What is the difference between model.evaluate() and model.predict() ?

2/ How does Keras calculate each one of them ?

like image 704
Mejdi Dallel Avatar asked Jan 30 '23 20:01

Mejdi Dallel


2 Answers

model.evaluate predicts values and computes the loss and all attached metrics to the model over a given dataset. It returns a list containing the loss and metrics in one value.

model.predict only predicts the output of the model given inputs from a dataset. model.predict's inner workings are used inside model.evaluate, but the output of both is different, as they do not compute the same thing.

like image 166
Dr. Snoopy Avatar answered Jun 01 '23 19:06

Dr. Snoopy


I am going for model.predict in beginning as model.predict is executed inside model.evaluate. model.predict only predict the output matrix on the basis of the test set as the model directs.

However, model.evaluate performs a model.predict operation internally and calculate the errors and accuracy depending on supplied parameters at the time of of model compilation. For example

model.compile(optimizer=OPTIMIZER, loss='categorical_crossentropy',  metrics=['mse','mae','accuracy'])

Here I have asked model to supply output mse, mae, and accuracy. But it will not provide anything if we execute model.predictexcept output matrix, and then with respect to output we need to calculate error or accuracy. On the other hand, model.evaluate is a compact version which will calculate mse, mae, and accuracy all together and will provide a matrix like

[0.2498760256045422,0.015400263790238618,,0.9456890699253224]

It's similar like [mse, mae, accuracy]

Call is yours, anything you can pickup.

like image 35
gdmanandamohon Avatar answered Jun 01 '23 21:06

gdmanandamohon