[Music] in this video we're going to discuss one hot encoding and how we can make use of these encoding in machine learning in a previous video we talked about how labels for images and caris were actually one hot encoded vectors now we'll discuss exactly what that means so we know that when we're training a neural network via supervised learning we pass labelled input to our model and the model gives us a predicted output if our model is an image classifier for example then we may be passing it labeled images of animals as input when we do this the model is usually not interpreting these labels as words like dog or cat additionally the output that our model gives us in regards to its predictions aren't typically words like dog or cat either instead most of the time our labels become encoded so that they can take on the form of an integer or of a vector of integers one type of encoding that's widely used for classifying categorical data is called one hot encoding one hot encoding transforms our categorical labels and two vectors of zeros and ones the length of these vectors is equal to the number of classes or categories that our model is expected to classify so if we were classifying whether images were either of a cat or of a dog then our one hot encoded vectors that correspond to these classes would each be of length 2 since there are two categories total if we added another category like lizard so that we could then classify whether images were of cats dogs or lizards then our corresponding one hot encoded vectors would each be of length 3 since we now have three categories alright so for one hot encoding we know the labels are transformed or encoded into vectors we know that each of these vectors has a link that is equal to the number of output categories and we briefly mentioned that the vectors contain zeros and ones so let's go into further detail on this last piece let's stick with the example of classifying images as being either of a cat dog or lizard with each of the corresponding factors of these categories being of length three we can think of each index or of each element within the vector corresponding to one of the three categories so let's say for this example that the cat label corresponds to the first element the dog label corresponds to the second element and the lizard label corresponds to the third element with each of these categories having their own place in the corresponding vectors we can now discuss the intuition behind the name one hunt with each one hot encoded vector every element will be a zero except for the element that corresponds to the actual category of the given input this element will be a one so sticking with our same example recall we said that a cat corresponds to the first element dog to the second and lizard to the third for cat we see that the first element is a one in the next two elements are zeros this is because each element within the vector is a zero except for the element that corresponds to the actual category and we said that the cat category correspond it to the first element so that's the reason for the one here similarly for dog we see that the second element is a one while the first and third elements are zeros and lastly for lizard the third element is a one while the first and second elements are zeros so now we can see that each time the model receives input that's a cat it's not interpreting the label as the word cat but instead is interpreting the label as this vector 1 0 0 4 images labeled as dog the model is interpreting the dog label as the vector 0 1 0 and 4 images labeled as lizard the models interpreting the label as the vector 0 0 1 now just for clarity purposes say we add another category llama to the mix so now we have four categories total and so this will cause each one hunt encoded vector corresponding to each of these categories to be of length 4 now and the vectors will look like this so we can see that for each of our pre-existing categories of cat dog and lizard we still have the corresponding one for each of these vectors in the same place it was in before the one is the first element for cat second element for dog and third element for lizard the new fourth element for each of our existing categories is just a zero since this fourth element corresponds to the llama category and finally the new one high-end cotton for the llama category is all zeros except for the fourth element which is a one again since the fourth element corresponds to the llama category now we just arbitrarily said that the cat correspond to the first element dog to the second lizard to the third and llama to the fourth but this could very well be in a different order for example we could instead have dog corresponding to the first element lizard to the second llama to the third and cat to the fourth this just depends on how the underlying code or library is doing the one high in coding if you're interested in understanding how to view the mapping between which element or index corresponds to which label and caris for image data check out my previous videos showing how that can be accessed so I hope now you understand what one-hot encoding is and how labels are transformed into one hot encoded vectors for classification purposes when working with artificial neural networks and I hope you found this video helpful if you did please like this video subscribe suggest and comment and thanks for watching [Music] you