Machine Learning - Training And Testing
Tags: machinelearning, beginners, computerscience
Published: 2020-02-10 15:40:14

---
title: Machine Learning - Training And Testing
published: true
description: Machine Learning studies
cover_image: https://i.ibb.co/gyDsXzP/0-hzqhs-KFIZNWJKhvq.jpg
tags: machinelearning, Beginners, Computer Science
series: Making Of Terminator
---
Hey there, 


When training a Machine Learning model, you always need to split your data set into at least two different partitions, 
<ul>
<li>The data you use for training</li> 
<li>The data you use for testing</li>
</ul>

As you recall,  
                                              
![details](https://i.ibb.co/YkfyFcM/training.png)    

We had a total of 70,000 examples in the Fashion MNIST Dataset. We split this into 
 <ul>
 <li>60,000 examples to use for training</li> 
 <li>10,000 to use for tests</li>
</ul>

 The reason is that once a neural network has been trained, on the training data set, we want to test it on data that it hasn't seen before, to see how well it performs. 


![details](https://media.giphy.com/media/1iTH1WIUjM0VATSw/giphy.gif)

 <code>Actually, it is kind of like taking an exam in school. Before you take the exam, you usually train yourself on the task, by studying examples</code>
Here are two exercises we might do to learn how to perform addition. 

![details](https://i.ibb.co/Khm8wfC/learning-addition.png)


  However, the test should not be on exactly the same exercises we studied. If that was the case, our strategy could be to memorize the exercises, instead of understanding how to perform addition in general. That's why the exam will have problems that you have never seen before. 

![details](https://i.ibb.co/tzGy1Pd/exam-test.png)

  In this way, it can be tested, if you have learned the general way of doing addition or not. The same happens with Machine Learning. 

![details](https://i.ibb.co/qxxqbw6/training-data.png)

When you train a Machine Learning Algorithm, you show it some data that is representative of the problem you're trying to solve. 
For Fashion MNIST, we want our neural network to be able to recognize 10 types of articles of clothing, such as sandals, t-shirts, and ankle boots, etc. 

We therefore train it with 60,000 images containing such items. 
Once the training is complete though, we want to test its performance on images he has never seen before. So we'll reserve 10,000 images for this purpose. <code> If we did not do this, we wouldn't know if the neural network has decided to memorize the images it saw during training, or if it has truly been able to understand the difference between these items of clothing.</code>
This is the reason why we always have a training set and a test set, when we do Machine Learning.

  <a href="https://medium.com/tensorflow/introducing-tensorflow-datasets-c7f01f7e19f3"> TensorFlow Datasets</a> provides a collection of datasets ready to use with TensorFlow.

Datasets are typically split into different subsets to be used at various stages of training and evaluation of the neural network. In this section we talked about:

<ul>
<li><code>Training Set</code>: The data used for training the neural network.</li>
<li><code>Test set</code>: The data used for testing the final performance of our neural network.</li>
</ul>

The test dataset was used to try the network on data it has never seen before. This enables us to see how the model generalizes beyond what it has seen during training, and that it has not simply memorized the training examples.

In the same way, it is common to use what is called a <code>Validation dataset</code>.This dataset is not used for training. Instead, <code>it it used to test the model during training. This is done after some set number of training steps, and gives us an indication of how the training is progressing</code>. For example, if the loss is being reduced during training, but accuracy deteriorates on the validation set, that is an indication that the model is memorizing the test set.

The validation set is used again when training is complete to measure the final accuracy of the model.

You can read more about all this in the Training and Test Sets lesson of <a href="https://developers.google.com/machine-learning/crash-course/training-and-test-sets/video-lecture">Google’s Machine Learning Crash Course.</a>

We will see the difference between "Celsius" and "Fashion Mnist" in the next one.