# How can Tensorflow be used to evaluate both the models on test data using Python?

PythonServer Side ProgrammingProgramming

Tensorflow is a machine learning framework that is provided by Google. It is an open-source framework used in conjunction with Python to implement algorithms, deep learning applications, and much more. It is used in research and for production purposes.

The ‘tensorflow’ package can be installed on Windows using the below line of code −

pip install tensorflow

Tensor is a data structure used in TensorFlow. It helps connect edges in a flow diagram. This flow diagram is known as the ‘Data flow graph’. Tensors are nothing but a multidimensional array or a list.

We are using Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero configuration and free access to GPUs (Graphical Processing Units). Colaboratory has been built on top of Jupyter Notebook.

## Example

Following is the code snippet −

print("The model is being evaluated")
binary_loss, binary_accuracy = binary_model.evaluate(binary_test_ds)
int_loss, int_accuracy = int_model.evaluate(int_test_ds)

print("The accuracy of Binary model is: {:2.2%}".format(binary_accuracy))
print("The accuracy of Int model is: {:2.2%}".format(int_accuracy))

## Output

The model is being evaluated
250/250 [==============================] - 3s 12ms/step - loss: 0.5265 - accuracy: 0.8110
250/250 [==============================] - 4s 14ms/step - loss: 0.5394 - accuracy: 0.8014
The accuracy of Binary model is: 81.10%
The accuracy of Int model is: 80.14%

## Explanation

• The loss and accuracy associated with training for both the ‘binary’ and ‘int’ vectorized model is evaluated.

• This data is displayed on the console.

Published on 19-Jan-2021 07:33:58