Deep Learning with Keras
Transcript
Hey, I'm Andy from deep lizard. And in this course, we're going to learn how to use Kerris, and neural network API written in Python and integrated with TensorFlow. Throughout the course, each lesson will focus on a specific deep learning concept, and show the full implementation in code using the keras API. We'll be starting with the absolute basics of learning how to organize and pre processed data, and then we'll move on to building and training our own artificial neural networks.
And some of these networks will be built from scratch, and others will be pre trained and state of the art models for which we'll fine tune to use on our own custom data sets. Now let's discuss the prerequisites needed to follow along with this course. From a knowledge standpoint, we'll give brief introductions of each deep learning concept that we are going to work with before we go through the code implementation. But if you're an absolute beginner to deep learning, then we first recommend you go through the deep learning fundamentals scores on the tables or Comm. Or if you're super eager to jump into the code, then you can simultaneously take this course and the deep learning fundamentals course, the deep learning fundamentals course will give you all the knowledge you need to know to get acquainted with major deep learning
concepts for which then you can come back and implement and code using the keras API. And this course, in regard to coding prerequisites, just some basic programming skills and some Python experience or all that's needed. On peoples.com. You can also find the deep learning learning path. So you can see where this Kerris course falls amidst all the deep lizard deep learning content. Now let's discuss the Course Resources. So aside from the videos here on YouTube, you will also have video and text resources available on peoples are calm. And actually each episode has its own corresponding blog and a quiz available for you to take and test your own knowledge. And you can actually contribute your own quiz questions as well. And you can see how to do that on the corresponding blog for each episode. Additionally, all of the code resources used in this course, are regularly tested and maintained,
including updates and bug fixes when needed. Download access to code files used in this course, are available to members of the deep lizard hive mind. So you can check out more about that on tables or calm as well. Alright, so now that we know what this course is about, and what resources we have available, along with the prerequisites needed to get started, let's now talk a little bit more about Kerris itself. Kerris was developed with a focus on enabling fast user experimentation. So this allows us to go from idea to implementation and very few steps. Aside from this benefit, users often wonder why choose Kerris as the neural network API to learn or in general, which neural network API should they learn? Our general advice is to not commit yourself just to only learning one and sticking with that one forever, we recommend to learn multiple neural network API's. And the idea is that once you have a fundamental understanding of the underlying concepts,
then the minor syntactical and implementation differences between the neural network API's shouldn't really be that hard to catch on to once you have at least one under your belt already, especially for job prospects. Knowing more than one neural network API will show your experience and allow you to compare and contrast the differences between API's and share your opinions for why you think that certain API's may be better for certain problems, and others for other problems. Being able to demonstrate this will make you a much more valuable candidate. Now, we previously touched on the fact that Kerris is integrated with TensorFlow. So let's discuss that more. Now. Historically, Kerris was a high level neural network API that you could configure to run against one of three separate lower level API's. And those lower level API's were TensorFlow viano and cntk. Later, though, Kerris became fully integrated with the TensorFlow API, and is no longer
a separate library that you can choose to run against one of the three back end engines that we discussed previously. So it's important to understand that cares is now completely integrated with the TensorFlow API. But in this course, we are going to be focusing on making use solely of that high level Kerris API without necessarily making much use of the lower level TensorFlow API. Now, before we can start working with cares, then we first have to obviously get it downloaded and installed onto our machines. And because Kerris is fully integrated with TensorFlow, we can do that by just installing TensorFlow Kerris will come completely packaged with the TensorFlow installation. So the installation procedure is as simple as running pip install TensorFlow from your command line, you might just want to check out the system requirements on tensor flows website to make sure that your specific system we The requirements needed for TensorFlow to install.
Alright, so we have one last talking point before we can get into the actual meat of the coding. And that is about GPU support. So the first important thing to note is that a GPU is not required to follow this course, if you're running your machine only on a CPU, then that is totally fine for what we'll be doing in the course. If however, you do want to run your code on a GPU, then you can do so pretty easily. After you get through the setup process for setting up your GPU to work with TensorFlow, we have a full guide on how to get the GPU setup to work with TensorFlow on deep lizard Comm. So if you are interested in doing that, then head over there to go through those steps. But actually, I recommend just going through the course with a CPU if you're not already set up with a GPU. And like I said, the all the code will work completely fine, run totally fine using only a CPU.
But then after the fact, after you go through the course successfully, then get the steps in order to work with the GPU if you have one, and then run all the code that you have in place from earlier, run it on the GPU, the second go round and just kind of look and see the kind of efficiency and speed ups that you'll see in the code. Alright, so that's it for the Kerris introduction. Now we're finally ready to jump in to the code. Be sure to check out the blog and other resources available for this episode on the poser.com as well as the dibbles at hive mind where you can gain access to exclusive perks and rewards. Thanks for contributing to collective intelligence. Now, let's move on to the next episode. Hey, I may be from deep lizard. In this episode, we'll learn how to prepare and process numerical data that will later use to train our very first artificial neural network.
To train any neural network and a supervised learning task, we first need a data set of samples along with the corresponding labels for those samples. When referring to the word samples, we're simply just talking about the underlying data set, where each data point in the set is referred to as a sample. If we were to train a model to do sentiment analysis on headlines from a media source, for example, then the labels that correspond to each headline sample would be positive or negative.
Or say that we were training an artificial neural network to identify images as cats or dogs, well, then that would mean that each image would have a corresponding label of cat or dog. Note that in deep learning, you may also hear samples referred to as inputs or input data. And you may hear labels referred to as targets or target data. When preparing a data set, we first need to understand the task for which the data will be used. In our example, we'll be using our data set to train an artificial neural network. So once we understand this, then we can understand which format the data needs to be in, in order for us to be able to pass the data to the network. The first type of neural network that we'll be working with is called a sequential model from the cares API. And we'll discuss more details about the sequential model in a future episode.
But for now, we just need to understand what type of data format the sequential model expects, so that we can prepare our dataset accordingly. The sequential model receives data during training whenever we call the fit function on it. And again, we're going to go into more details about this function in the future. But for now, let's check out what type of data format the fit function expects. So if we look at the fit documentation here, on tensor flows website, we can see the first two parameters that the fit function expects are x and y. So x is our input data, our samples, in other words, so this function expects x our input data to be in a NumPy array, a TensorFlow tensor, a dict, mapping, a TF dot data data set or a karass generator. So if you're not familiar with all of these data types, that's okay, because for our first example, we are going to organize our data to be in a NumPy array.
So the first option here in the documentation, so this is for our input samples, but also the Y parameter that is expected by the fit function is our data set that contains the corresponding labels for our samples. So the target data. Now the requirement for why is that it is formatted as one of the above formats that we just discussed for x, but y needs to be in the same format as x. So we can't have our samples contained in a NumPy array, for example, and then have
y Our target data or our labels for those samples and the TensorFlow tensor. So the format of x and y, both need to match. And we're going to be putting both of those into NumPy arrays. Alright, so now we know the data format that the model expects. But there's another reason that we may want to transform or process our data. And that is to put it in a format that will make it easier or more efficient for the model to learn from. And we can do that with data normalization or standardization techniques, data processing, and deep learning will vary greatly depending on the type of data that we're working with. So to start out, we are going to work with a very simple numerical data set to train our model. And later, we'll get exposure to working with different types of data as well. Alright, so now we're ready to prepare and process our first data set. So we are in our Jupyter Notebook.
And the first step is to import all the packages that we'll be making use of including NumPy random and some modules from scikit learn. Next, we will create two list one called train samples, one called train labels, and these lists will hold the corresponding samples and labels for our data set. Now about this data set, we are going to be working with a very simple numerical data set. And so for this task, we're actually going to create the data ourselves. Later, we'll work with more practical examples and realistic ones where where we won't be creating the data, but instead downloading it from some external source. But for now, we're going to create this data ourselves for which will train our first artificial neural network. So as a motivation for this kind of dummy data, we have this background story to give us an idea of what this data is all about. So let's suppose that an experimental drug was tested on individuals ranging from age
13 to 100. In a clinical trial, this trial had 2100 participants total, half of these participants were under the age of 65. And half were 65 years or older. And the conclusions from this trial was that around 95% of the patients who were in the older population, so 65 or older, the 95% of those patients experienced side effects. And around 95% of patients who were under 65 years old, experienced no side effects. Okay, so this is a very simplistic data set. And so that is the background story.
Now in this cell, here, we're going to go through the process of actually creating that data set. So what this is, is this first for loop is going to generate both the approximately 5% of younger individuals who did experience side effects, and the 5% of older individuals who did not experience side effects. So within this first for loop, we are first generating a random number or a random integer rather between 13 and 64.
And that is constituting as a younger individual who is under 65 years of age, or yet who's under 65 years of age. And we are going to then append this number to the train samples list. And then we append a one to the train labels list. Now a one is representing the fact that a patient did experience side effects. And a zero would represent a patient who did not experience side effects. So then similarly, we jumped down to the next line.
And we are generating a random integer between 65 in 100, to represent the older population. And we are doing that Remember, this is in our first for loop. So it's only running 50 times. So this is kind of the outlier group, these 5% of older individuals who did not experience side effects. So we then take that sample appended to the train samples list, and append a zero to the corresponding train labels list. Since these patients were the older patients who did not experience side effects.
So then if we jumped down to the next for loop, very similarly, we have pretty much the same code here, except for this is the bulk of the group. And this for loop, we're running this for the 95% of younger individuals who did not experience side effects, as well as the 95% of older individuals who did experience side effects. So generating a random number between 13 and six before and then appending that number, representing the age of the younger population to the train samples list, and appending the label of zero. Since these individuals did not experience side effects, we're appending zero to the train labels list. Similarly, we do the same thing for the older individuals from 65 to 100. Except for since the majority of these guys did experience side effects, we are appending a one to the train The labels list. So just to summarize, we have the samples list that contains a bunch of integers ranging
from 13 to 100. And then we have the train labels list that has the labels that correspond to each of these individuals with the ages 13 to 100. The labels correspond to whether or not these individuals experience side effects. So a samples list containing ages, a labels list containing zeros and ones representing side effects, or no side effects. And just to get a visualization of the samples, here, we are printing out all of the samples in our list. And we see that these are just all integers, like we'd expect, ranging from 13 to 100. And then correspondingly, if we run our train labels list and print out all of the data there, then we can see this list contains a bunch of zeros and ones. Alright, so now the next step is to take these lists and then start processing them. So we have our data generated. Now we need to process it to be in the format for which we saw the fit function expects,
and we discussed the fact that we are going to be passing this data as NumPy arrays to the fit function. So our next step is to go ahead and do that transformation here, where we are taking the train labels list and making that now a NumPy array. Similarly, doing the same thing with the train samples list. And then we use the shuffle function to shuffle both are trained labels and trained samples respective to each other so that we can get rid of any imposed order from the data generation process. Okay, so now the data is in the NumPy array format that is expected by the fit function. But as mentioned earlier, there's another reason that we might want to do further processing on the data. And that is to either normalize or standardize it so that we can get it in such a way that the training of the neural network might become quicker or more efficient. And so that's what we're doing in this cell.
Now we are using this min max scalar object to create a feature range ranging from zero to one, which we'll then use in this next line to rescale our data from the current scale of 13 to 100, down to a scale of zero to one, and then this reshaping that we're doing here is just a formality because the fit transform function doesn't accept one D data by default. Since our data is one dimensional, we have to reshape it in this way to be able to pass it to the fit transform function.
So now if we print out the elements in our new scaled train samples variable, which that's what we're calling our new scaled samples, then we can print them out and see that now the individual elements are no longer integers ranging from 13 to 100. But instead, we have these values ranging anywhere between zero and one. So at this point, we have generated some raw data, and then processed it to be in a NumPy array format that our model will expect.
And then rescale the data to be on a scale between zero and one, and an upcoming episode, we'll use this data to train our first artificial neural network, be sure to check out the blog and other resources available for this episode on deep lizard calm, as well as the deep lizard hive mind where you can gain access to exclusive perks and rewards. Thanks for contributing to collective intelligence. Now, let's move on to the next episode. Hey, I'm Andy from Blizzard.
And this episode will demonstrate how to create an artificial neural network using a sequential model from the keras API integrated within tensor flow. In the last episode, we generated data from an imagined clinical trial. And now we'll create an artificial neural network for which we can train on this data. Alright, so first things first, we need to import all of the TensorFlow modules that we'll be making use of to build our first model.
And that includes everything that you see here except for actually the last two of atom and categorical cross and vitry. categorical cross entropy, rather, those two are going to be used when we train the model, not when we build it. But we're going ahead and bringing all the imports in now. And then next, if you are running this code on a GPU, then you can run this cell which will allow you to make sure that TensorFlow is correctly identifying your GPU as well as enable memory growth.
And there's a few lines on the blog where you can check out what exactly that means and why you might want to do this. But if you are running a GPU then go ahead and run this cell. So next, this is the The actual model that we are building this is a sequential model. And that is kind of the most simplest type of model that you can build using Kerris or TensorFlow. And a sequential model can be described as a linear stack of layers. So if you look at how we're creating the model here, that's exactly what it looks like. So we are initializing the model as an instance of the sequential class. And we are passing in a list of layers here. Now, it's important to note that this first dense layer that we're looking at, that is actually the second layer overall. So this is the first hidden layer. And that's because the input layer, we're not explicitly defining using Kerris, the input data is what creates the input layer itself.
So the way that the model knows what type of input data to expect, or the shape of the input data, rather, is through this input shape parameter that we pass to our first dense layer. So through this, the model understands the shape of the input data that it should expect. And then therefore it accepts that shape, have input data, and then passes that data to the first hidden layer, which is this dense layer here in our case, now, we are telling this dense layer that we want it to have 16 units.
These units are also otherwise known as nodes or neurons. And the choice of 16 here is actually pretty arbitrary. This model overall is very simple. And with the arbitrary choice of nodes here, it's actually going to be pretty hard to create a simple model, at least, that won't do a good job at classifying this data, just given the simplicity of the data itself. So we understand that we're passing in, or that we're specifying 16 units for this first
hidden layer, we are specifying the input shape, so that the model knows the shape of the input data to expect and then we are stating that we want the relu activation function to follow this dense layer. Now, this input shape parameter is only specified for our first hidden layer. So after that, we have one more hidden, dense layer. This time, we are arbitrarily setting the number of units for this dense layer to be 32. And again, we're following the layer by the activation function value.
And then lastly, we specify our last output layer or our last layer, which is our output layer. This is another dense layer, this time with only two units, and that is corresponding to the two possible output classes. Either a patient did experience side effects, or the patient did not experience side effects. And we're following this output layer with the softmax function, which is just going to give us probabilities for each output class.
So between whether or not a patient experience side effects or not, we will have an output probability for each class, letting us know which class is more probable for any given patient. And just in case, it's not clear, this dense layer here is what we call a densely connected layer or a fully connected layer, probably the most well known type of layer and an artificial neural networks. Now in case you need any refresher on fully connected layers, or activation functions, or anything else that we've discussed up to this point, then just know that all of that is covered in the deep learning fundamentals course, if you need to go there and refresh your memory on any of these topics here. Alright, so now we'll run this cell to create our model. And now we can use model dot summary to print out a visual summary of the architecture of the model we just created. So looking here, we can just see the visual representation of the architecture that we
just created in the cell above. All right, so now we have just finished creating our very first neural network using this simple and intuitive sequential model type. In the next episode, we will see how we can use the data that we created last time to train this network. Be sure to check out the blog and other resources available for this episode on depot's or.com as well as the tables at hive mind where you can gain access to exclusive perks and rewards. Thanks for contributing to collective intelligence. Now let's move on to the next episode. Hey, I'm Andy from deep lizard. In this episode, we'll see how to train an artificial neural network using the keras API integrated with TensorFlow. In previous episodes, we went through steps to generate data and also build an Artificial neural network. So now we'll bring these two together to actually train the network on the data that we created and processed.
Alright, so picking up where we were last time in our Jupyter Notebook, make sure that you still have all of your imports included and already ran so that we can continue where we were before. So first we have after building our model, we are going to call this model compile function. And this just prepares the model for training. So it gets everything in order that's needed before we can actually train the model. So first, we are specifying to the compile function, what optimizer that we want to use, and we're choosing to use the very common optimizer atom with a learning rate of 0.0001. And next we specify the type of loss that we need to use, which is in our case, we're going to use sparse categorical cross in but we're going to use sparse categorical cross entropy. And then lastly, we specify what metrics we want to see.
So this is just for the model performance, what we want to be able to judge our model by and we are specifying this list, which just includes accuracy, which is a very common way to be able to evaluate model performance. So if we run this cell, alright, so the model has been compiled and is ready for training. And training occurs whenever we call this fit function. Now recall earlier in the course, we actually looked at the documentation for the split function, so that we knew how to process our input data. So to fit the first parameter that we're specifying is x here, which is our input data, which is currently stored in this scaled at train samples variable, then y, which is our target data, or our labels are labels are currently stored in the train labels variable. So we are specifying that here. Next, we specify our batch size that we want to use for training.
So this is how many samples are included in one batch to be passed and processed by the network at one time. So we're setting this to 10. And the number of epochs that we want to run, we're setting this to 30. So that means that the model is going to process or train on all of the data in the data set 30 times before completing the total training process. Next, we're specifying this shuffle, shuffle parameter which we are setting to true.
Now, by default, this is already set to true, but I was just bringing it to your attention to show or to make you aware of the fact that the data is being shuffled by default, when we pass it to the network, which is a good thing, because we want any order that is inside of the dataset to be kind of erased before we pass the data to the model so that the model is not necessarily learning anything about the order of the data set. So this is true by default. So we don't necessarily have to specify that I was just letting you know. And actually, we'll see something about that in the next episode about why this is important regarding validation data, but we'll see that coming up. The last parameter that we specify here is verbose, which is just an option to allow us to see output from whenever we run this fit function. So we can either set it to 01, or two, two is the most verbose level in terms of output messages.
So we are setting that here so that we can get the highest level of output. So now let's run this cell so that training can begin. All right, so training has just stopped. And we have run for 30 epochs. And if we look at the progress of the model, so we're starting out on our first epoch, our loss value is currently point six, eight and our accuracy is 50%. So no better than chance. But pretty quickly looking at the accuracy, we can tell that it is steadily increasing all the way until we get to our last a POC, which we are yielding 94% accuracy. And our loss has also steadily decreased from the point six five range to now being at point two seven. So as you can see this model train very quickly, with each epoch taking only under one second to run. And within 30 epochs, we are already at a 94% accuracy right. Now although this is a very simple model, and we were training it on a very simple data,
we can see that without much effort at all, we were able to yield pretty great results in a relatively quick manner of time as well. In subsequent episodes, we'll demonstrate how to work with more complex models as well as more complex data. But for now, hopefully this example served the purpose of encouraging you on how easy it is to get started with Kerris. Be sure to check out the blog and other resources available for this episode on V bowser.com. As well as the deep lizard hive mind where you can gain access to exclusive perks and rewards. Thanks for contributing to collective intelligence. Now let's move on to the next episode. Hey, I'm Andy from deep lizard. In this episode, we'll demonstrate how we can use tensor flows keras API to create a validation set on the fly during training. Before we demonstrate how to build a validation set using Kerris, let's first talk about what exactly a validation set is.
So whenever we train a model, our hope is that when we train it that we see good results from the training output, that we have low loss and high accuracy. But we don't ever train a model just for the sake of training it, we want to take that model and hopefully be able to use it in some way on data that it wasn't necessarily exposed to during the training process. And although this new data is data that the model has never seen before, the hope is that the model will be good enough to be able to generalize well on this new data and give accurate predictions for it, we can actually get an understanding of how well our model is generalizing by introducing a validation set during the training process to create a validation set. Before training begins, we can choose to take a subset of the training set, and then separate it into a separate set labeled as validation data.
And then during the training process, the model will only train on the training data, and then we'll validate on the separated validation data. So what do we mean by validating? Well, essentially, if we have the addition of a validation set, then during training, the model will be learning the features of the training set, just as we've already seen. But in addition, in each epoch, after the model has gone through the actual training process, it will take what it's learned from the training data, and then validate by predicting on the data in the validation set, using only what it's learned from the training data, though. So then during the training process, when we look at the output of the accuracy and loss, not only will we be seeing that accuracy and loss computed for the training set, we'll also see that computed on the validation set. It's important to understand though, that the model is only alerting on or training
on the training data. It's not taking the validation set into account during training. The validation set is just for us to be able to see how well the model is able to predict on data that it was not exposed to during the training process. In other words, it allows us to see how general our model is how well it's able to generalize on data that is not included in the training data. So knowing this information will allow us to see if our model is running into the famous overfitting problem.
So overfitting occurs when the model has learned the specific features of the training set really well, but it's unable to generalize on data it hasn't seen before. So if while training, we see that the model is giving really good results for the training set, but less than good results for the validation set, then we can conclude that we have an overfitting problem, and then take the steps necessary to combat that specific issue. If you'd like to see the overfitting problem covered in more detail, then there is an episode for that in the deep learning fundamentals course. Alright, so now let's discuss how we can create and use a validation set with a karass sequential model, there's actually two ways that we can create and work with validation sets with a sequential model. And the first way is to have a completely separate validation set from the training set.
And then to pass that validation set to the model in the fit function, there is a validation data parameter. And so we can just set that equal to the structure that is holding our validation data. And there's a write up in the corresponding blog for this episode that contains more details about the format that that data needs to be in. But we're going to actually only focus on the second way of creating and using a validation set. This step actually saves us a step because we don't have to explicitly go through the creation process, the validation set, instead, we can get Kerris to create it for us. Alright, so we're back in our Jupyter Notebook right where we left off last time. And we're here on the model dot fit function. And recall, this is what we use last time to train our model. Now, I've already edited this cell to include this new parameter, which is validation split.
And what validation split does is it does what it sounds like it splits out a portion of the training set into a validation set. So we just set this to a number between zero and one. So just a fractional number to tell Kerris How much of the training set we need to split out into the validation set. So here I'm splitting out 10% of the training set. So it's important to note that whenever we do this, the validation set is completely held out of the training set.
So the training samples that we remove from the training set into validation set are no longer contained within the training data any longer. So using this approach, the validation set will be created on the fly whenever we call the fit function. Now, there's one other thing worth mentioning here. And remember last time, I discussed this shuffle equals true parameter. And I said that by default, the training set is shuffled whenever we call fit. So this shuffle equals true is already set by default. But I was just bringing it up to let you know that that the training set is being shuffled. So that is a good thing, we want the training set to be shuffled. But whenever we call validation split in this way, this split occurs before the training set is shuffled, meaning that if we created our training set and say, we put all of the sick patients first and then the non sick patients second, and then we say that we want
to split off the last 10% of the training data to be our validation data, it's going to take the last 10% of the training data. And therefore it could just take all of the the second group that we put in the training set and not get any of the first group. So I wanted to mention that because although the training data is being shuffled with the fit function, if you haven't already shuffled your training data before you pass it to fit, then you also use the validation split parameter, it's important to know that your validation set is going to be the last X percent of your training set and therefore may not be shuffled and may yield some strange results because you think that everything has been shuffled when really, it's only the training set has been shuffled after the validation set has been taken out. So just keep that in mind the way that we created our training set.
Before this episode, we actually shuffled the training data before it's ever passed to the fit function. So in the future, whenever you're working with data, it's a good idea to make sure that your data is also shuffled beforehand, especially if you're going to be making use of the validation split parameter to create a validation set. Alright, so now we'll run this cell one more time calling the fit function. But this time, not only will we see loss and accuracy metrics for the training set, we'll also see these metrics for the validation set. Alright, so the model has just finished running it's 30 epochs. And now we see both the loss and accuracy on the left hand side, as well as the validation loss and validation accuracy on the right hand side. So we can see, let's just look at the accuracy between the two. They're both starting at around the same 50% Mark, and going up gradually around the same
rate. So we just scroll all the way to our last epoch, we can see that the accuracy and validation accuracy are pretty similar with only 1% difference between the two. And yet the loss values are similar as well. So we can see in this example that our model is not overfitting, it is actually performing pretty well or just as well rather on the validation set as it is on the training set. So our model is generalizing well. If however, we saw that the opposite case was true, and our validation accuracy was seriously lagging behind our training accuracy, then we know that we have a overfitting problem and we would need to take steps to address that issue. Alright, so we've now seen how to train the model how to validate the model, and how to make use of both training and validation sets. In the next episode, we're going to see how to make use of a third data set that test data set. To use the model for inference.
Be sure to check out the blog and other resources available for this episode on depot's or.com as well as the deep lizard hive mind where you can gain access to exclusive perks and rewards. Thanks for contributing to collective intelligence. Now let's move on to the next episode. Hey, I'm Andy from deep lizard. In this episode, we'll see how we can use a neural network for inference to predict on data from a test set using TensorFlow keras API.
As we touched on previously, whenever we train a model, the hope is that we can then take that model and use it on new data that it has not seen before during training, and hopefully the model is able to generalize well. And give us good results on this new data. So as a simple example, suppose that we trained a network to be able to identify images of cats or dogs. And so during the training process, of course, we had a training set that, say, we downloaded
from a website with 1000s of images of cats and dogs. So the hope is later that if we wanted to, we could maybe build a web app, for example. And we could have people from all over the world, submit their dog and cat photos and have our model, tell them with high accuracy, whether or not their animal is a cat or a dog. So I don't know why anyone would actually make that web app. but you get the point. The hope is that even though the images that are being sent in from people around the world have their own cats and dogs, even though those weren't included in the training set that the model was originally trained on. Hopefully, the models able to generalize well enough to understand from what it's learned about dog and cat features, that it can predict that Mandy's dog is actually a dog and not a cat, for example, we call this process inference. So the model takes what it learned during training, and then uses that knowledge to infer things about data that it hasn't seen before.
In practice, we might hold out a subset of our training data to put in a set called the test set. Typically, after the model has been trained and validated, we take the model and use it for inference purposes against the test set, just as one additional step to the validation to make sure that the model is generalizing Well, before we deploy our model to production. So at this point, the model that we've been working with over the last few episodes has been trained and validated.
And given the metrics that we saw during the validation process, we have a good idea that the model is probably going to do a pretty good job at inference on the test set as well. In order to conclude that though, we first would need to create a test set. So we're going to do that now. And then after we create the test set, then we'll use the model for inference on it. Alright, so we are back in our Jupyter Notebook. And now we're going to go through the process of creating the test set. And actually, if you just glance at this code here, you can see that this whole process of setting up the the samples and labels list and then generating the data from the imagine clinical trial that we discussed in a previous episode, we're then taking that generated data and putting it into a NumPy array format, then shuffling that data, and then scaling the data to be on a scale from zero to one, rather than from the scale of 13 to 100.
So actually, that is the same exact process using almost the same exact code, except for we're working with our tests, labels, and test samples, variables rather than train labels and train samples. So we're not going to go line by line through this code. If you need a refresher, go check out the earlier episode where we did the exact same process for the training set. The important thing to take from this process, though, is that the test set should be prepared and processed in the same format as the training data was. So we'll just go ahead and run the cells to test and are to create and process the test data. And now, we are going to use our model to predict on the test data. So to obtain predictions from our model, we call predict on the model that we created in the last couple of episodes. So we are calling model dot predict. And we are first passing in this parameter x which we're setting equal to our scaled test samples.

Ask anything
We've read this whole study set, so questions about it get the best answers.