0:06 Welcome to our machine learning full course. By 2025, machine learning will be one of the most in demand skills in industries like healthcare, finance and technology. Companies everywhere are looking for people who can create smart models, manage big data and automate real world task. And the best part is the salary is great. In India, machine learning experts can earn anywhere between 10 lakh to 25 lakh peranom. And in US, salaries can exceed up to $120,000 plus. This course goes beyond theory. We'll start with an easy to follow beginner road map for 2025. You'll dive into key topics like KNN and the confusion matrix. And as you advance, we will explore more complex topics like deep learning, reinforcement learning, and LSTM. We'll also introduce you to large language models, get you familiar with hugging phase, and teach you how to evaluate AI models like a professional. 1:09 And by the end, you'll not only understand machine learning, but be ready to take charge in the AI revolution. So, let's get started. But before we commence, if you're interested in mastering the future of technology, then the professional certificate course in generative AI and machine learning is the perfect opportunity for you. Offered in collaboration with the ENIC Academy, IT Kpur, this 11month live and interactive program provides hands-on expertise in cutting edge areas like generative AI, machine learning and tools like chat, GPT, D2, and even hugging. You'll also gain practical experience through 15 plus projects, integrated labs, and live master classes delivered by esteemed IT Kpool faculty. So, hurry up and enroll now and find a course link in the description box below and in the pin comments. We know humans learn from their past experiences and machines follow instructions given by humans. But what if humans can train the machines to learn from their past data and do what humans can do and much 2:09 faster? Well, that's called machine learning. But it's a lot more than just learning. It's also about understanding and reasoning. So today we will learn about the basics of machine learning. So that's Paul. He loves listening to new songs. He either likes them or dislikes them. Paul decides this on the basis of the songs tempo, genre, intensity, and the gender of voice. For simplicity, let's just use tempo and intensity for now. So here tempo is on the x-axis ranging from relaxed to fast whereas intensity is on the y-axis ranging from light to soaring. We see that Paul likes the song with fast tempo and soaring intensity while he dislikes the song with relaxed tempo and light intensity. So now we know Paul's choices. Let's say Paul listens to a new song. Let's name it as song A. Song A has fast tempo and a soaring intensity. So it lies somewhere 3:10 here. Looking at the data, can you guess whether Paul will like the song or not? Correct. So Paul likes this song. By looking at Paul's past choices, we were able to classify the unknown song very easily. Right? Let's say now Paul listens to a new song. Let's label it as song B. So song B lies somewhere here with medium tempo and medium intensity neither relaxed nor fast neither light nor soaring. Now can you guess whether Paul likes it or not? Not able to guess whether Paul will like it or dislike it. Are the choices unclear? Correct. We could easily classify song A. But when the choice became complicated as in the case of song B. Yes. And that's where machine learning comes in. Let's see how. In the same example for song B, if we draw a circle around the song B, we see that there are four votes for like whereas one vote for dislike. If we go for the majority votes, we can say that Paul will definitely like the song. That's all. This was a basic machine 4:11 learning algorithm also. It's called K nearest neighbors. So this is just a small example in one of the many machine learning algorithms. Quite easy, right? Believe me, it is. But what happens when the choices become complicated as in the case of song B? That's when machine learning comes in. It learns the data, builds the prediction model and when the new data point comes in, it can easily predict for it. More the data, better the model, higher will be the accuracy. There are many ways in which the machine learns. It could be either supervised learning, unsupervised learning or reinforcement learning. Let's first quickly understand supervised learning. Suppose your friend gives you 1 million coins of three different currencies. Say 1 rupee, 1 euro and 1 dirham. Each coin has different weights. For example, a coin of one rupee weighs 3 g. 1 euro weighs 7 g and 1 dirham weighs 4 g. Your model will predict the currency of the coin. Here your weight becomes the feature of coins while currency becomes 5:12 their label. When you feed this data to the machine learning model, it learns which feature is associated with which label. For example, it will learn that if a coin is of 3 g, it will be a 1 rupee coin. Let's give a new coin to the machine. On the basis of the weight of the new coin, your model will predict the currency. Hence, supervised learning uses labeled data to train the model. Here, the machine knew the features of the object and also the labels associated with those features. On this note, let's move to unsupervised learning and see the difference. Suppose you have cricket data set of various players with their respective scores and the wickets taken. When we feed this data set to the machine, the machine identifies the pattern of player performance. So, it plots this data with the respective wickets on the x-axis while runs on the y-axis. While looking at the data, you'll clearly see that there are two clusters. The one cluster are the players who scored high runs and took less wickets while the other cluster is of the players who scored less runs but took many wickets. So here 6:14 we interpret these two clusters as batsmen and bowlers. The important point to note here is that there were no labels of batsmen and bowlers. Hence the learning with unlabeled data is unsupervised learning. So we saw supervised learning where the data was labeled and the unsupervised learning where the data was unlabeled. And then there is reinforcement learning which is a reward-based learning or we can say that it works on the principle of feedback. Here let's say you provide the system with an image of a dog and ask it to identify it. The system identifies it as a cat. So you give a negative feedback to the machine saying that it's a dog's image. The machine will learn from the feedback and finally if it comes across any other image of a dog, it'll be able to classify it correctly. That is reinforcement learning. To generalize machine learning model, let's see a flowchart. Input is given to a machine learning model which then gives the output according to the algorithm applied. If it's right, we take the output as our final result. Else we provide feedback to the training model and ask it to predict until it learns. I 7:16 hope you've understood supervised and unsupervised learning. So let's have a quick quiz. You have to determine whether the given scenarios uses supervised or unsupervised learning. Simple, right? Scenario one. Facebook recognizes your friend in a picture from an album of tagged photographs. Scenario two, Netflix recommends new movies based on someone's past movie choices. Scenario three, analyzing bank data for suspicious transactions and flagging the fraud transactions. Think wisely and comment below your answers. Moving on. Don't you sometimes wonder how is machine learning possible in today's era? Well, that's because today we have humongous data available. Everybody's online either making a transaction or just surfing the internet and that's generating a huge amount of data every minute and that data my friend is the key to analysis. Also, the memory handling capabilities of computers have largely increased which helps them to process such huge amount of data at hand without any delay. And yes, computers 8:18 now have great computational powers. So there are a lot of applications of machine learning out there. To name a few, machine learning is used in healthcare where diagnostics are predicted for doctor's review. The sentiment analysis that the tech giants are doing on social media is another interesting application of machine learning. Fraud detection in the finance sector and also to predict customer churn in the e-commerce sector. While booking a cab, you must have encountered search pricing often where it says the fair of your trip has been updated. Continue booking. Yes, please. I'm getting late for office. Well, that's an interesting machine learning model which is used by global taxi giant Uber and others where they have differential pricing in real time based on demand, the number of cars available, bad weather, rush hour r etc. So they use the search pricing model to ensure that those who need a cab can get one. Also, it uses predictive modeling to predict where the demand will be high with a goal that drivers can take care of the demand and search pricing can be 9:20 minimized. Great. Hey Siri, can you remind me to book a cab at 6 p.m. today? Okay, I'll remind you. Thanks. No problem. I will be giving you a tutorial on one of the most talked about topics in the world of technology and that is machine learning. I'm sure that if you are watching this video, you must have heard about machine learning somewhere or the other. And yes, it is quite an intriguing topic. This video will act as a supplement for the ones who know the basics of machine learning and are aware of where it is being used and how it is being used. For the ones who are completely new to this, you don't have to worry. We will be brushing up the basics as well. So to start off with, let's have a look at the agenda. First, we'll look into a life without machine learning. Then we'll move into a life with machine learning. Then we'll try to understand what is machine learning actually. Then we'll look into the types of machine learning. We'll talk about the right machine learning solutions. Then we'll move into the different algorithms that machine learning has. 10:21 Finally, we'll do a use case wherein we'll be predicting the price of a house using linear regression. Let's talk about a life without machine learning. For someone who doesn't know anything about machine learning or artificial intelligence, he or she might think that it is only being used in robots or machines and stuff which is actually true as portrayed by most of the sci-fi movies nowadays. But you wouldn't believe how much more machine learning is giving us how much of it we are using in our daily lives. Let's say you need information on any random topic, say a computer. The first place you would check would definitely be Google, right? It would collect all the information on the word you search for and present it to you according to relevance. If there was no Google, you would have to do it in a very hard way. That is by going through tens or hundreds of books and articles even after which you won't find the answer. If we go back four to 5 years, facial recognition would be a thing only showed in movies like Mission Impossible or Terminator or any of the 11:22 sci-fi movies you pick. But machine learning has made it possible for Facebook and Instagram to use this feature for your benefits. You don't have to go through the trouble of tagging every single person present in a picture that you have posted. Facebook will automatically recognize the people in the photo and tag them for you. That saves a lot of time for you, doesn't it? Also, Siri, Kotana, Iris, all of them would not be there to help you if there was no machine learning. Now that we know life would be a lot more difficult without machine learning, let's look into the things that are run by machine learning and we are using them on our daily basis. Let's enter the world of gaming. PS4s and Xboxes have introduced virtual reality glasses which brings a whole new level of detail into gaming. Every time your head moves in real world, it replicates the movement in the virtual world providing an excellent gaming experience. Then there is gesture control gaming where in machine learning tracks your 12:22 body movement and makes a corresponding movement in the game. Finally, in the game FIFA, your opponent tends to adapt based on the kind of strategy or gameplay you follow. That is again done by machine learning. I'm sure you must have shopped a lot from Amazon. So let's look into some of the places Amazon makes use of machine learning. Let's say you buy a formal t-shirt on Amazon. Now as you buy it, it suggests you formal shoes, ties, blazers, and apparel that go with what you have bought. That's the recommendation system powered by machine learning. Again, the price on every product that you see on Amazon is varying every moment based on demand. That's being done by machine learning algorithms. Then comes customer segmentation. Customer segmentation is one of the most crucial thing for all the e-commerce platforms. Machine learning helps them differentiate between customers based on what they buy, how frequent are they and their reviews. This helps the companies to make sure that their customers are 13:23 taken care of and the needs are being fulfilled. Now let's talk about an app that you use on a daily basis to reach office on time. Yes, it's Uber caps. Once you have traveled with Uber, you must have noticed that it suggests you the places you might want to go based on your previous journeys. When you're taking a share, how does the app make sure that the cab you get is traveled by the same route you want to travel in? There are so many factors like the distance, the traffic, the ratings, all of it is taken care of by machine learning. For the past 5 minutes, we have been talking about how machine learning is improving our lives, where all it is being used. I have probably said machine learning 100 times already. I think it's about time that I tell you what machine learning actually is. Let's take an ordinary system that you currently are using. It can't do much except from the basic operations that you already know about. Now let's add artificial intelligence or for a layman's point of view, let's give the 14:24 same machine the power to think on its own. That is what machine learning basically is. It's an application of artificial intelligence that provides systems the ability to learn on their own and improve from experience without being programmed externally. So if your computer had machine learning, it may be able to play the difficult parts of a game for you or probably solve a complicated mathematical equation for you. That could be really helpful. Let's dive in a little deeper and see how machine learning works. Let's say you provide a system with the input data that carries the photos of various kinds of fruits. Now you want the system to figure out what are the different fruits and group them accordingly. So what the system does it analyzes the input data. Then it tries to find patterns. Patterns like shapes, size and color. Based on these patterns, the system will try to predict the different types of fruit and segregate them. Finally, it keeps track of all such decisions it took in the process to make sure it's learning. The next time you ask the same 15:26 system to predict and segregate the different types of fruits, it won't have to go through the entire process again. That's how machine learning works. Now let's look into the types of machine learning. Machine learning is primarily of three types. First one is supervised machine learning. As the name suggests, you have to supervise your machine learning while you train it to work on its own. It requires labeled training data. Next up is unsupervised learning wherein there will be training data but it won't be labeled. Finally, there's reinforcement learning wherein the system learns on its own. Let's talk about all these types in detail. Let's try to understand how supervised learning works. Look at the pictures very very carefully. The monitor depicts the model or the system that we are going to train. This is how the training is done. We provide a data set that contains pictures of a kind of a fruit, say an apple. Then we provide another data set which lets the model know that 16:26 these pictures were that of a fruit called apple. This ends the training phase. Now what we will do is we provide a new set of data which only contains pictures of apple. Now here comes the fun part. The system can actually tell you what fruit it is and it will remember this and apply this knowledge in future as well. That's how supervised learning works. You are training the model to do a certain kind of an operation on its own. This kind of a model is generally used into filtering spam mails from your email accounts as well. Yes, surprised, aren't you? So, let's move on to unsupervised learning. Now, let's say we have a data set which is cluttered. In this case, we have a collection of pictures of different fruits. We feed this data to the model and the model analyzes the data to figure out patterns in it. In the end, it categorizes the photos into three types as you can see in the image based on their similarities. So, you provide the data to the system and let the system do the rest of the work. Simple, isn't it? This kind of a 17:28 model is used by Flipkart to figure out the products that are well suited for you. Honestly speaking, this is my favorite type of machine learning out of all the three. And this type has been widely shown in most of the sci-fi movies lately. Let's find out how it works. Imagine a newborn baby. You put a burning candle in front of the baby. The baby does not know that if it touches the flame, its fingers might get burned. So, it does that anyway and gets hurt. The next time you put that candle in front of the baby, it will remember what happened the last time and would not repeat what it did. That's exactly how reinforcement learning works. We provide the machine with a data set wherein we ask it to identify a particular kind of a fruit. In this case, an apple. So what it does as a response, it tells us that it's a mango. But as we all know, it's a completely wrong answer. So as a feedback, we tell the system that it's wrong. It's not a mango, it's an apple. What it does, it learns from the feedback and keeps that in mind. When 18:30 the next time when we ask a same question, it gives us the right answer. It is able to tell us that it's actually an apple. That is a reinforced response. So that's how reinforcement learning works. It learns from his mistakes and experiences. This model is used in games like Prince of Persia or Assassin's Creed or FIFA wherein the level of difficulty increases as you get better with the games. Just to make it more clear for you, let's look at a comparison between supervised and unsupervised learning. Firstly, the data involved in case of supervised learning is labeled. As we mentioned in the examples previously, we provide the system with a photo of an apple and let the system know that this is actually an apple. That is called label data. So, the system learns from the label data and makes future predictions. Now unsupervised learning does not require any kind of label data because its work is to look for patterns in the input data and organize it. The next point is that you get a feedback in case 19:32 of supervised learning. That is once you get the output the system tends to remember that and uses it for the next operation. That does not happen for unsupervised learning. And the last point is that supervised learning is mostly used to predict data whereas unsupervised learning is used to find out hidden patterns or structures in data. I think this would have made a lot of things clear for you regarding supervised and unsupervised learning. Now let's talk about a question that everyone needs to answer before building a machine learning model. What kind of a machine learning solution should we use? Yes, you should be very careful with selecting the right kind of solution for your model because if you don't, you might end up losing a lot of time, energy, and processing cost. I won't be naming the actual solutions because you guys aren't familiar with them yet. So, we will be looking at it based on supervised, unsupervised, and reinforcement learning. So, let's look into the factors that might help us select the right kind of machine learning solution. 20:32 First factor is the problem statement describes the kind of model you will be building or as the name suggests it tells you what the problem is. For example, let's say the problem is to predict the future stock market prices. So for anyone who is new to machine learning would have trouble figuring out the right solution. But with time and practice you will understand that for a problem statement like this solution based on supervised learning would work the best for obvious reasons. Then comes the size, quality and nature of the data. If the data is cluttered, you go for unsupervised. If the data is very large and categorical, we normally go for supervised learning solutions. Finally, we choose a solution based on their complexity. As for the problem statement wherein we predict the stock market prices, it can also be solved by using reinforcement learning. But that would be very very difficult and timeconuming unlike supervised learning. Algorithms are not types of machine learning. In the most simplest language, 21:34 they are methods of solving a particular problem. So the first kind of method is classification which falls under supervised learning. Classification is used when the output you are looking for is a yes or a no or in the form A or B or true or false. Like if a shopkeeper wants to predict if a particular customer will come back to his shop or not, he will use a classification algorithm. The algorithms that fall under classification are decision tree, knife base, random forest, logistic regression and KN&N. The next kind is regression. This kind of a method is used when the predicted data is numerical in nature. Like if the shopkeeper wants to predict the price of a product based on its demand, it would go for regression. The last method is clustering. Clustering is a kind of unsupervised learning. Again, it is used when the data needs to be organized. Most of the recommendation system used by Flipkart, 22:35 Amazon, etc. make use of clustering. Another major application of it is in search engines. The search engines study your old search history to figure out your preferences and provide you the best search results. One of the algorithms that fall under clustering is K means. Now that we know the various algorithms, let's look into four key algorithms that are used widely. We will understand them with very simple examples. The four algorithms that we will try to understand are K nearest neighbor, linear regression, decision tree and KN base. Let's start with our first machine learning solution. K nearest neighbor. K nearest neighbor is again a kind of a classification algorithm. As you can see on the screen, the similar data points form clusters. the blue one, the red one and the green one. There are three 23:35 different clusters. Now, if we get a new and unknown data point is classified based on the cluster closest to it or the most similar to it. K in KN&N is the number of nearest neighboring data points we wish to compare the unknown data with. Let's make it clear with an example. Let's say we have three clusters in a cost to durability graph. First cluster is of footballs. The second one is of tennis balls and the third one is of basketballs. From the graph we can say that the cost of footballs is high and the durability is less. The cost of tennis balls is very less but the durability is high and the cost of basketballs is as high as the durability. Now let's say we have an unknown data point. We have a black spot which can be one kind of the balls but we don't know what kind it is. So what we'll do we'll try to classify this 24:35 using KN&N. So if we take K is equal to 5, we draw a circle keeping the unknown data point in the center and we make sure that we have five balls inside that circle. In this case we have a football, a basketball and three tennis balls. Now since we have the highest number of tennis balls inside the circle, the classified ball would be a tennis ball. So that's how K nearest neighbor classification is done. Linear regression is again a type of supervised learning algorithm. This algorithm is used to establish linear relationship between variables, one of which would be dependent and the other one would be independent. Like if we want to predict the weight of a person based on his height. Weight would be the dependent variable and height would be independent. Let's have a look at it through an example. Let's say we have a graph here showing a relationship between height and weight of a person. Let's put the y-axis as age 25:38 and the x-axis as weight. So the green dots are the various data points. These green dots are the data points and D is the mean squared error. That is the perpendicular distances from the line to the data points are the error values. This error tells us how much the predicted values vary from the original value. Let's ignore this blue line for a while. So let's say if this is our regression line, you can see the distance from all the data points from this line is very high. So if we take this line as a regression line, the error in the prediction will be too high. So in this case the model will not be able to give us a good prediction. Let's say we draw another regression line here like this. Even in this case you can see 26:39 that the perpendicular distance of the data points from the line is very high. So the error value will still come as high as the last one. So this model will also not be able to give us a good prediction. So what to do? So finally we draw a line which is this blue line. So here we can see that the distance of the data points from the line is very less relative to the other two lines we drew. So the value of D for this line will be very less. So in this case if we take any value on the x-axis the corresponding value on the y-axis will be our prediction. And given the fact that the d is very low our prediction should be good also. This is how regression works. We draw a line, a regression line that is in such a way that the value of D is the least eventually giving us good predictions. 27:40 This algorithm that is decision tree is a kind of an algorithm you can very strongly relate to. It uses a kind of a branching method to realize the problem and make decisions based on the conditions. Let's take this graph as an example. Imagine yourself sitting at home getting bored. you feel like going for a swim. What you do is you check if it's sunny outside. So that's your first condition. If the answer to that condition is yes, you go for a swim. If it's not sunny, then the next question you would ask yourself is if it's raining outside. So that's condition number two. If it's actually raining, you cancel the plan and stay indoors. If it's not raining, then you would probably go outside and have a walk. So that's the final node. That's how decision tree algorithm works. You probably use this every day. It realizes a problem and then takes the decisions based on the answers to every conditions. NBI algorithm is mostly used in cases where a prediction needs to be done on a very large data set. It makes use of 28:41 conditional probability. Conditional probability is the probability of an event say A happening given that another event B has already happened. This algorithm is most commonly used in filtering spam mails in your email account. Let's say you receive a mail. The model goes through your old spam mail records. Then it uses space theorem to predict if the present male is a spam mail or not. So P C of A is the probability of event C occurring when A has already occurred. P A of C is the probability of event A occurring when C has already occurred. And P C is the probability of event C occurring. and PA is a probability of event A occurring. Let's try to understand night base with a better example. Night base can be used to determine on which days to play cricket based on the probabilities of a day being rainy, windy or sunny. The model tells us if a match is possible. If we 29:43 consider all the weather conditions to be event A for us and the probability of a match being possible event C. So the model applies the probabilities of event A and C into the base theorem and predicts if a game of cricket is possible on a particular day or not. In this case, if the probability of C of A is more than 0.5, we can be able to play a game of cricket. If it's less than 0.5, we won't be able to do that. That's how NY algorithm works. Now we have reached the most important part of our video. The use case wherein we'll be predicting the price of a house using machine learning. Look at this guy. He seems a bit worried, doesn't he? Let's figure out what the problem here is. So he's planning on selling his house in a few months, but he's unable to decide what price he should sell it for. So let's help him predict the price of his house using machine learning. So our problem statement is to predict the 30:44 price of a house using machine learning that will be implemented on Python. Now the first job at hand is to figure out which algorithm to use here. We will be using linear regression for this problem. As I mentioned before, linear regression is a kind of a supervised learning. Let's have a look at the reason why we are choosing linear regression over all the other algorithms. So the first reason here is the output is quantitative in nature and directly proportional to the variables. So I've mentioned this before many many times that if the prediction is quantitative in nature, linear regression is the best choice. The next reason is low computation cost. What does it mean? If you use an algorithm that involves a lot of equation solving and stuff, you'll need a very powerful system. So that will cost you more. but not in the case of linear regression because it is a very simple algorithm and it can be done in any normal system. Finally, linear regression is easy to understand as I 31:45 mentioned before. Let's have a look at the various features in the data set. The first feature is the lower status of population in that area. Then comes the mean price of all the houses in that area. Then the building age, the tax rate, the average number of rooms in every houses, the distance to five Boston employments, accessibility to highways, and finally the per capita crime rate. So these all are the factors that we'll be taking into consideration to predict the price of a house. Let's move ahead. So let's quickly try to understand how linear regression works. So this is your model the computer here and you provide the training data all the values for the different features you provide the system so that it can learn from it. As you can see it is trying to study the training data. It learns from it and then you give it the test data. You give it some values that it needs to predict. Now from the training data that it learned it will be able to predict the price of the house. That's how the entire model works. It's simple right? Now that we understand 32:47 what we are supposed to do, let's implement the entire model on Python. We will be using Jupyter notebook to run the code. It's because it will be easier for you to understand and I'll be able to explain every line of it to you properly. We'll be using scikitlearn to load all the data and libraries. Scikitlearn is a library specially dedicated to machine learning in case you are programming on Python. So let's start off by importing the required libraries for the model. So let's import the various libraries from scikitlearn. Firstly comes up numpy. Numpy is a support for large arrays and matrices that we are going to use in this use case. Then comes pandas. Pandas is a package that makes working with relational data easier. Then from regression model that we are going to use to check the accuracy of the model. We import train test split from scalearn.cross 33:47 validation. import train test split. So that's it. All the important libraries have been imported. Now let's move on. Now to run the cell, we press shift + enter. So that's it. The cell is running properly. Now from scikitlearn again we load the data set and to load that the code is from skarn dot data sets import load Boston line is Boston equal to load. So it makes it easier for us to load the entire data set we want. So again pressing shift and enter to run the cells. No errors. So now we'll try to have a look at the data set. Post. So as you can see 34:49 the entire data set is available in front of us. This is the entire data set. This are the values of all the features that we have. These are the names of the features that we talked about before. And these are the target values. With this value, we will compare the predictions that we have. So now we'll divide the data into two different data frames. This is how we create a data frame. dfx this is one of the data frame equal to pd. So here's where the pandas library come into work. Boston data columns equal to Boston or features feature names. So the next data frame would be dfy 35:55 data frame Boston dot target. So in this data frame all the target values will be loaded. So that's it. We run the cell two. It's running fine. Now let's try to describe the data. that is rfx dot describe. Now you can see that this table provides us with the count of every features, the mean value for every feature and the standard deviation. So all this data can be useful but not in this case. So let's not waste time here. So next comes an important part. Here we will apply regression. Now, so the code is rag equal to linear model dot linear regression. So that's why we loaded this library in the beginning. We press shift + enter. The cell is done 36:57 pretty well. No errors. Now we split our data into train and test data to validate the model. As we move ahead, I will show you how to do it as well. The code is x train comma x test comma y train y test equal to train test split dfx comma dfy test size test size is equal to 0.2. So that means 20% of the data is test and the remaining is train. 2. So random state is needed when we are to run and validate our model multiple times. So in this case we put it is 37:58 equal to four. So now what we do is we fit the data set into the regression function. The code is reg x train y train. Press shift and enter. And now as we can see that our data set is fit into the function that we called before line 14. You can see that. So next let's check the coefficient. So the code is reg. So these are the weights and these are optimal. So let me tell you what coefficient actually is. So the coefficients give us an idea of how much the dependent variable will increase if the independent variable value increases by one. If you take the equation of a line, 38:58 let's say the regression line that is y= mx + c. So C is the constant and M is the coefficient in this case. Very simple. Okay. Now we will predict the prices. So A will be the predicted price. So A equal to RG dot predict X test. So we will be predicting the prices according to arrays. Okay. So a in brackets will specify the array number. So in this case we get three. As we press enter we get array equal to 18.15. So for array three we are getting 18.1. So if we check on the test data what is the value for array number three. This is array number zero. This is 1 2 3. For array three the test data is 19.3. 39:58 and we are getting 18.1. So that's the prediction. So you can see that the predicted value and the original value don't vary much. The predictions are pretty good. So now let's test for array number five. So in the test table array 0 1 2 3 4 5. So in the test the value for the fifth array is 24.5 and we are getting 25.4. So the prediction is still pretty good. So our model is functioning pretty well. Now let's try and find the error. So the code will be np dot mean in bracket a minus y test. So a is the predicted value and y test is the test value. This gives us the error. Now if we square this value we get the mean squared error. two press shift and enter. So the error 41:00 value is 25. So that's our mean squared error. So we have successfully created a linear regression model. Now the error value that we got is 25 which is good enough as you have seen in the predictions. It can be made better by manipulating the data as well. Lesser the mean squared error, better the predictions. So let me go through the entire process once more for your convenience. Firstly, we'll be importing the various libraries from scikitlearn. Then we load the Boston data set from scikitlearn again. Then we transfer the data into two different data frames. So if we describe the Boston data set, we get a table like this wherein we get the count, mean value and standard deviation for every feature. Then we train the regression model. Next up, we split the data into test and train wherein the test size is 0.2 and the random state is equal to four. Then we fit the data into the regression model. After that, we 42:00 calculate the coefficients and the value of the coefficients you can see on the screen. So then we try to predict the prices. So for array number two, we get a value 17.5 and for the same array on the test data, it is 17.4. So the difference between the predicted data and the original data is very less. A model was functioning pretty well. For array number three, we get 18.1 and on the test data it is 19.3. So finally we calculate the mean square error which came out to be 25.4 which is quite good for our model. To summarize the entire video, let's look at a few important things we talked about. Firstly, we learned how machine learning is affecting our day-to-day lives with Facebook, Flipkart, Uber, etc. And we understood what machine learning actually is. Then we talked about the three types of machine learning, supervised, unsupervised, and reinforcement. We did a comparison between supervised and unsupervised 43:02 learning wherein we learned that supervised learning involves label data and in case of unsupervised learning there is non-labelled data. In case of supervised there is direct feedback and in case of unsupervised there is no feedback. Finally supervised learning is used to predict output and unsupervised learning is used to find hidden structure in a data. Then we try to understand the four widely used machine learning algorithms that are K nearest neighbor linear regression decision tree knives base. Then we learn when to use classification algorithms regression algorithms and clustering algorithms. Finally, we did a use case wherein we predicted the price of a house with a mean squared error value of 25.4, which turned out to be pretty fine. Hi everyone and welcome to the course of AI foundation for everyone. In this world rapidly shaped by artificial intelligence, understanding AI is becoming essential for everyone, not just experts. This course is your 44:02 non-technical guide to clarify AI and equipping you with practical job ready skills. We will be covering fundamental concepts of AI, explore the exciting new frontier of generative AI and how to effectively communicate with it using prompt engineering. And finally, we will be diving into building powerful AI chat boards all without any programming. Let's begin our journey into the world of AI for everyone. AI is no longer a futuristic concept. It's transforming numerous industries and aspects of our lives. In healthcare, AI is aiding in more accurate diagnosis, accelerating drug discovery, and enabling personalized treatment plans. In finance, it's being used to detect fraud, drive algorithm trading, and assess risk. The transportation sector is witnessing the rise of self-driving cars and AI powered traffic management systems. Retailers are leveraging AI for personalized recommendation and optimizing their supply chains. Even in 45:04 entertainment, AI is shaping what we watch and listen to through recommendation systems and even the creation of a new content. Like any powerful technology, AI comes with both benefit and limitation. On the plus side, AI can significantly increase efficiency and productivity, automate tidacs and repetitive task, improve the accuracy of decision and drive new discoveries and innovations that were previously impossible. However, there are also challenges to consider. Developing AI systems can be expensive and they often require vast amount of data to function effectively. Current AI systems can sometimes lack the common sense that humans possess and there are valid concern about the potential for job displacement as automatic increases. AI is already deeply woven into fabric of our daily lives and the operational of business. We interact with AI every 46:07 time we use virtual assistants like Siri or Google assistants. rely on navigation apps to get around, scroll through social media feeds curated by algorithms, or use email services that filter out spam. In the business world, AI is being used to enhance customer services through chat bots, predict equipment failures to enable productive maintenance, automate marketing campaigns, and analyze vast amount of data to gain valuable insights, generate and manipulate human language. They are trained on large data sets of text to learn the statistical patterns of how words, phrases and sentenced are structured. As AI become more powerful and pervasive, it's essential to address the ethical concerns it raises. One major issue is biases in AI systems which can perpetuate and even amplify existing societal productions. Privacy 47:07 and data security are also paramount as AI system often rely on large amount of personal data. The potential for job displacements due to automation is significant society challenge. And there are other concerns such as development of autonomous weapons and need for explanability and transparency in how AI systems arrive at their decision. A critical ethical challenge is the issue of biases in AI systems. AI systems learns from the data they are trained on. And if that data reflects existing societal biases, the AI will likely perpetuate and even amplify those biases. We have seen example of this in facial recognition systems that perform less accurately on individuals with darker skin tones and in hiring algorithms that inadvertably favor candidates from certain backgrounds. Addressing this requires careful attention to the data used to train AI. 48:10 ensuring it is diverse and representative and a commitment to fairness and accountability throughout the AI development process. Many AI systems, especially those involve personalized services, rely on vast amount of data, often including sensitive personal information. This raises significant concerns about privacy and data security. The risk of data breaches and the potential of misuse of this information are very real. It's crucial that we implement robust data protection measures priority transparency in how data is collected and used and empower users with control over their own data. To mitigate the risk and ensures that AI benefits society as a whole, it's essential to embrace responsible AI development. This involves adhering to a set of ethical principles such as fairness ensuring that AI system don't discriminate. Transparency so we understand how AI 49:12 systems make decision accountability establishing who is responsible when things go wrong. Safety ensuring AI system function reliably and of course protecting privacy. Developing ethical guidance and regulation is a crucial and this is a shared responsibility involving AI developers, organization and policy makers. The field of AI is evolving at a rapid pace and seven exciting trends are shaping its future. We can expert continued advancement in deep learning leading to even more sophisticated AI system. Generative AI which can create new content like text, images and music is poised to revolutionize creative industries. Explainable AI or XAI is becoming increasingly important as we seek to understand how AI systems arrive at their decision. We are also seeing a shift towards AI at the edge where 50:13 processing is done closer to data source and in the longer term the convergence of quantum computing and AI cloud unlock entirely new possibilities. The rapid growth of AI is creating a surge in demand for skilled professionals. There are a wide range of exciting career paths emerging in this field. Some of the key roles include machine learning engineers who design and build AI systems, data scientists who analyze data to extract insights, AI researchers who push the boundaries of AI knowledge, AI ethicist who help ensure responsible AI development, NLP specialist who work on language based AI, and computer vision engineers who develop systems that can see. These roles typically require a strong foundation in computer science, mathematics and statistics as well as specialized knowledge in AI related areas. Let's move on to the next topic which is gen AI or generative AI. 51:16 Generative AI or Gen AI is a type of artificial intelligence that create new original content like text, images, audio and video. It learns patterns from vast amount of existing data to generate noble outputs that resembles the data it was trained on. The next question is how do these models achieve such a feat. It happens in two main phases. First the learning the distribution phase. The model is fed vast amount of existing data perhaps millions of images, articles or audio clips. It meticulously analyzes this data to understand its statistical properties and hidden rules and the fundamental patterns that define it. For example, when I'm learning about human faces, it understand things like a common placement of eyes, nose, and mouth and how they can relate to each other. Once it has learned this deep understanding, we move to the generating 52:18 new samples phase. The model can then sample from this internal representation. It does not just copy and paste. It uses its learned understanding to originate new data instance that are statistically similar to what it was trained on, making them appear incredibly realistic and novel. To truly grasp generative AIs, it's essential to understand how it stands apart from discriminative AI. Let's look at a quick comparison. for learning objective. Discriminative AI aims to map inputs to specific labels or values. It learns the boundary between different categories. Generative AI on the other hand aims to model the underlying data distribution. It learns the entire data space. Regarding the output type, discriminative AI output is typically a prediction, a classification or a score. Think of yes or no, cat or a dog, or even any numerical value. Generative 53:20 AI's output is a new data itself. This could be a new image, a new piece of text, a new sound or a new code. The question it ask is also differs. You can imagine discriminative AI asking what is this or is this X or Y. Generative AI is asking what could this be or more directly create something like this. Finally, their prime task diverge. Discriminative AI's primary task as prediction, classification, and regression. While generative AI's primary task are generation, synthesis, and data augmentation. This fundamental distinction highlights their difference purposes and approaches. Let's solidify this with some concrete examples for discriminative AI. A image recognition system that tells you this is a cat in a photo. It identify what's already there. A spam filter classifies an incoming 54:21 email as either spam or not. It distinguishly between two categories. A fraud detection system predicts if the credit card transaction is fraudulent based or historical patterns. Now, for generative AI, instead of just identifying if it's just a cat or a dog, generative AI can create a completely new image of a cat that has never existed before. Perhaps a cat wearing a tiny hat. Instead of just filtering spam, it can write an entirely new email draft for you from a few keywords. For a fraud detection, generative AI can synthesize new realistic but fake transaction data to train a discriminative fraud detection model more effectively, especially if the real fraud data is scarce. These examples clearly show the shift from analysis to creation. The capabilities of generative AI are truly vast and continue to expand. It's moving far beyond just 55:21 predicting outcomes to actively shaping and creating the digital world around us. Here's a glimpse at the spectrum of what generative AI can accomplish. It can generate humanlike test, astonishingly realistic images, functional code, natural sounding speech and audio, and even dynamic video. Beyond direct content creation, it's also incredibly powerful for data augmentation, which is crucial for training other AI models. Let's dive into each other capabilities. First up, we have text generation or natural language generation, which is NLG. This is one of the most recognized capabilities today, powering much of the public's interaction with AI. Generative AI models can produce humanlike text on various topics in various styles. Some of the use cases are wide ranging from content creation like generating articles, blog post, marketing copy or social media updates to summarization, 56:24 condensing long documents. It's behind smarter chat boards and virtual assistants enabling more natural and coherent conversations. and it's powerful tool for creative writing, helping with poems, stories or scripts. Next, we have generating images or visual creation. This is perhaps where generative AI has captured the most public imagination. These models can create entirely new images, photos, and artistic works from simple test description or modify the existing ones. Some of the use cases include art and design for generating unique artwork, illustration or concept art, product prototyping, rapidly visualizing product variation or architectural designing. It is also used in photo editing which performs task like image implanting which is filling the missing parts style transfer and upscaling resolution and even creating realistic textures and environments for virtual worlds in 57:27 gaming and simulation. Generative AI is increasingly powerful for generating code effective automatic parts of the development process. AI can act as a programming assistance generating code snippets, functions or even basic programs based on natural language description or the context of your existing code. Some of the use cases include code completion which is auto suggesting lines of code as you type significantly speeding up the development. It also fixes bugs identifying comma errors and purposing correction and also we are boiler plate generation creating standard function structures class definitions or common configuration and transforming natural language to code allowing developers to describe what they want in plain English and the AI converts into functional code. Now let's talk about generating speech and audio or voice and sound 58:27 synthesis. This capability allows AI to produce realistic human speech, compose original music and generate diverse sound effect. Some of the use cases include text to speech converting any return text into natural sounding speech perfect for virtual assistants, audio books or narrations. It is also used for voice cloning which replicates specific voice. It also includes music generation, composing, original melodies, harmonies or even full instrumental tax and creating custom sound effects for games, films or user interacts. Imagine having a AI narrator your presentation slides or compose a unique background score for your video. This is a new power of audio generation. The most complex but rapidly advancing capability is generating video which enables dynamic content creation. This involves producing new video content, 59:30 animating still images or manipulating existing video footage to create dynamic and compiling sense. Some of the use cases include video synthesis which is creating short video clips from text description or images. And it also plays a vital role in animations assisting animators by generating character movement, lip syncing. This capability also is in virtual avatars generating realistic talking head videos from text and advanced special effects enhancing or altering video content in ways previously through impossible. While still a frontier, the process in AI video generation is astonishing, allowing for unexpected creative control. Finally, let's discuss data augmentation, a critical behind the scene capability that enhances the performance of other AI models. Data augmentation is a process of increasing the amount and the diversity of the 1:00:30 training data. Generative AI plays a vital role here by creating modified versions of existing data or more powerful synthesis entirely which is new realistic data that aders to the patterns learned from the real data. Why is it even important? It overcomes data security when real world data is limited. It provides model robustness by making models less sensitive to minor variations. It helps address data imbalance, ensuring models learn effectively from under represented categories and it's crucial for privacy, allowing the use of synthetic data when the real data is sensitive. Generative AI helps teach other AI models by creating more varied and comprehensive learning material. Let's see some examples where I'm going to create images and videos from a prompt. NLP in the next 10 minutes. So, what can you expect from this video? What's in it for 1:01:32 you? First, we'll give you a basic understanding of NLP. We'll tell you why we need NLP and we'll talk about what NLP exactly is. Next, we'll look at NLP pipelines. NLP pipelines cover the basic processes involved in text passing in NLP, which means converting text to a form suitable for machines to understand as humans would understand it. And finally, we'll talk about some real world applications of NLP which are all around us and a lot more common than you might have realized. So let's get started. So what exactly is NLP? Before we talk about NLP, let's talk about how humans talk and interact with each other. Humans communicate with each other mostly via speech or text. To convey your intent to someone, you may directly talk to them or send them a message. The human way of communicating is known as natural language. Around the globe, many languages are spoken and messages are shared virtually every 1:02:33 single day. All these conversations, feedbacks and messages are data in themselves. This data is extremely valuable as it can give us customer information and insight into human sentiment. However, this data is not useful to computers as it is not in a form that can be understood by machines. Machines communicate using ones and zeros and not via words. They cannot understand English, French or Spanish only binary. And this is where NLP comes into the picture. NLP stands for natural language processing. Natural language processing is a branch of artificial intelligence that deals with the interactions between humans and computers using the natural language. The ultimate objective of NLP is to read, decipher, understand, and make sense of human languages in a manner that is valuable and to build systems that can make sense of text and perform tasks like translation, grammar checking or topic classification. 1:03:35 NLP basically is the task of processing written forms of languages and making a computer understand them. Companies are increasingly using NLP equipped tools to gain insights from data and to automate routine tasks. A sentiment analyzer, for instance, can help brands detect emotions in text such as negative comments on social media. NLP at the end of the day is nothing more than accumulation of artificial intelligence, computer science, and the human language. The next topic that we'll be looking at are NLP pipelines. So what exactly are pipelines? A pipeline is a set of data processing elements which are connected in series where the output of one element is the input of the next one. It basically represents the various steps which have to be taken in our computation and the order in which they occur. In this pipeline we are going to be parsing our data. Parsing means converting our data from one form to 1:04:35 another. In this case, we are parsing our input text data to a file which can be understood by a computer. The text is first broken into segments and the segments are then converted into even smaller tokens. The word stems of all of these tokens are found followed by finding the root words of these stems in a process known as leatization. We will then recognize which part of speech the word belongs to. Which means if the word is a verb, a noun or a pronoun. And finally, we will separate the instances of everyday popular entities from our words to better understand what the sentence is trying to convey. The final file that we'll get will be a file which will be understood by a computer. Segmentation. The first process of a pipeline is segmentation. Now what exactly is segmentation? Sentence segmentation or text segmentation is basically dividing the 1:05:37 given text into logically decipherable units of information. We divide the sentence into its constituent subsentes usually along the punctuations like full stops or commas or along line breaks and page components for HTML files. Dividing a document into its constituent sentences allows us to process it without losing its essence and the necessary information that it contains. In this case, let's consider a sentence. The lemonade quenched her thirst but not her longing. After sentence segmentation, we are going to divide the sentence into two. The first sentence is going to be the lemonade quenched her thirst. And the second one is going to be but not her longing. The next step of our pipeline is called tokenization. Tokenization is nothing but the process of dividing a sentence into its constituent words. The sentence that is given to us will be separated and all the words in the sentence will be stored 1:06:39 separately. This is done so we can understand the syntactic and semantic information contained in each sentence. Thus, we decipher the relevance of a sentence by analyzing it word by word, thereby making sure that no loss of information occurs. The computer does not understand punctuations and special characters. Hence, we can remove any punctuations and special characters which may occur. Let's take a part of a previously segmented sentence. Over here, let's consider the lemonade quenched her thirst. After tokenization, we are going to separate every single word in the sentence. So after tokenization, we are going to get five different tokens. The, lemonade, quenched, her, and thirst. All of these are going to be treated as separate entities. After tokenization, we perform stemming. Stemming is a process of obtaining the word stems of a word. Word stems are also known as the base form of a word. And we can create new words by 1:07:41 attaching affixes to them in a process known as inflection. Stemming is a process of recognizing the word stems of individual words. This is done by removing a fixes such as ing, s, ed, etc. For example, consider a sentence jump. Jump is the word stem of various different words like jumping, jumped and jumps. If we remove all of these affixes, we will get our basic word stem which is jump. This is basically what we want at the end of stemming. The next process in our pipeline is called lemitization. Lemitization is the process of figuring out the root form or root word which is nothing but the most basic form also known as the lema of each word in the sentence. Lemitization is very similar to stemming where we remove word affixes to get the base form of a word. The difference is that the root word is always a word which is present in the dictionary. But the root stem may not 1:08:42 be. So lemitization uses a knowledge base called word net. Let's consider three different words went, going, and gone. At the end of the day, all of these words have originated from a single word which is go. In this case, go is our lema. All the other words which are derived from go can be traced back to it. The next part of our pipeline is called part of speech tagging. Part of speech tagging is a process of converting a sentence to different forms. It can be a list of words or a list of pupils. The tag in case of is a part of speech tag and signifies whether the word is a noun, adjective, verb and so on. We are basically splitting our verbs into their grammatical components to understand the meaning of any sentence or to extract relationships and to build a knowledge graph. Part of speech tagging is a very important step as the same word can have different part of speeches in different 1:09:42 sentences. For example, let's consider the sentence give me your answer. In this sentence, answer is a noun. But if we consider another sentence answer the question over here answer will be a verb using part of speech tagging we can take our different tokens and find the different part of speech that it belongs to. In this case the is a determiner lemonade is a noun quenched is a verb. Her is a pronoun and thirst is a noun. The final step in our NLP pipeline that we are looking at here is nothing but named entity recognition. Named entity recognition, also known as named entity identification, entity chunking and entity extraction is a subtask of information extraction that seeks to locate and classify named entities which are mentioned in unstructured text into predefined categories. Extracting the 1:10:42 main entities in a text helps us sort unstructured data and detect important information which is crucial if you have to deal with large data sets. The subcategories that we are considering are person, whether the named entity is a person, whether it's a quantity like kilograms, a location, an organization, the name of a movie, or whether it's a monetary value like dollars or euros. So far, we've looked at what NLP is and how we can perform natural language processing. But what are some applications of it and where is it used in the real world? One of the applications of NLP is in chat bots. Chatbots can help you solve issues while performing natural language generation. In other words, they can hold a conversation in plain English. A chatbot is nothing but a software application which can be used to conduct 1:11:44 an online chat conversation either through text or speech in place of providing direct contact with a live human agent. You might have seen those talk to one of our agents section on websites. Those are usually chat bots. A lot of companies also use WhatsApp chat bots to make the process seem less mechanical. Another application of NLP is speech recognition. Probably the most popular example of NLP in action are virtual assistants like Google Assist, Siri, and Alexa. Natural language processing understands and translates the human language like, "Hey Siri, where is the nearest gas station?" into numbers, making it easy for machines to understand. They recognize when you are talking, converting speech to text, and understand what you requested. Over the years, virtual assistants have become streamlined enough to be able to emulate human speech patterns almost flawlessly. Another application of NLP is 1:12:44 autocorrection. Autocorrection, also known as text replacement, replace as you type, or simply autocorrect, is an automatic data validation function commonly found in word processors and text editing interfaces for smartphones and tablet computers. It acts as a spell check and corrects any spellings or grammar mistakes which may arise as you are typing. Some language check softwares like Grammarly, Paperrator, Reverso and others can even check how unique and engaging your articles are and all of this is done using NLP. So as you can see I have headed over to the homepage of Invido AI. So I would say that in video AI is a fantastic tool for creating high quality videos and personally my favorite directly from your text prompts or images. It's incredibly versatile. So now so we'll just see from this navigation bar here. So we have got this plugins or voices text to clip text to image. So we'll just be clicking on text 1:13:48 to clip from here because we want to generate. So we'll just be clicking on this create AI video from scratch and after we click on this we have to provide a topic or any detailed instruction of what video you want to create. So we also have this other option of creating a short video whether your topic is about making an explainer video or if you want to create an animated film or you want to just simply use your script or whatever. So right now we will just be giving off a prompt. A cat sneaking out of the house and exploring the city from its point of view. And this is the visuals I would want to show sneaking into the fish market and then returning home just in time. So I will say I'll just create and if you want to create an animated film but then we don't have this in our free version. So we'll just be clicking on generate video from here and we'll wait for a few seconds. Now as you can see it is analyzing our video from here. So 1:14:48 after it has analyzed it has also given a title name of like the secret life of a sneaky cat mission tune and this is really impressive. And then from here we'll just select on the visual style whatever visual style you want whether it's realistic animation anime. So I'll just click on realistic and I want my video to be under 30 seconds. And in which platform are you wanting to post your video. So I'll just click on YouTube shorts and I'll just be clicking on continue. So you can see with you have this plus version where you can select any visual style you want which is $35 per month. Now we will be using the free version. So we can just proceed with the stock media and then we'll just continue. We'll wait for a few seconds till our video is being created fully. So, now that our video is being created, I'll just play and show you our video. If your cat's got a secret agent vibe, you're in for a wild ride. Meet Whiskers, our fearless feline adventure. 1:15:49 Today, he's sneaking out for a top secret mission, exploring the bustling streets of Bengaluru. First stop, the rooftops. Whiskers leaps from one to another like a furry superhero. He pauses, tail twitching, spying on the world below. Next, it's the classic car dodge. Whiskers weaves through the traffic like a pro, earning his stripes as a street serving kitty. Meow Nific. What's this? The fish. So now that you see the result is really impressive and it's really amazing. Within just a single prompt I mean just a text you can create a wholly working video in front of you and I personally liked it the most. So first we'll see what is prompt engineering. So let's demystify what prompt engineering actually is. In the simplest terms, it's the art and science of crafting inputs or prompts to effectively communicate with AI models like GPD3, DALE, and others. It's about being precise, creative, and strategic to elicit the best possible responses. But why does it matter? Well, with the 1:16:50 right prompt, you can unlock the full potential of AI from generating artistic masterpieces to solving complex problem. Let's break it down into the basics. A good prompt should be clear, concise, and directed. And you should avoid ambiguity, and be as descriptive as necessary. Remember, you are guiding the AI to understand exactly what you want. Here's where the magic of prompt engineering really comes into play. By tweaking just a few words, you can dramatically change the output. As you del deeper into various instances and uses of prompt engineering, it becomes evident that a prompt is composed of several key components. And now we'll see those components. A prompt may include any combination of the following components that is instruction, a precise action or directive you wish the model to execute. And then comes context that is background information or supplementary context that can guide the model towards more accurate responses. And then we have input data. The specific inquiry or data for which you 1:17:52 seek a response. And then comes output indicator. the desired structure or nature of the response. Not all four components are necessary for every prompt and their utilization varies based on the specific task. We will explore more detailed examples in the future tutorials. So, are you ready to level up your prompt engineering skills? Here are some pro tips. Use specific and detailed language, experiment with different phrasings, and consider the models limitations. And don't forget to iterate. The best prompt engineers constantly refine their prompts based on the AI's responses. All right, it's time to put theory into practice. I will walk you through a live demonstration of crafting prompts for different scenarios. Watch closely as I adjust the wording and structure to achieve the desired outcomes. Feel free to follow along with your own AI tool. So here we'll use the chat GPT and that is the GB4 version. And before starting, I want to tell you that even experts make mistakes. Here are some common pitfalls to avoid in prompt engineering. Over 1:18:53 complicating your prompt, being too vague, or misunderstanding the AI's capabilities can lead to unexpected and sometimes hilarious results. Learn from these missteps to perfect your technique. So now we'll start with the demo and first we'll open our chat GPT. So let's start with the first prompt and we name it as text condensation and refinement. So in this text condensation is a critical skill that is used in natural language processing and serving as a broad spectrum of domains. Among the most exciting applications for language models is their ability to distill complex models and complex articles and concepts into brief easy to understand summaries. Let's dive into an enhanced text condensation exercise using prompts. Suppose you are curious about the role of antioxidants in the body. You might craft a prompt like this that I will write summarize the role of antioxidants. 1:19:59 So now let's see what our chbd gives us the output. 1:20:16 So you can see that the chat JD has completed its response and like to refine this information further you might instruct the chat JPD or your model to encapsulate the essence in a shorter format. So for that you can write a prompt that use the above context and summarize this into some 100 words or some 200 words or just condense this into a brief explanation. So we will do that 1:21:02 So now you can see that the chat GPT has taken our query or the prompt and it has condensed the above content into brief explanation. So accordingly you could use different prompts and now we'll move to Dallay and we'll generate a image and here we'll like we'll use the condensed format only to give a prompt to Dalai. So we'll write generate a highly detailed image of a futuristic city. Uh and we can specify what time of day we want that at dusk and featuring towering skyscrapers with glowing windows or flying cars and a sky filled with neon colored clouds. So we can give the prompt or generate prompt like that only. So we will write the prompt for that is detailed image 1:22:02 of a futuristic city and here we will specify the time for the day uh that would be at dusk and featuring towering skyscrapers with glowing windows, flying cars, and what you need to specify. You could do that. 1:22:52 So let's see what DA respond to us and you could see that it's repeat and you could see that D is creating image now with the prompt we entered and this is the response. So it has given us that here are the images of the futuristic city at dusk featuring towing skyscrapers with glowing windows, flying cars and a sky filled with neon colored clouds. You could see the picture here. So similarly you can give prompts to Dalai or any other AI tool and you can get the output as expected and you can iterate your prompts according to the AI's capabilities. And now moving back to chat GPT. So here we will come to another type of prompt that is information synthesis and retrieval. So these language models excel not only in language generation but also in extracting and synthesizing information from text. So we will consider this prompt that is designed to pull specific 1:23:54 details from a given narrative. So we will ask it that researchers often use various AI tools including LLMs like open age GPT in their studies. So I have a prompt written. We will use that and let's see what chat GPT gives the response for this prompt. So you could see here that researchers often use various AI tools including LLMs like open GPT in their studies. Transparent disclosure of these tools helps maintain integrity in specific publication. So it's important for authors to disclose the context and extent of AI assistance in the research and journals should be upfront about their AI usage in the review process. So identify the specific LLM that is large language model mentioned in the text. So let's see if he can guess. So you could see that chat gd has given the response that the specific language model lm mentioned in the text is open GPD. So 1:24:57 so this was about the prompt information synthesis and retrieval. Now moving to the next prompt. So our next prompt here is enhanced query response. So optimizing how models respond to queries involves crafting more intricate prompts that guide the AI to deliver precise and useful answers. So for this we'll write a prompt that would be provide an answer based on the context given. So be successcent and clear. If uncertain respond with cannot confirm. So we will write the prompt for this and I have written the prompt earlier. So I'll show you guys. This is the prompt and we'll ask JJ GPT about the enhanced query response. So we have pasted the prompt here and our prompt is provide an answer based on the context given that is be susent and clear if uncertain provide with cannot confirm. So our prompt is here the innovative drug Alzma was developed as a result of collaborative efforts between several biotech firms. So this drug aimed at treating 1:25:58 autoimmune disorders represent a significant breakthrough in biio medicine. So we'll ask the chat JPY the question what is the purpose of alzumab. So let's see what it respond to us. So you could see that the chat deputy has responded. The purpose of alumab is to treat autoimmune disorders. So this is the type of prompt that is named as enhanced query response. So it optimizes how models respond to queries involve crafting more intricate prompts that guide the AI to deliver precise and useful answers. So now we'll move to the next type of prompt that is advanced text categorization. So to handle more complex task combining detailed instructions with context and examples can significantly enhance the model's performance. So here we will write the prompt to assess the sentiment of the following statements. So we will write some statements and ask a jet or AI model to assess them and classify them as negative, positive or neutral. So 1:26:59 let's see. We'll write a prompt here. Assess the sentiment of the following statement as positive, negative or neutral. And after this we will provide a statement to chat GPD. So our statement would be the movies stunning visuals overshadow its weak story line. 1:27:52 So let's see how Chad Gypty classifies this statement as positive, negative or neutral. So you could see that the chat jeopardy has generated its response and it stated that the sentiment of this statement the movie is stunning visuals or shadow its weak story line is mixed. It acknowledges a positive aspect that is stunning visuals and a negative one weak story line. So you could see here that the chat GPT can be used for sentiment analysis. So you could provide statements and ask chat GP whether it's positive, neutral or negative. Now moving to the next prompt. So our next prompt is dynamic conversations. So creating conversational systems that adapt to various tones and complexities is a fascinating application of prompt engineering. So here's how you might design a system to provide simplified friendly response. So for this we'll write a prompt and let's see what your AI model and our chat GP will give a response. So this is a conversation. 1:28:57 So here we'll write a prompt and start a conversation with our AI model. So first we'll write hi there, what's your role? So let's see what it responds. 1:29:14 So as our AI model chat GBT it states that hello my role is to assist you by providing information answering questions and helping with a wide range of task. How can I assist you today? So you can continue the conversation here and we'll continue and ask him whether you know about photosynthesis. If yes, kindly explain it to me. 1:29:53 So you could see that our chipy has started generating the response and it has stated that yes, I can explain photosynthesis and it's a process used by plants align certain bacteria to convert light energy usually from the sun into chemical energy. Repeat. usually from the sun into chemical energy and it is giving us some examples. You could go through that and you can continue your conversation with your AI model. So this is the another kind of prompt. Now we'll move to the next prompt type that is the innovative code generation. So expanding on the potential of LLMs that is large language models in code generation. Let's explore a more intricate example that is we'll ask them to write a code for us. So we'll write a prompt that would be write a Python function that calculates the factorial of a number and prints the result. So let's see what JP will respond to this. 1:31:06 So you could see that JP is showing analyzing. So it's analyzing a statement and after that it will start generating the code for us. And you could see that it has generated the code and it has the prompts or the statements that explain the code itself. So if you want this code as understandable, you could ask the chat JPY to explain it line by line 1:31:44 and you could see that the chat JP has done the task for you. 1:32:01 So you could see that it has completed its response and it has explained each line of the code with all the necessity concepts. So moving now. So these enhanced prompts and examples showcase how versatile and powerful language models can be and within well structured and throughout instructions. As we continue to explore and experiment with these prompts, the potential for creating sophisticated, nuanced, and highly functional airdriven applications become increasingly evident. So these are the types of prompts you could try on. Let's move on to the next topic which is building AI powered chatboards without programming. For many, the idea of building AI powered chatbot might immediately conjure images of complex code and specialized programming languages. But I'm here to tell you that the landscape has fundamentally shifted. Today's generative AI and no code tools mean that sophisticated chatbots are no 1:33:03 longer exclusive domain of developers. You can go for beyond simple question and answer both building dynamic intelligent assistance. Our focus is on empowering you with the job ready skills that businesses are actively seeking. Skills centered around understanding user needs, designing logical conversational flows and integrating various AI compounds all without needing to write a single line of code. So why are businesses so eager to adopt AI powered chatboards? The benefits are compelling. Firstly, they are offer 24 by7 availability, meaning your customer can get answers or assistance around the clock regardless of time zones. This leads to improved efficiency as routine inquires and tasks are automated, freeing up your human customer service agents to handle more complex or sensitive issues. The result is significantly enhanced customer experience, faster response, consistent 1:34:05 information, and reduced weight time. All of this contributes to cost reduction and allows businesses to scale their customer service operations without proportional increase in staffing. One of the most powerful ways to elevate your chatboard is by embedding an AI powered recommendation system. This moves your chatboard beyond generic responses to truly personalized customer services. So what exactly are recommendation systems? They are AI algorithms that analyze data to suggest relevant products, services or information to individual users in a no code chat environment. This means you configure your chatboard to listen for cues from the users. Perhaps they started preferences, browse history if integrator or previous interaction and then using predefined rules or simple integrations, the chatboard platform displays tailored suggestion from your product or service catalog. The benefits 1:35:08 are clear. Increase sales through targeted recommendation, improved user satisfaction because they feel understood and the ability offer proactive help assistance. Now let's talk about building complex workflows. This is where your chatbot really comes alive and handles diverse user needs beyond a simple back and forth. A workflow is essential the structure part of a conversation that based on user inputs and system logic in no code platforms. You'll be working with key elements like intents which help AI understand the user goals. For example, I want to check my order status. Then there are entities to check my order status which are pieces of crucial information extracted from the user's request like an order number. Based on this, the chatbot performs actions which could be displaying information asking follow-up questions or even connecting to a external system. 1:36:10 All of this is driven by conditional logic. Essentially, if the user says X, then do Y. Throughout this process, rigorous testing is absolutely crucial to ensure smooth, logical, and error-free interaction. Designing complex workflow is an art form. It often stays with mapping out conversation, literally drawing out potential user journeys and how your chatbot will respond to each step. You will then move to prototyping, building early versions to test the core functionalities. For testing, don't just rely on yourself. Engage in self-resting by running through every possible scenario you can think of. Then do peer testing. Ask colleagues to try and break your boat by asking unusual questions or trying unexpected parts. If possible, involve user acceptance testing which is UAT with actual end users to gather authentic feedback. This entire process 1:37:12 is highly interactive. You'll continually refine your chatboard based on insights gained from testing, ensuring it's robust and userfriendly. Finally, the moment of truth, deploying your chatbot in a realw world scenario. This involves several key steps. First, you'll need to choose the right channel where your target audience communicates. Whether it's your website, Facebook, Messenger, WhatsApp or other platform. No platforms make integration incredibly straightforward, often requiring just a simple copy paste of the embedded code or configuration of an API key. Once live, it's crucial to monitor your chatbot's performance, tracking user interaction, identifying common queries, and spotting any errors. Chatbots are not set it and forget it. They require ongoing maintenance, updates to content and continuous improved based on real user data. And always remember to 1:38:12 consider security and privacy, especially when handling sensitive customer information even when you're writing the code. Here are some of the platforms that provide intuitive drag and drop interface where you can build conversational flows. Connect to data sources and deploy your chatbot on websites, apps or messaging platform. Here are popular no code chatbots builders. Each one has its pros and cons. TDO is great for customer support and lead generation. It can integrate with website, messenger, Instagram, and more. It also offers templates and AI based responses. Whereas chatfield is popular for Facebook Messenger bots, it is ideal for e-commerce and customer engagement. Many chat focuses on marketing and sales boards. It also works well with messenger, Instagram and WhatsApp. Landboard has powerful drag and drop builder. It can create webbased 1:39:13 chat boards and WhatsApp boards. It's a clean UI for designing chat experience. Coming to WordPress cloud, it offers AI capabilities and multilingual support. Ideal for more complex workflows with integration. Let's just give a short look on how TDO makes chatboard available without using any code. So as you guys can see this is TDIO. So initially it is going to ask you an email and what is the purpose of your visit? what you are wishing to create whether it's a chatboard or messenger integrated with chatboard um Instagram used for Instagram or WhatsApp chats. So here I'll give you a small example of how you can how easily you can create a chatboard. So there is an inbuilt LRO AI agent here. So these are the steps you need to follow to create a chatboard. So it includes adding the knowledge by providing the URL of your site. So you 1:40:13 have to add on which site this chatboard is going to go. So I'll give simply learn website. I'm just going to press import knowledge. So it gets all the information of the website. So you can chat with the LRO which is an AI chatbot created by TDIO. It will take some time. It will assess all the links related to simplylearn.com. It is accessing all the pages under simplearn.com. Whether it's the contact us page or about us page, every information it should be knowing. So now the AI is getting trained, the chatbot is getting trained. So after this is done, you can move on to test lido. If you do not want any particular link to be accessed in this data, you can 1:41:14 just click here and delete it. So since I don't want and I'm going to test the chatbot now whose name is LRO. So here's the chatbot. So here it is saying hi how can I help you? So here are pre-built question. So is it it is okay for you to choose and test the knowledge. So you can see this providing questions and answers. So let me type in something specific to see if the knowledge is there and I'm going to send this. Let me see if it will suggest any course which will upskill my current position. So yeah to recommend the most suitable course you could please tell me your current position or field of work. We offer various specialization. So it's asking me input. So I'll say my current position 1:42:16 is data analyst. 1:42:26 So it has suggested me few of the courses for your data analyst role. I recommend for our business analyst course featuring Excel and PowerBI training and Tableau certification. These course will enhance your data visualization and analysis skills or it is regarding alumini also and the salaries and the certification every information is being provided. So this you can integrate to your original website and you will have a chatboard without even coding one single sentence. As we conclude AI foundation for everyone, I hope you feel not just informed but empowered. You have gained a fundamental understanding of what AI is. Explored incredible creative power of generative AI. Learn how to communicate effectively with these models through prompt engineering and discover how to build practical AI powered chatboards all without writing a single line of code. The world of AI is constantly evolving but you have a solid 1:43:28 foundation to navigate it confidently. Remember AI is a tool and with the knowledge you have gained you are better equipped to leverage its potential responsible and creativity. Thank you for being a part of this journey. We encourage you to continue exploring, experimenting, and applying what you have learned. The future is exciting and you are now a part of it, shaping it. We look forward to seeing amazing things you will achieve. Today, we are diving into machine learning, the technology behind things like Netflix recommendations, CD, and even the face unlock of your phone. Machine learning helps devices get smarter by learning from data and predicting what we might like or need. And here's why machine learning is huge for your career. Right now, machine learning jobs are among the fastest growing roles worldwide. Companies in every industry, tech, healthcare, finance, and more are looking for people with machine learning skills to improve their products, automate tasks, and make smarter 1:44:28 decisions. Machine learning engineers in the US earn around $112,000 on average with plenty of room for growth as you gain experience. So if you want to jump into this exciting field, learning machine learning can open doors to highpaying in demand jobs. So in this video I'll guide you through the ultimate road map to master machine learning in 2025 one step at a time. So let's get started. So in the first month start with the foundations of programming. So programming is a language you'll use to communicate with your computer and bring machine learning algorithms to life. So this month is all about Python, the language of choice for most machine learning practitioners. So here's what to focus on. First, learn Python basics. Begin with Python's fundamentals like variables, data types, loops, and functions. So spend time writing small programs daily to get comfortable. After that, explore the key libraries like numpy, pandas, and scikitlearn. So numpy is for numerical 1:45:28 operations. It makes handling large data sets faster and easier. And pandas is to manipulate and analyze data. So pandas allow you to filter, sort and reshape data in a breeze. And then scikitlearn is for implementing algorithms in just a few lines of code. So now you might have heard about R, another language used in machine learning. But don't stress about it now. Python will serve you well, especially as a beginner, because it's simpler and more flexible. So aim to spend an hour or two each day coding. By the end of this month, you'll have a solid base to build on. Now, in the second month, get organized with version control and data structures. So, this month is about learning how to organize and manage your code effectively and sharpening your problem solving skills with data structures and algorithms. So, first is version control with Git. So, think of Git as your project history tracker. So, imagine working on a big project and making changes, then realizing something went wrong. You want to go back to an earlier version, right? So that's where git comes in. And here's 1:46:29 what you should practice. Number one is committing changes. So save different versions of your work as you progress. And then branching, which means work on separate features without affecting your main code. And then comes merging, which means combining changes from different versions once they are ready. So you have to set up an account on GitHub or GitLab to store your projects online. So not only will this be super useful but it'll also start building your portfolio. Now next is data structures and algorithm. So think of data structures like tools in a toolkit. So each one like arrays, stacks, cues, etc. serves a specific purpose. So here's how to approach them. Number one, arrays and lists. Now arrays and lists are for storing data in sequence. After that you can get familiar with stacks and cues. So stacks and cues are for tasks that need ordered data access. And then you have sorting and searching algorithms. So these make your programs more efficient and that's super important in machine learning where data can get massive. So the goal here is to build up 1:47:30 your problem solving skills which are key to machine learning success. So take it slow, practice daily and you'll see progress. Now in the third month, learn to access data with SQL. So in machine learning, a lot of work involves accessing and organizing data from databases. So SQL a structured query language is your ticket to getting the data you need for training ML models. So here's what you should focus on. Select and where. So these commands help you pull specific pieces of data. And then you can move on to joins. Joins usually combine data from different tables. So this is so powerful that you'll use it all the time. And then comes group by and aggregate functions. They are great for summarizing data to find patterns. So spend time working with sample databases you can find online and practice writing queries. Being comfortable with SQL will save you time when preparing data for your models. Now after completing the third month you can move on to mathematics which is building your analytical mind. So this month we are tackling the math behind machine 1:48:30 learning. So don't worry you don't need to be a math genius but understanding certain concepts will make everything feel less mysterious. So in this month you have to focus on linear algebra. So this is the map behind how models see data. So you can study vectors, matrices and operations like multiplication. Next comes calculus. So you'll use calculus to help your models learn. So you have to focus on derivatives and gradients which help minimize errors in your model. And then you can move on to probability and statistics. So understanding probability helps you make sense of data. So learn about distributions like normal distribution, bormal distribution and then variance and standard deviation. So once you have learned maths, next you'll be moving on to data handling and visualization which is the heart of machine learning as you all know. So with math under your belt, it's time to dig into data handling and visualization. So data preparation is vital because your model is only as good as the data you period. So number one comes data manipulation. So using pandas 1:49:30 and numpy, you'll clean and organize your data. You might be removing missing values like clean up messy data so it doesn't confuse your model. And then you will learn transforming variables like converting data into formats that work for models. And then you will move on to encoding categorical data like changing text data like female or male into numbers. Now once you're done with data manipulation next comes data visualization. So visualization is how you get to see your data before training a model. So here you have to learn mattplot lip and seabboard. So you can create line charts, histograms, scatter plots and heat maps. So this lets you explore patterns and spot outliers. So understanding these patterns in your data is crucial for building effective models. Now in the sixth month, you'll be moving on to the machine learning fundamentals. So now it's time to start building your own models. So you'll focus on two main types of machine learning this month. Number one comes the supervised learning. So this is when you train a model on label data where the outcome is already known. So you'll 1:50:30 work with algorithms like linear regression which predicts a continuous outcome. Then you'll work with decision trees which breaks down decisions into a tree structure. And then you have support vector machines under supervised learning which seates data into classes. Now after supervised learning comes unsupervised learning. So here your model identifies patterns and data without labeled outcomes. So two popular techniques in unsupervised learning is number one clustering like K means clustering which means group similar data points and then you have dimensionality reduction. This reduces data complexity by focusing on key features. So you can use scikitlearn to try out these algorithms on sample data sets. So this will give you hands-on experience with model training and you will learn to fine-tune them to get better results. Now moving on to the seventh month, you'll be building and training models with advanced libraries. So by now you have experimented with some basic models. So let's step it up with advanced tools like TensorFlow and PyTorch. So these libraries offer more flexibility and power. So TensorFlow and 1:51:31 PyTorch. So here you can start with simple models and work your way up. So these libraries allow for building neural networks which you'll be studying more on the next month. Now once you have become familiar with TensorFlow and PyTorch, you can move on to model training and evaluation. So you have to learn to split data into training and testing sets and evaluate models using metrics like accuracy and precision. So your goal this month should be to get comfortable with these libraries and understand how they handle data and model training behind the scenes. So once you are done with this, you'll be moving on to the eighth month where you'll be dealing with advanced machine learning. So this month's concept will be number one on nse symbol learning which means combining multiple models to get better predictions. So here you'll be learning about bagging for example random forests. Here multiple decision trees make predictions and then you have boosting like ada boost, xg boost. So models learn from each other's mistakes over here and after ensemble learning comes deep learning. So here you explore neural networks which mimic the human 1:52:32 brain. So you learn about neural network basics. So you can start with simple fully connected networks and then you can move on to back propagation and gradient descent. So this helps your model learn and improve. So you can use TensorFlow or PyTorch to practice building neural networks. So you can work on projects to reinforce these concepts. Now moving on, you have to specialize on topics like NLP and computer vision. So machine learning applications are so powerful and here you'll get a taste of two major fields which is NLP or natural language processing. So here they work with text data for tasks like sentiment analysis and text classification. So you can start with basic pre-processing like tokenization, stop word removal and move to building simple NLP models. After that you can try out computer vision. So for image data you have to learn CNN, convolutional neural networks. So these network analyze visual patterns making them ideal for image classification. So you practice with open data sets like text, documents or images and apply the concepts you will learn to see results 1:53:33 in real world applications. Now in the 10th month you'll be dealing with model deployment which is bringing your models to life. So here you'll be using Flask or Django. So you can use these frameworks to create a web API so users can interact with your model. For example, build a web app that lets people upload images for classification. And then you can also try out Docker. So package your model and its dependencies so it can run on any machine. So this is super helpful for deploying models without compatibility issues. So by the end of this month, you'll be able to share your models with the world. So moving on to the 11th month, you'll be starting with cloud and production. So this month, you'll learn how to deploy models on the cloud and ensure they perform well in real world environments. So you'll be dealing with cloud platforms like AWS, Google Cloud or Azure. So you have to learn to deploy models on the cloud for wider accessibility and scalability. And then comes monitoring and maintenance. So understand how to track your models performance over time and update it as needed. So these skills are essential for maintaining models in production and 1:54:35 ensuring they stay reliable. And finally you'll be creating real world projects and portfolio building. So here you have to choose topics that interest you and showcase your skills. So first you can start with full projects. So complete projects that go from data cleaning and model building to deployment. So ideas could be a sentiment analysis tool or an image recognition app. And then you have to build your portfolio. So organize and document your projects, host them on GitHub, and create an online portfolio to share with potential employers or collaborators. So by following this road map, you'll be well prepared to handle real world machine learning challenges and have an impressive portfolio to show for it. So thank you so much for joining me on this ultimate road map to mastering machine learning in 2025. I hope this monthby-month guide gives you a clear achievable path to dive into machine learning from the basics to deploying your own models. Remember, learning machine learning is a journey. There will be challenges along the way, but with patience and consistent practice, you'll see progress step by step. LLMs, if you ever wondered how 1:55:38 machine learning can now understand and generate humanlike text, you are in the right place. From chatboards like chat jeepy to AI assistant that powers search engines, LLMs are transforming how we interact with technology. One of the most exciting advancement in this space is Google's Gemini or OpenAI Charging large language model designed to push the boundaries of what AI can achieve. In this video, we will explore what LLMs are, how they work, and why models like Gemini are critical for the future of AI. Google Gemini is part of a new wave of AI models that are smarter, faster, and more efficient. It is designed to understand context better, offer more accurate responses, and integrate deeply into service like Google search and Google Assistant, providing more humanlike interactions. So, we will break down the science behind LLMs, including their massive training data set, transformer architecture, and how models like Gemini use deep learning innovation to change industries. Plus, we will compare Google Gemini to other popular LMS such as OpenAI Chaty models, 1:56:40 showing how each of these technologies is used to power chat bots, virtual assistants, and other AIdriven application. By end of this video, you will have a clear understanding of how large language models like Gemini work, their key features, and what they mean for their future AI. Don't forget to like, subscribe, and hit the bell icon to never miss any update from Simply Learn. So, what are the large language models? Large language models like CH GPD4 generative pre-trained transformer 4 O and Google Gemini are sophisticated AI system designed to comprehend and generate humanlike text. These models are built using deep learning techniques and are trained on vast data set collected from the internet. They leverage self attention mechanism to analyze relationship between words or tokens allowing them to capture context and produce coherent relevant responses. LLMs have significant application including powering virtual assistant, chatboards, content creation, language translation and supporting research and decision making. Their ability to generate fluent and contextually appropriate text has advanced natural 1:57:41 language processing and improved human computer interaction. So now let's see what are large language model used for. Large language models are utilized in scenarios with limited or no domain specific data available for training. These scenarios include both few short and zero short training approaches which rely on the model's strong inductive bias and its capability to derive meaningful representation from a small amount of data or even no data at all. So now let's see how are large language model train. Large language models typically undergo pre-training on a board. All encompassing data set that shares statical similarities with the data set specific to the target task. The objective of pre-training is to enable the model to require highlevel feature that can later be applied during the fine-tuning phase for specific task. So there are some training processes of LLM which involves several steps. The first one is text prep-processing. The textual data is transformed into a numerical representation that the LLM model can effectively process. This conversion may be involve techniques like tokenization, encoding and creating 1:58:42 input sequences. The second one is random parameter initialization. The model's parameter are initialized randomly before the training process begins. The third one is input numerical data. The numerical representation of the text data is fed into the model of processing. The model's architecture typically based on transformers allows it to capture the conceptual relationship between the words or tokens in the next. The fourth one is loss function calculation. A loss function calculation measure the discrepancy between the model's prediction and the actual next word or token in a syntax. The LLM model aims to minimize this loss during training. The fifth one is parameter optimization. The model's parameter are registers through optimization technique. This involves calculating gradient and updating the parameters accordingly gradually improving the model's performance. The last one is iterative training. The training process is repeated over multiple iteration or epochs until the model's output achieve a satisfactory level of accuracy on that given task or data set. By following this training process, large language model learn to capture linguistic patterns, understand 1:59:42 context and generate coherent responses, enabling them to excel at various language related tasks. The next topic is how do large language models work. So large language models leverage deep neural network to generate output based on patterns learned from the training data. Typically a large language model adopts a transformer architecture which enables the model to identify relationship between words in a sentence irrespective of their position in the sequence. In contrast to RNNs that rely on recurrence to capture token relationship transform neural network employ self attention as their primary mechanism. Self attention calculates attention scores that determine the importance of each token with respect to the other token in the text sequence facilitating the modeling of intricate relationship within the data. Next, let's see application of large language models. Large language models have a wide range of application across various domains. So here are some notable application. The first one is natural language processing NLP. Large language models are used to improve natural language understanding tasks such as sentiment analysis, named entity 2:00:43 recognition, text classification and language modeling. The second one is chatbot and virtual assistant. Large language models power conversational agents, chatbots and virtual assistant providing more interactive and humanlike user interaction. The third one is machine translation. LA language models have been used for automatic language translation enabling text translation between different languages with improved accuracy. The fourth one is sentiment analysis. LLMs can analyze and classify the sentiment or emotion expressed in a piece of text which is valuable for market research, brand monitoring and social media analysis. The fifth one is content recommendation. These models can be employed to provide personalized content recommendations enhancing user experience and engagement on platforms such as news website or streaming services. So these application highlight the potential impact of large language models in various domains for improving language understanding automation. What's in it for you? We're going to cover clustering. What is clustering? K means clustering which is one of the most common used clustering 2:01:44 tools out there including a flowchart to understand K means clustering and how it functions. And then we'll do an actual Python live demo on clustering of cars based on brands. Then we're going to cover logistic regression. What is logistic regression? Logistic regression curve and sigmoid function. And then we'll do another Python code demo to classify a tumor as malignant or benign based on features. And let's start with clustering. Suppose we have a pile of books of different genres. Now, we divide them into different groups like fiction, horror, education, and as we can see from this young lady, she definitely is into heavy horror. You can just tell by those eyes and the maple Canadian leaf on her shirt. But we have fiction, horror, and education. And we want to go ahead and divide our books up. Well, organizing objects into groups based on similarity is clustering. And in this case, as we're looking at the books, we're talking about clustering things with known categories. But you can also use it to explore data. So you might not know the categories. You just 2:02:46 know that you need to divide it up in some way to conquer the data and to organize it better. But in this case, we're going to be looking at clustering in specific categories. And let's just take a deeper look at that. We're going to use K means clustering. K means clustering is probably the most commonly used clustering tool in the machine learning library. K means clustering is an example of unsupervised learning. If you remember from our previous thing, it is used when you have unlabeled data. So we don't know the answer yet. We have a bunch of data that we want to cluster to different groups. Define clusters in the data based on feature similarity. So we've introduced a couple terms here. We've already talked about unsupervised learning and unlabeled data. So we don't know the answer yet. We're just going to group stuff together and see if we can find an unanswer connect. We've also introduced feature similarity. Features being different features of the data. Now with books, we can easily see fiction and horror and history books. But a lot of times with 2:03:46 data, some of that information isn't so easy to see right when we first look at it. And so K means is one of those tools where we can start finding things that connect that match with each other. Suppose we have these data points and want to assign them into a cluster. Now when I look at these data points I would probably group them into two clusters just by looking at them. I'd say two of these group of data kind of come together. But in K means we pick K clusters and assign random centroidids to clusters where the K clusters represents two different clusters. We pick K clusters and assign random centroidids to the clusters. Then we compute distance from objects to the centroidids. Now we form new clusters based on minimum distances and calculate the centrids. So we figure out what the best distance is for the centrid. Then we move the centrid and recalculate those distances. Repeat previous two steps iteratively till the cluster centroid stop changing their positions and become static. Repeat previous two steps iteratively till the cluster centroid stop changing and the positions 2:04:47 become static. Once the clusters become static, then K means clustering algorithm is said to be converged. And there's another term we see throughout machine learning is converged. That means whatever math we're using to figure out the answer has come to a solution or it's converged on an answer. Shall we see the flowchart to understand make a little bit more sense by putting it into a nice easy step by step? So we start, we choose K. We'll look at the elbow method in just a moment. We assign random centrids to clusters. And sometimes you pick the centrids because you might look at the data in a in a graph and say, "Ah, these are probably the central points. Then we compute the distance from the objects to the centrids. We take that and we form new clusters based on minimum distance and calculate their centrids. Then we compute the distance from objects to the new centrids. And then we go back and repeat those last two steps. We calculate the distances. So as we're doing it, it brings into the new centroidid and then we move the centrid around and we figure out what the best 2:05:48 which objects are closest to each centrid. So the objects can switch from one centrid to the other as the centroidids are moved around and we continue that until it is converged. Let's see an example of this. Suppose we have this data set of seven individuals and their score on two topics A and B. So here's our subject in this case referring to the person taking the uh test and then we have subject A where we see what they've scored on their first subject and we have subject B and we can see what they score on the second subject. Now let's take two farthest apart points as initial cluster centroidids. Now remember we talked about selecting them randomly or we can also just put them in different points and pick the furthest one apart so they move together. Either one works okay depending on what kind of data you're working on and what you know about it. So we took the two furthest points one and one and five and seven. And now let's take the two farthest apart points as initial cluster centrids. Each point is then assigned to the closest cluster with respect to the distance from the 2:06:50 centrids. So we take each one of these points in there. We measure that distance. And you can see that if we measured each of those distances and you use the the Pythagorean theorem for a triangle in this case because you know the x and the y and you can figure out the diagonal line from that or you can just take a ruler and put it on your monitor. That'd be kind of silly but it would work if you're just eyeballing it. You can see how they naturally come together in certain areas. Now we again calculate the centrids of each cluster. So cluster one and then cluster two and we look at each individual dot. There's one, two, three. We're in one cluster. Uh the centrid then moves over. It becomes 1.8 comma 2.3. So remember it was at one and one. Well, the very center of the data we're looking at would put it at the one point roughly 22, but 1.8 and 2.3. And the second one, if we wanted to make the overall mean vector, the average vector of all the different distances to that centrid, we come up with 4, 1, and 54. So we've now moved the centrids. We compare each 2:07:50 individual's distance to its own cluster mean and to that of the opposite cluster and we find build a nice chart on here that the as we move that centrid around we now have a new different kind of clustering of groups and using uklitian distance between the points and the mean we get the same formula. You see new formulas coming up. So we have our individual dots distance to the mean centrid of the cluster and distance to the mean cent of the cluster. only individual three is nearer to the mean of the opposite cluster cluster two than its own cluster one. And you can see here in the diagram where we've kind of circled that one in the middle. So when we've moved the clust the centrids of the clusters over one of the points shifted to the other cluster because it's closer to that group of individuals. Thus individual 3 is relocated to cluster two resulting in a new partition. And we regenerate all those numbers of how close they are to the different clusters. For the new clusters, we will find the actual cluster centroidids. So now we move the centrids over and you can see that we've now formed two very distinct clusters on 2:08:52 here. On comparing the distance of each individual's distance to its own cluster mean and to that of the opposite cluster, we find that the data points are stable. Hence we have our final clusters. Now if you remember I brought up a concept earlier K mean on the K means algorithm. Choosing the right value of K will help in less number of iterations. And to find the appropriate number of clusters in a data set, we use the elbow method. And within sum of squares, WSS is defined as the sum of the squared distance between each member of the cluster and its centrid. And so you see we've done here is we have the number of clusters. And as you do the same K means algorithm over the different clusters and you calculate what that centroid looks like and you find the optimal you can actually find the optimal number of clusters using the elbow. The graph is called as the elbow method. And on this we guessed at two just by looking at the data. But as you can see the slope you actually just look for right there where the elbow is in the slope and you have a clear answer 2:09:52 that we want two different to start with K means equals two. A lot of times people end up computing k means equals 2, three, four, five until they find the value which fits on the elbow joint. Sometimes you can just look at the data and if you're really good with that specific domain. Remember domain, I mentioned that last time, you'll know that that where to pick those numbers and where to start guessing at what that k value is. So let's take this and we're going to use a use case using K means clustering to cluster cars into brands using parameters such as horsepower, cubic inches, make, year, etc. So we're going to use the data set cars data having information about three brands of cars, Toyota, Honda, and Nissan. We'll go back to my favorite tool, the Anaconda Navigator with the Jupiter notebook. And let's go ahead and flip over to our Jupyter notebook. And in our Jupyter notebook, I'm going to go ahead and just paste the uh basic code that we usually start a lot of these off with. We're not going to go too much into this 2:10:53 code because we've already discussed numpy. We've already discussed mattplot library and pandas that be being the number array. Pandas being the pandas data frame and mapplot for the graphing. And don't forget uh since if you're using the Jupyter notebook, you do need the mattplot library in line so that it plots everything on the screen. If you're using a different Python editor, then you probably don't need that because it'll have a popup window on your computer. And we'll go ahead and run this just to load our libraries and our setup into here. The next step is, of course, to look at our data, which I've already opened up in a spreadsheet. And you can see here we have the miles per gallon, cylinders, cubic inches, horsepower, weight pounds, how, you know, how heavy it is, time it takes to get to 60. My cart is probably on this one at about 80 or 90 what year it is. So this is you can actually see this is kind of older cars and then the brand Toyota, Honda, Nissan. So the different cars are coming from all the way from 1971. If we scroll down to uh the 80s we 2:11:54 have between the 70s and 80s a number of cars that they've put out. And let's uh we come back here. We're going to do importing the data. So we'll go ahead and do data set equals and we'll use pandas to read this in. and it's uh from a CSV file. Remember, you can always post this in the comments and request the data files for these either in the comments here on the YouTube video or go to simplylearn.com and request that. The car CSV, I put it in the same folder as the code that I've stored. So, my Python code is stored in the same folder, so I don't have to put the full path. If you store them in different folders, you do have to change this and double check your name variables. And we'll go ahead and run this. And uh we've chosen data set arbitrarily because you know it's a data set we're importing. And we've now imported our car CSV into the data set. As you know, you have to prep the data. So we're going to create the X data. This is the one that we're going to try to figure out what's going on with. And then there is a number of ways to do this, but we'll do it in a simple loop so you can actually see what's going on. 2:12:54 So we'll do for i and x doc columns. So we're going to go through each of the columns. And a lot of times it's important I I'll make lists of the columns and do this because I might remove certain columns or there might be columns that I want to be processed differently. But for this we can go ahead and take x of i and we want to go fill in a and that's a pandas command. But the question is what are we going to fill the missing data with? We definitely don't want to just put in a number that doesn't actually mean something. And so one of the tricks you can do with this is we can take x of i and then addition to that we want to go ahead and turn this into an integer because a lot of these are integers. So we'll go ahead and keep it integers and let me add the bracket here. And a lot of editors will do this. They'll think that you're closing one bracket. Make sure you get that second bracket in there if it's a double bracket. That's always something that happens regularly. So once we have our integer of x of i, this is going to fill in any missing data with the average. And I was so busy 2:13:56 closing one set of brackets, I forgot that the mean is also has brackets in there for the pandas. So we can see here we're going to fill in all the data with the average value for that column. So if there's missing data is in the average of the data it does have. Then once we've done that, we'll go ahead and loop through it again and just check and see to make sure everything is filled in correctly. And we'll print. And then we take x is null. And this returns a set of the null value or the how many lines are null. And we'll just sum that up to see what that looks like. And so when I run this and so with the x, what we want to do is we want to remove the last column because that had the models. That's what we're trying to see if we can cluster these things and figure out the models. There is so many different ways to sort the x out. For one, we could take the X and we could go data set, our variable we're using, and use the eyelocation, one of the features that's in pandas, and we could take that and then take all the rows and all but the last column of the 2:14:59 data set. And at this time, we could do values. We just convert it to values. So, that's one way to do this. And if I let me just put this down here and print X, it's a capital X we chose. and I run this, you can see it's just the values. We could also take out the values and it's not going to return anything because there's no values connected to it. What I like to do with this is instead of doing the location which does integers more common is to come in here and we have our data set and we're going to do data set dot or data set.c columns and remember that lists all the columns. So if I come in here, let me just mark that as red and I print data set.c columns. You can see that I have my index here. I have my MPG cylinders everything including the brand which we don't want. So the way to get rid of the brand would be to do data columns of everything but 2:15:59 the last one minus one. So now if I print this, you'll see the brand disappears. And so I can actually just take data set columns minus one and I'll put it right in here for the columns we're going to look at. And let's unmark this and unmark this. And now if I do an X.the head, I now have a new data frame. And you can see right here we have all the different columns except for the brand at the end of the year. And it turns out when you start playing with the data set, you're going to get an error later on and it'll say cannot convert string to float value. And that's because for some reason these things the way they recorded them must have been recorded as strings. So we have a neat feature in here on pandas to convert. And it is simply convert objects. And for this we're going to do convert oops convert underscore 2:17:02 numeric numeric equals true. And yes, I did have to go look that up. I don't have it memorized the convert numeric in there. If I'm working with a lot of these things, I remember them, but um depending on where I'm at, what I'm doing, I usually have to look it up. And we run that. Oops, I must have missed something in here. Let me double check my spelling. And when I double check my spilling, you'll see I missed the first underscore in the convert objects. And when I run this, it now has everything converted into a numeric value because that's what we're going to be working with is numeric values down here. And the next part is that we need to go through the data and eliminate null values. Most people when they're doing small amounts, you working with small data pools discover afterwards that they have a null value and they have to go back and do this. So, you know, be aware whenever we're formatting this data, things are going to pop up and sometimes you go backwards to fix it. And that's fine. That's just part of exploring the data and understanding what you have. 2:18:02 And I should have done this earlier, but let me go ahead and increase the size of my window one notch. There we go. Easier to see. So, we'll do 4 I in working with X dot columns. will page through all the columns and we want to take x of i and we're going to change that we're going to alter it and so with this we want to go ahead and fill in x of i. Pandas has the fill in a and that just fills in any non-existent missing data. And we'll put my brackets up. And there's a lot of different ways to fill this data if you have a really large data set. Some people just void out that data because if and then look at it later in a separate exploration of data. One of the tricks we can do is we can take our column and we can find the means and the means is in there are quotation marks. So we take the columns we're 2:19:02 going to fill in the non-existing one with the means. The problem is that returns a decimal float. So some of these aren't decimals. Certainly we need to be a little careful of doing this. But for this example, we're just going to fill it in with the integer version of this. Keeps it on par with the other data that isn't a decimal point. And then what we also want to do is we want to double check. A lot of times you do this first part first to double check, then you do the fill, and then you do it again just to make sure you did it right. So we're going to go through and test for missing data. And one of the re ways you can do that is simply go in here and take our X of I column. So it's going to go through the X of I column. It says is null. So it's going to return any any place there's a null value. It actually goes through all the rows of each column is null. And then we want to go ahead and sum that. So we take that, we add the sum value. And these are all pandas. So isnull is a 2:20:02 panda command and so is sum. And if we go through that and we go ahead and run it and we go ahead and take and run that, you'll see that all the columns have zero null values. So we've now tested and double checked and our data is nice and clean. We have no null values. Everything is now a number value. We turned it into numeric and we've removed the last column in our data. And at this point, we're actually going to start using the elbow method to find the optimal number of clusters. So, we're now actually getting into the sklearn part. Uh, the K means clustering on here. I guess we'll go ahead and zoom it up one more notch so you can see what I'm typing in here. And then from sklearn going to or sklearn cluster, we're going to import k means. I always forget to capitalize the k and the m when I do this. So it's capital K, 2:21:02 capital M, K means. And we'll go and create a um array WCSS equals we'll make it an empty array. If you remember from the elbow method from our slide within the sums of squares, WSS is defined as the sum of squared distance between each member of the cluster and its centrid. So we're looking at that change in differences as far as a squared distance. And we're going to run this over a number of K mean values. In fact, let's go for I in range. We'll do 11 of them. Range zero of 11. And the first thing we're going to do is we're going to create the actual we'll do it all lowercase. And so we're going to create this object from the K means that we just imported. And the variable that we want to put into this is in clusters. We're going to 2:22:05 set that equals to I. That's the most important one because we're looking at how increasing the number of clusters changes our answer. There are a lot of settings to the K means. Our guys in the back did a great job just kind of playing with some of them. The most common ones that you see in a lot of stuff is how you admit your K means. So we have K means plus plus. This is just a tool to let the model itself be smart how it picks it centroidids to start with its initial centroidids. We only want to iterate no more than 300 times. We have a max iteration we put in there. We have the init the random state equals zero. You really don't need to worry too much about these when you're first learning this. As you start digging in deeper, you start finding that these are shortcuts that will speed up the process as far as a setup. But the big one that we're working with is the inclusters equals I. So, we're going to literally train our K means 11 times. We're going to do this process 11 times. And if 2:23:08 you're working with big data, you know, the first thing you do is you run a small sample of the data so you can test all your stuff on it. And you can already see the problem that if I'm going to iterate through a terabyte of data 11 times and then the K means itself is iterating through the data multiple times. That's a heck of a process. So you got to be a little careful with this. A lot of times though you can find your elbow using the elbow method, find your optimal number on a sample of data, especially if you're working with larger data sources. So we want to go ahead and take our K means and we're just going to fit it. If you're looking at any of the sklearn, very common you fit your model. And if you remember correctly, our variable we're using is the capital X. And once we fit this value, we go back to the array we made. And we want to go and just append that value on the end. And it's not the actual fit we're pinning in there. It's when it generates it, it generates the value you're looking for is inertia. So K means.inertia will pull that specific value out that we need. 2:24:11 And let's get a visual on this. We'll do our PLT plot. And what we're plotting here is first the X axis, which is range 0 11. So that will generate a nice little plot there. And the WCSS for our Y axis. It's always nice to give our plot a title. And let's see, we'll just give it the elbow method for the title. And let's get some labels. So let's go ahead and do PLT X label. And what we'll do, we'll do number of clusters for that. And PLT Y label. And for that, we can do Oops, there we go. WCSS since that's what we're doing on the plot on there. And finally, we want to go ahead and display our graph, which is simply plt. Oops. Show. There we go. And because we have it set to inline, it'll appear inline. Hopefully I didn't make a type error on there. 2:25:13 And you can see we get a very nice graph. You can see a very nice elbow joint there at uh two and again right around three and four. And then after that, there's not very much. Now, as a data scientist, if I was looking at this, I would do either three or four. And I'd actually try both of them to see what the output look like. And they've already tried this in the back. So, we're just going to use three as a setup on here. And let's go ahead and see what that looks like when we actually use this to show the different kinds of cars. And so, let's go ahead and apply the K means to the cars data set. And basically, we're going to copy the code that we looped through up above where K means equals K means number of clusters. And we're just going to set the number of clusters to three since that's what we're going to look for. And you could do three and four on this and graph them just to see how they come up differently. Be kind of curious to look at that. But for this, we're just going to set it to three. Go ahead and create our own variable Y k means for our 2:26:14 answers. And we're going to set that equal to Whoops, a double equal there to K means. But we're not going to do a fit. We're going to do a fit predict is the setup you want to use. And when you're using untrained models, you'll see um a slightly different because usually you see fit and then you see just the predict, but we want to both fit and predict the K means on this. And that's fit underscore predict and then our capital X is the data we're working with. And before we plot this data, we're going to do a little pandas trick. We're going to take our X value and we're going to set X as matrix. So, we're converting this into a nice rows and columns kind of set up, but we want the we're going to have columns equals none. So, it's just going to be a matrix of data in here. And let's go ahead and run that. A little warning. You'll see this warnings pop up because things are always being updated. So, there's like minor changes in the versions and future versions. Instead of matrix now that it's more common to set it values 2:27:16 instead of doing as matrix, but mass matrix works just fine for right now. and you'll want to update that later on. But let's go ahead and dive in and plot this and see what that looks like. And before we dive into plotting this data, I always like to take a look and see what I am plotting. So let's take a look at why K means. I'm just going to print that out down here. And we see we have an array of answers. We have 2 1 0 2 1 2. So, it's clustering these different rows of data based on the three different spaces it thinks it's going to be. And then let's go ahead and print X and see what we have for X. And we'll see that X is an array. It's a matrix. So, we have our different values in the array. And what we're going to do, it's very hard to plot all the different values in the array. So, we're only going to be looking at the first two or positions zero and one. And if you were doing a full presentation in front of the board 2:28:16 meeting, you might actually do a little different than and dig a little deeper into the different aspects because this is all the different columns we looked at. But we'll look at columns one and two for this to make it easy. So let's go ahead and clear this data out of here and let's bring up our plot. And we're going to do a scatter plot here. So plt scatter. And this looks a little complicated. So, let's explain what's going on with this. We're going to take the x values and we're only interested in y of k means equals 0, the first cluster. Okay? And then we're going to take value zero for the x-axis. And then we're going to do the same thing here. We're only interested in k means equals 0, but we're going to take the second column. So, we're only looking at the first two columns in our answer or in the data. And then the guys in the back played with this a little bit to make it pretty. And they discovered that it looks good with as a size equals 100. That's the 2:29:17 size of the dots. We're going to use red for this one. And when they were looking at the data and what came out, it was definitely the Toyota on this. We're just going to go ahead and label it Toyota. Again, that's something you really have to explore in here as far as playing with those numbers and see what looks good. We'll go ahead and hit enter in there. And I'm just going to paste in the next two lines, which is the next two cars. And this is our Nissa and Honda. And you'll see with our scatter plot, we're now looking at where Y_K means equals 1. And we want the zero column and YK means equals 2. Again, we're looking at just the first two columns, zero and one. And each of these rows then corresponds to Nissan and Honda. And I'll go ahead and hit enter on there. And uh finally, let's take a look and put the centrids on there. Again, we're going to do a scatter plot. And on the centrids, you can just pull that from our K means, the uh model we createdcluster 2:30:18 centers. And we're going to just do um all of them in the first number and all of them in the second number, which is 01 because you always start with zero and one. And then they were playing with the size and everything to make it look good. We'll do a size of 300. We're going to make the color yellow. And we'll label them. It's always good to have some good labels. Centroidids. And then we do want to do a title. PLT title. And pop up there. PLT title because you always make want to make your graphs look pretty. And we'll call it clusters of carake. And one of the features of the plot library is you can add a legend. It'll automatically bring in it since we've already labeled the different aspects of the legend with Toyota, Nissan, and Honda. And finally, we want to go ahead and show so we can actually see it. And remember, it's in line. Uh so if you're using a different editor that's not the Jupyter notebook, you'll get a popup of 2:31:19 this. And you should have a nice set of clusters here. So we can look at this and we have a clusters of Honda in green, Toyota in red, Nissan in purple. And you can see where they put the centroidids to separate them. Now when we're looking at this, we can also plot a lot of other different data on here as far because we only looked at the first two columns. This is just column one and two or 01 as as you label them in computer scripting. But you can see here we have a nice clusters of car making. we were able to pull out the data and you can see how just these two columns form very distinct clusters of data. So if you were exploring new data you might take a look and say well what makes these different almost going in reverse you start looking at the data and pulling apart the columns to find out why is the first group set up the way it is. Maybe you're doing loans and you want to go, well, why is this group not defaulting on their loans and why is the last group defaulting on their loans? And why is the middle group 50% defaulting on their bank loans? And you 2:32:20 start finding ways to manipulate the data and pull out the answers you want. So now that you've seen how to use K mean for clustering, let's move on to the next topic. Now let's look into logistic regression. The logistic regression algorithm is the simplest classification algorithm used for binary or multiclassification problems. And we can see we have our little girl from Canada who's into horror books is back. That's actually really scary when you think about that with those big eyes. In the previous tutorial, we learned about linear regression, dependent and independent variables. So to brush up, y= mx + c. Very basic algebraic function of uh y and x. The dependent variable is the target class variable we are going to predict. The independent variables X1 all the way up to XN are the features or attributes we're going to use to predict the target class. We know what a linear 2:33:20 regression looks like. But using the graph, we cannot divide the outcome into categories. It's really hard to categorize 1.5, 3.6, 9.8. Uh for example, a linear regression graph can tell us that with increase in number of hours studied, the marks of a student will increase, but it will not tell us whether the student will pass or not. In such cases where we need the output as categorical value, we will use logistic regression. And for that, we're going to use the sigmoid function. So you can see here we have our marks 0 to 100, number of hours studied. That's going to be what they're comparing it to in this example. And we usually form a line that says y = mx + c. And when we use the sigmoid function, we have p = 1 / 1 + e the minus y. It generates a sigmoid curve. And so you can see right here when you take the ln, which is the natural logarithm. I always thought it should be nl, not ln. That's just the inverse of uh e your e to the minus y. 2:34:23 And so we do this, we get ln of p over 1 minus p = m * x + c. That's the sigmoid curve function we're looking for. And we can zoom in on the function and you'll see that the function as it deres goes to one or to zero depending on what your x value is. And the probability if it's greater than 0.5, the value is automatically rounded off to one indicating that the student will pass. So if they're doing a certain amount of studying, they will probably pass. Then you have a threshold value at the 0.5. It automatically puts that right in the middle usually. And your probability if it's less than 0.5, the value run it off to zero indicating the student will fail. So if they're not studying very hard, they're probably going to fail. This of course is ignoring the outliers of that one student who's just a natural genius and doesn't need any studying to memorize everything. That's not me, unfortunately. Have to study hard to learn new stuff. problem statement to classify whether a tumor is malignant or B9. And this is actually one of my 2:35:23 favorite data sets to play with because it has so many features and when you look at them you really are hard to understand. You can't just look at them and know the answer. So it gives you a chance to kind of dive into what data looks like when you aren't able to understand the specific domain of the data. But I also want you to remind you that in the domain of medicine, if I told you that my probability was really good at classified things at say 90% or 95% and I'm classifying whether you're going to have a malignant or a B9 tumor, I'm guessing that you're going to go get it tested anyways. So you got to remember the domain we're working with. So why would you want to do that if you know you're just going to go get a biopsy because you know it's that serious. This is like an all or nothing. Just referencing the domain, it's important. It might help the doctor know where to look just by understanding what kind of tumor it is. So it might help them or aid them on something they missed from before. So let's go ahead and dive into the code and I'll come 2:36:23 back to the domain part of it in just a minute. So use case and we're going to do our normal imports here where we're importing numpy, pandas, seabour, the mattplot library and we're going to do mattplot library in line since I'm going to switch over to anaconda. So, let's go ahead and flip over there and get this started. So, I've opened up a new window in my Anaconda Jupyter Notebook. And by the way, Jupyter Notebook, uh, you don't have to use Anaconda for the Jupyter Notebook. I just love the interface and all the tools that Anaconda brings. So, we got our import numpy as in P for our numpy number array. We have our pandas pd. We're going to bring in Seabor to help us with our graphs as SNS. So many really nice tools in both Seabour and Mattplot library. And we'll do our mattplot library.pipplot as plt. And then of course we want to let it know to do it in line. And let's go and just run that. So it's all set up. And we're just going to call our data data. Not creative today. Uh equals pd. And this happens to be in a CSV file. So we'll 2:37:26 use a pdread_sv. And I happen to name the file. I renamed it data forp2.csv. You can of course um write in the comments below the YouTube and request for the data set itself or go to the simply learn website and we'll be happy to supply that for you. And let's just um open up the data before we go any further. And let's just see what it looks like in a spreadsheet. So when I pop it open in a local spreadsheet and this is just a CSV file, comma separated variables, we have an ID. So I guess they um categorize this for reference or what ID which test was done. The diagnosis M for malignant, B for B9. So there's two different options on there. And that's what we're going to try to predict is the M and B and test it. And then we have like the radius mean or average the texture average, perimeter mean, area mean, smoothness. I don't know about you, but unless you're a doctor in the field, most of the stuff, I mean, you can guess what concave means just by the term concave, 2:38:27 but I really wouldn't know what that means in the measurements they're taking. So, they have all kinds of stuff like how smooth it is, uh, the symmetry, and these are all float values. You just page through them real quick, and you'll see there's, I believe, 36, if I remember correctly in this one. So there's a lot of different values they take and all these measurements they take when they go in there and they take a look at the different growth, the tumorous growth. So back in our data and I put this in the same folder as a code. So I saved this code in that folder. Obviously if you have it in a different location, you want to put the full path in there. And we'll just do uh Pandanda's first five lines of data with the data.head. We run that. We can see that we have pretty much what we just looked at. We have an ID. We have a diagnosis. If we go all the way across, you'll see all the different columns coming across displayed nicely for our data. And while we're exploring the data, our uh Seabor, which we referenced as SNS, 2:39:30 makes it very easy to go in here and do a joint plot. You'll notice the very similar to because it is sitting on top of the U plot library. So the joint plot does a lot of work for us. And we're just going to look at the first two columns that we're interested in. The radius mean and the texture mean. We'll just look at those two columns. And data equals data. So that tells it which two columns we're plotting. And that we're going to use the data that we pulled in. Let's just run that. And it generates a really nice graph on here. And there's all kinds of cool things on this graph to look at. I mean, we have the texture mean and the radius mean, obviously, the axes. You can also see and uh one of the cool things on here is you can also see the histogram. They show that for the radius mean where is the most common radius mean come up and where the most common texture is. So we're looking at the tech the on each growth it's average texture and on each radius its average uh radius on there gets a little confusing because we're talking about the individual objects 2:40:32 average. And then we can also look over here and see the the histogram showing us the median or how common each measurement is. And that's only two columns. So let's dig a little deeper into Seabor. They also have a heat map. And if you're not familiar with heat maps, a heat map just means it's in color. That's all that means. Heat map, I guess the original ones were plotting heat density on something. And so ever since then it's just called a heat map. And we're going to take our data and get our corresponding numbers to put that into the heat map. And that's simply data.co for that. That's a pandas expression. So remember, we're working in a pandanda's data frame. So that's one of the cool tools in pandas for our data. And let's just pull that information into a heat map and see what that looks like. And you'll see that we're now looking at all the different features. We have our ID. We have our texture. We have our area, our compactness, concave points. And if you look down the middle of this chart diagonal going from the upper left to 2:41:33 bottom right, it's all white. That's because when you compare texture to texture, they're identical. So they're 100% or in this case perfect one in their correspondence. And you'll see that when you look at say area or right below it, it has almost a black on there. when you compare it to texture. So these have almost no corresponding data. They don't really form a linear graph or something that you can look at and say how connected they are. They're very scattered data. This is really just a really nice graph to get a quick look at your data. Doesn't so much change what you do, but it changes verifying. So when you get an answer or something like that or you start looking at some of these individual pieces, you might go, "Hey, that doesn't match. According to showing our heat map, this should not correlate with each other. And if it is, you're going to have to start asking, well, why? What's going on? What else is coming in there? But it does show some really cool information on here. I mean, we can see from the ID, there's no real 2:42:34 one feature that just says if you go across the top line that lights up. There's no one feature that says, hey, if the area is a certain size, then it's going to be B9 or malignant. It says there's some that sort of add up and that's a big hint in the data that we're trying to ID this whether it's malignant or B9. That's a big hint to us as data scientists to go okay we can't solve this with any one feature. It's going to be something that includes all the features or many of the different features to come up with a solution for it. And while we're exploring the data let's explore one more area and let's look at data isisnull. We want to check for null values in our data. If you remember from earlier in this tutorial, we did it a little differently where we added stuff up and sum them up. You can actually with pandas do it really quickly. Data.isnull and summit. And it's going to go across all the columns. So when I run this, you're going to see all the columns come up with no null data. 2:43:36 So we've just just to rehash these last few steps. We've done a lot of exploration. We have looked at the first two columns and seen how they plot with the seaborn with a joint plot which shows both the histogram and the data plotted on the XY coordinates. And obviously you can do that more in detail with different columns and see how they plot together. And then we took and did the seabour heat map the SNS heat mapap of the data. And you can see right here where it did a nice job showing us some bright spots where stuff correlates with each other and forms a very nice combination or points of scattering points. And you can also see areas that don't. And then finally, we went ahead and checked the data. Is the data null value? Do we have any missing data in there? Very important step because it'll crash later on. If you forget to do this step, it will remind you when you get that nice error code that says null values. Okay. So, not a big deal if you 2:44:38 miss it, but it it's no fun having to go back when you're when you're in a huge process and you've missed this step and now you're 10 steps later and you got to go remember where you were pulling the data in. So, we need to go ahead and pull out our X and our Y. So, we just put that down here and we'll set the X equal to. And there's a lot of different options here. Certainly we could do X equals all the columns except for the first two because if you remember the first two is the ID and the diagnosis. So that certainly would be an option. But what we're going to do is we're actually going to focus on the worst the worst radius the worst texture parameter area smoothness compactness and so on. One of the reasons to start dividing your data up when you're looking at this information is sometimes the data will be the same data coming in. So if I have two measurements coming into my model, it might overweigh them. It might overpower the other measurements because it's measuring it's basically taking that 2:45:39 information in twice. That's a little bit past the scope of this tutorial. I want you to take away from this though is that we are dividing the data up into pieces and our team in the back went ahead and said hey let's just look at the worst. So I'm going to create a an array and you'll see this array radius worst texture worst perimeter worst. We've just taken the worst of the worst and I'm just going to put that in my X. So this X is still a pandas data frame but it's just those columns. And our Y, if you remember correctly, is going to be Oops. Hold on one second. It's not X. is data. There we go. So, x equals data and then it's a list of the different columns, the worst of the worst. And if we're going to take that, then we have to have our answer for our y for the stuff we know. And if you remember correctly, we're just going to be looking at the diagnosis. That's all we care about is what is it diagnosed? Is it B9 or malignant? And since it's a single column, we can just do diagnosis. Oh, I forgot to put the brackets. There we go. 2:46:40 Okay. So, it's just diagnosis on there. And we can also real quickly do like X.ad if you want to see what that looks like and Y.D. and run this. And you'll see um it only does the last one. I forgot about that. If you don't do print, you can see that the the Y head is just mm because the first ones are all malignant. And if I run this the X do head is just the first five values of radius worst texture worst parameter worst area worst and so on. I'll go ahead and take that out. So moving down to the next step we've built our two data sets our answer and then the features we want to look at. In data science it's very important to test your model. So we do that by splitting the data and from sklearn model selection we're going to import train test split. So we're going to split it into two groups. There are so many ways to do this. I 2:47:42 noticed in one of the more modern ways they actually split it into three groups and then you model each group and test it against the other groups. So you have all kinds and there's reasons for that which is past the scope of this and for this particular example isn't necessary for this. We're just going to split it into two groups. one to train our data and one to test our data and the sklearn uh.mmodel selection we have train tests split you could write your own quick code to do this where you just randomly divide the data up into two groups but they do it for us nicely and we actually can almost we can actually do it in one statement with this where we're going to generate four variables capital X train capital X test so we have our training data we're going to use to fit the model and then we need something to test it. And then we have our Y train. So we're going to train the answer. And then we have our test. So this is the stuff we want to see how good it did on our model. And we'll go ahead and take our train test split that we just imported. And we're going to do X and our Y, our 2:48:44 two different data that's going in for our split. And then the guys in the back came up and wanted us to go ahead and use a test size equals.3. That's test size. Random state. It's always nice to kind of switch a random state around, but not that important. What this means is that the test size is we're going to take 30% of the data and we're going to put that into our test variables, our Y test and our X test. And we're going to do 70% into the X train and the Y train. So, we're going to use 70% of the data to train our model and 30% to test it. Let's go ahead and run that and load those up. So, now we have all our stuff split up and all our data ready to go. And now we get to the actual logistics part. We're actually going to do our create our model. So let's go ahead and bring that in from sklearn. We're going to bring in our linear model and we're going to import logistic regression. That's the actual model we're using. And let's we'll call it log model. Oops, there we go. Model. And let's just 2:49:44 set this equal to our logistic regression that we just imported. So now we have a variable log model set to that class for us to use. And with most the uh models in the sklearn, we just need to go ahead and fix it. Fit do a fit on there. And we use our X train that we separated out with our Y train. And let's go ahead and run this. So once we've run this, we'll have a model that fits this data, that 70% of our training data. Uh and of course, it prints this out that tells us all the different variables that you can set on there. There's a lot of different choices you can make, but for Word do, we're just going to let all the defaults set. We don't really need to mess with those on this particular example, and there's nothing in here that really stands out as super important until you start fine-tuning it. But for what we're doing, the basics will work just fine. And then let's we need to go ahead and test out our model. Is it working? So, let's create a variable y predict. And this is going to be equal to our log 2:50:47 model. And we want to do a predict. Again, very standard format for the sklearn library is taking your model and doing a predict on it. And we're going to test y predict against the y test. So we want to know what the model thinks it's going to be. That's what our y predict is. And with that, we want the capital xx test. So we have our train set and our test set. And now we're going to do our y predict. And let's go ahead and run that. And if we uh print y predict, let me go ahead and run that. You'll see it comes up and it predents a prints a nice array of uh B and M for B9 and malignant for all the different test data we put in there. So it does pretty good. We're not sure exactly how good it does, but we can see that it actually works and is functional. Was very easy to create. You'll always discover with our data science that as you explore this, you spend a significant amount of time 2:51:48 prepping your data and making sure your data coming in is good. Uh there's a saying, good data in, good answers out, bad data in, bad answers out. That's only half the thing. That's only half of it. Selecting your models becomes the next part as far as how good your models are. And then of course fine-tuning it depending on what model you're using. So we come in here, we want to know how good this came out. So we have our y predict here, log model.predict x test. So for deciding how good our model is, we're going to go from the sklearn.metrics, we're going to import classification report. And that just reports how good our model is doing. And then we're going to feed it the uh model data. Let's just print this out. and we'll take our uh classification report and we're going to put into there our test our actual data. So this is what we actually know is true and our 2:52:50 prediction what our model predicted for that data on the test side. And let's run that and see what that does. So we pull that up. You'll see that we have um a precision for B9 and malignant B and M. And we have a precision of 93 at 91, a total of 92. So it's kind of the average between these two of 92. There's all kinds of different information on here. Your F1 score, your recall, your support coming through on this. And for this, I'll go ahead and just flip back to our slides that they put together for describing it. And so here, we're going to look at the precision using the classification report. And you see this is the same printout I had up above. Some of the numbers might be different because it does randomly pick out which data we're using. So this model is able to predict the type of tumor with 91% accuracy. So we look back here that's you'll see where we have uh B9 and Miglin. It actually has 92 coming up here. We're 2:53:50 looking about a 92 91% precision. And remember I reminded you about domain. So, when we're talking about the domain of a medical domain with a very catastrophic outcome, you know, at 91 or 92% precision, you're still going to go in there and have somebody do a biopsy on it. Very different than if you're investing money and there's a 92% chance you're going to earn 10% and 8% chance you're going to lose 8%, you're probably going to bet the money because at that odds, it's pretty good that you'll make some money. And in the long run, you do that enough, you'll definitely will make money. And also with this domain, I've actually seen them use this to identify different forms of cancer. That's one of the things that they're starting to use these models for because then it helps a doctor know what to investigate. So that wraps up this section. We're finally we're going to go in there and let's discuss the answers to the quiz asked in machine learning tutorial part one. Can you tell what's happening in the following cases? Grouping documents into different categories based on the topic 2:54:50 and content of each document. This is an example of clustering where K means clustering can be used to group the documents by topics using bag of words approach. So if you gotten in there that you're looking for clustering and hopefully you had at least one or two examples like K means that are used for clustering different things then give yourself a two thumbs up. B identifying handwritten digits in images correctly. This is an example of classification. The traditional approach to solving this would be to extract digit dependent features like curvature of different digits etc. and then use a classifier like SVM to distinguish between images. Again, if you got the fact that it's a classification example, give yourself a thumb up. And if you're able to go, hey, let's use SVM or another model for this, give yourself those two thumbs up on it. C. Behavior of a website indicating that the site is not working as designed. This is an example of anomaly detection. In this case, the algorithm learns what is normal and what is not normal, 2:55:52 usually by observing the logs or the website. Give yourself a thumbs up if you got that one. And just for a bonus, can you think of another example of anomaly detection? One of the ones I use it for in my own business is detecting anomalies in stock markets. Stock markets are very fickled and they behave very erratic. So finding those erratic areas and then finding ways to track down why they're erratic. Was something released in social media? Was something released you can see where knowing where that anomaly is can help you to figure out what the answer is to it in another area. D. Predicting salary of an individual based on his or her years of experience. This is an example of regression. This problem can be mathematically defined as a function between independent years of experience and dependent variables salary of an individual. And if you guess that this was a regression model, give yourself a thumbs up. And if you're able to remember that it was between independent and dependent variables and that terms, give yourself two thumbs up. The principal component uh analysis, we're 2:56:54 going to cover dimensionality reduction. Principal component analysis, what is it? important PCA terminologies, and you'll see it abbreviated uh normally as PCA, principal component analysis, PCA properties, PCA example, and then we'll pull up some Python code in our Jupyter notebook and have some hands-on demo on the PCA and how it's used. Dimensionality reduction. Dimensionality reduction refers to the technique that reduces the number of input variables in a data set. And so you can see on the table on the right shows the orders made at an automobile parts retailer. The retailer sells different automobile parts from different companies. And you can see we have company uh BPEX isomax and they have the item, the tire, the axle, an order ID, a price number and a quantity. In order to predict the future sales, we find out that using correlation analysis that we just need three attributes. Therefore, we have reduced the number of 2:57:56 attributes from five to three. And clearly, we don't really care about the part number. I don't think the part number would have an effect on how many tires are bought. Um, and even the store, who's buying them, probably does not have an effect on that. In this case, that's what they've actually done is remove those. And we just have the item, the tire, the price, and the quantity. One of the things you should be taking away from this is in the scheme of things, we are in the descriptive phase. We're describing the data and we're pre-processing the data. What can we do to clean it up? Why dimensionality reduction? Well, number one, less dimensions for a given data set means less computation or training time. That can be really important if you're trying a number of different models uh and you're rerunning them over and over again. And even if you have seven gigabytes of data, that can start taking days to go through all those different models. So, this is huge. This is probably the hugest part as far as reducing um our data set. Redundancy is 2:58:58 removed after removing similar entries from the data set. Again, pre-processing some of our models like a neural network. If you put in two of the same data, it might give them a higher weight than they would if it was just one. So, we want to get rid of that redundancy. It also increases the processing time if you have multiple uh data coming in. space required to store the data is reduced. So if we're committing this into a big data uh pool, we might not send the company that bought it. Why would we want to store two whole extra columns when we add it into that pool of data? Makes the data easy for plotting in 2D and 3D plots. This is my favorite part. Very important. You're in your shareholder meeting. You want to be able to give them a really good um clear and simplified version. You want to reduce it down to something people can take in. It helps to find out the most significant features and skip the rest which also comes in in postcribing. Uh 2:59:59 leads to better human interpretation. That kind of goes with number four where it makes data easy for plotting. You have a better interpretation when we're looking at it. Principal component analysis. So what is it? Uh principal component analysis is a technique for reducing the dimensionality of data sets increasing interpretability but at the same time minimizing information loss. So we take some very complex data set with lots of variables. We run it through the PCA. We reduce the variables. We end up with a reduced variable setup. This is very confusing to look at because if you look at the end result, we have the different colors all lined up. So what we're going to take a look at is let's say we have a picture here. Uh let's say you are asked to take a picture of some toddlers and you are deciding which angle would be the best to take the picture from. So if we come up here we look at this we say okay this is you know one angle. Uh we get the back of a lot of heads not many faces. Uh so we'll do it from here. We might get the one person up front 3:01:00 smiling. A lot of the people in the class are missing. So we have um a huge amount off to the right of blank space. maybe from up here. Again, we have the back of someone's head. And uh it turns out that the best angle to click the picture from might be this bottom left angle. You look at it and you say, "Hey, that makes sense. It's a a good um configuration of all the people in the picture." Now, when we're talking about data, it's not you really can't do it by what you think is going to be the best. We need to have some kind of mathematical formula so it's consistent and so it makes sense in the back end. One of the projects I worked on many years ago uh has something similar to the iris. And if you've ever done the iris data set, it's probably one of the most common ones out there where they have the flower and they're measuring the stomach uh in the petals and they have width and they have length of the petal. Instead of putting through the width and the length of the petal, we could just as easily do the um width to length 3:02:01 ratio. We can divide the width by the length and you get a single number where you had two. That's the kind of idea that's going on into this in pre-processing and looking at what we can do to bring the data down. The very simplified example on my uh Iris pedal example when we look at the similarity in PCA we find the best picture or projection of the data points. And so we look down at from one angle we've drawn a line down there. uh we can see these data points based on in this case just two variables. Now keep in mind we're usually talking about 36 40 variables. Um almost all of your business models usually have about 26 to 27 different variables they're looking at. Uh same thing with like a bank loan model. We're talking 26 to 36 different variables they're looking at that are going in. So we want to do is we want to find the best view. In this case, we're just looking at the XY. We look down at it and we have our second um idea PC2. And again, we're 3:03:04 looking at the XI. This XY this time from a different direction. Here for our ease, we can consider that we get two principal components, namely PC1 and PC2. Comparing both the principal components, we find the data points are sufficiently spaced in PC1. So if you look at what we got here, we have uh PC1. You can see along the line how the data points are spaced versus the spacing in PC2. And that's what they're coming up with. What is going to give us the best look for these data points when we combine them and we're looking at them from just a single angle. Whereas in PC2, they are less spaced, which makes the observation and further calculations much more difficult. Therefore, we accept the PC1 and not the PC2 as the data points are more spaced. Now obviously the backend calculations are a little bit more complicated when we get into the math of how they decide what is more valuable. This gives you an idea though that when we're talking about this we're talking 3:04:05 about the perspective uh which would help in understanding how PCA analysis works. we want to go ahead and do is dive into the important terminologies under PCA. And important terminologies are views, the perspective through which data points are observed. And so you'll hear that if someone's talking about a PCA presentation and they're not taking the time to reduce it to something that the average person shareholders can understand, you might hear them refer to it as the different views. What view are we taking? Dimension. Number of columns in a data set are called the dimensions of that data set. We talked about you'll hear features, dimensions. Um, I was talking about features. There's usually when you're running a business, you're talking 25, 26, 27 different features, minimal. And then you have the principal component. New variables that are constructed as linear combinations or mixtures of the initial variables. Principal component is very important. It's a combination. If you remember my 3:05:05 flower example, it would be the width over the length of the petal. As opposed to putting both width and length in, you just put in the ratio instead, which is a single number versus two separate numbers. Projections, the perpendicular distance between the principal component and the data points. And that goes to that line we had earlier. It's that right angle line of where those point all those points fall onto the line. Important properties. important properties. Number of principal components is always less than or equal to the number of attributes. That just makes common sense. Uh you're not going to do 10 principal properties with only three features. You're trying to reduce them. So that's just kind of goofy, but it is important to remember that people will throw weird code out there and just randomly do stuff instead of really thinking it through. Principal components are orthogonal. And this is what we're talking about. that right angle from the line we when we do PC1 we're looking at how those 3:06:07 points fall on to that line. Uh same thing with PC2 and we want to make sure that PC1 does not equal PC2. We don't want to have the same two principal points uh when we do two points. The priority of principal components decreases as their numbers increase. This is important to understand. If you're going to create uh one principal component, everything is summarized into that one component. As we go to two components, the priority um how much it holds value decreases as we go down. So if you have five different points, each one of those points is going to have less value than just the one point which has everything summarized in it. how PCA works. I said there was more in the back end when we talk about the math. This is what we're talking about is how does it actually work. So now we have understanding that you you're looking at 3:07:08 a perspective. Uh now we want to see how that math side works. PCA performs the following operations in order to evaluate the principal components for a given data set. First we start with the standardization. Then we have a co-variance matrix computation and we use that to generate our gene vectors and I gene values which is the feature vector and if you remember the gene vector is like a translation if we're um moving the data from x= 1 to x= 2 or whatever altering it and the iene value is the final value that we generate. When we talk about standardization, the main aim of this step is to standardize the range of the attributes so that each one of them lie within similar boundaries. This process involves removal of the mean from the variable values and scaling the data with respect to the standard deviation. 3:08:08 And you can see here we have Z equals the variable values minus the mean over the standard deviation. The co-variance matrix computation. Covariance matrix is used to express the correlation between any two or more attributes in multi-dimensional data set. The coariance matrix has the entries as the variance and the covariance of the attribute values. The variance is denoted by var and the coariance is denoted by cove. On the right, we can see the covariance matrix for two attributes and their values. When we do a hands-on look at the code, we'll do a display of this so you can see what we're talking about and what that looks like. For now, you can just notice that this is a matrix that we're generating with the variance and then the coariance of X to Y. On the right side, we can see the coariance table for more than two attributes in a multi-dimensional data set. This is what I was talking about. We usually are looking at uh not just one feature or two features. We're usually 3:09:10 looking at 25 30 features going on. And so if we do a setup like this, we should see all those different features as the different variables. Covariance matrix tells us how the two or more variables are related. Positive covariance indicate that the value of one variable is directly proportional to the other variable. Negative coariance indicate that the value of one variable is inversely proportional to the other variable. That is always important to note when whenever we're doing any of these matrixes that we're going to be looking at that positive and negative whether it's inverted or not. And then we have the gene values and the gene vectors. I gene values and hygiene vectors are the mathematical value that are extracted from the covariance table. They are responsible for the generation of a new set of variables from the old set of variables which further lead to the construction of the principal components. I gene vectors do not change directions after linear transformation. I gene values are the scalers or the 3:10:12 magnitude of the hygiene vectors. And again this is just change transforming that data. So we're going to change uh the vector B to the B prime as denoted on the chart. And so when we have like multiple variables, how do we calculate that new variable? And then we have feature vectors. Feature vectors is simply a matrix that has igene vectors of the components that we decide to keep as the columns. Here we decide whether we must keep or discard the less significant principal components that we have generated in the above steps. This becomes really important as we start looking at u the back end of this and we'll do this in the demo uh but one of the more important steps to understand. And so we have the PCA example. Consider matrix X with n rows or observations and K columns or variables. Now for this matrix, we would construct a variable space with as many dimensions as the variable. 3:11:13 But for our simplicity, let's consider this three dimensions for now. Now each observation row of the matrix X is placed in the K- dimensional variable space such that the rows in the data table form a swarm of points in this space. Now we find the mean of all the observations and then place it along the data points on the plot. The first principal component is a line that best accounts for the shape of the point swarm. It represents the maximum variance direction in the data. Each observation may be projected onto this line in order to get a coordinate value along the PC1. This value is known as a score. Usually only one principal component is insufficient to model the systematic variation for a data set. Thus, a second principal axis is created. The second principal component is oriented such that it reflects the second largest source of variation in the data. While being orthogonal to PC1, 3:12:16 PC2 also passes through the average point. Let's go ahead and pull this up and just see what that means. Uh, inside our Python scripting, I'm going to use the Anaconda Navigator. And I will be in Python 3.6 for this example. I believe there's even like a 3.9 out. I tend to stay in 3.6 because a lot of the models I use, especially with the neural networks, are stable in 36. And then we open up our uh Jupiter. I'm in Chrome. And we go ahead and create a new Python 3. And for ease of use, uh, our team in the back was nice enough to put this together for me. And we'll go ahead and start with the libraries. The first thing I like to do whenever I'm looking at any new setup, uh, well, you know what? Let's do let's do the libraries first. We're going to do our basic libraries which is mapplot library uh 3:13:17 the plt from the mapplot library pandas our data frame uh pd numpy our numbers array np seabor for graphing sns that goes with the plot that actually sits on mplot library so the seabour sits on there and then we have our amber sign because we're in Jupyter notebook mattplot library in line the newer version actually doesn't require that u but I put it in there either anyway just because I'm so used to it. And then we want to go ahead and take a look at the data. And in this case, we're going to pull in uh certainly you can have lots of fun with different data, but we're going to use the cancer data set. Uh and one of the reasons the cancer data set is is it has like 36 35 different features. So it's kind of fun to use that as our base for this. And we'll go ahead and run this and look at our keys. And the first thing we notice in our keys for the cancer data set uh is we have our data, we have our target, our frame, target 3:14:18 names, description, feature names, and file name. So what we're looking for in all this is um well, let's take a look at the description. Let's go in here and pull up the description on here. I'm not going to spend a huge amount of time on the description um because this is we don't want to get into a medical domain. We want to focus on our PCA setup. Uh what's important is you start looking at what the different attributes are, what they mean. Um if you were in the medical field, you'd want to note all these different things, whether what they're measuring or where it's coming from. You can actually see the actual different um measurements they're taking. no missing attributes. We page all the way to the bottom. And you're going to have your data, in this case, our target. And if you dig deep enough to the target, uh let's actually do this. Let's go ahead and print target names 3:15:22 real quick here. I always like to to just take a look and see what's on the other end of this uh target. names. Run that. And so the target name is is it malignant or is it B9? Um so in other words, is this uh dangerous growth or is it something we don't have to worry about? That's the bottom line with the cancer in this case. And then we can go ahead and load our data. And uh you know, let me go up a just a notch here for easy of reading. It's hard to get that just right. That's all you have to do. Uh so let's go ahead and look at our data. Uh our our we're going to use our pandas and we're going to go ahead and do our data frame. It's going to equal cancer data columns equals cancer feature equals feature names. So remember up here we already loaded the the names up of our of the features in there. What is going to come out of this? Let me just see if I can get to that. 3:16:28 It's at the top of target names. Um, that's just this list of names here in the setup. And we can go ahead and run this code and it'll print the head. And you can see here we have the mean radius, the mean texture, mean perimeter. I don't know about you, this is a wonderful data set if you're playing with it because like many of the data that most of the data that comes in, half the time we don't even know what we're looking at. uh we're just handed a bunch of stuff as a data scientist going what the heck is this and so this is a good place to start because this has a number of different features in there and we have no idea what these feature means or where they come from we want to just look at the data and figure that out and now we actually are getting into the PCA side of it as we've noticed before it is difficult to visualize highdimensional data we can use PCA to find the first two principal components and visualize the data data this new two-dimensional space with a single scatter plot. Uh before we do this, we 3:17:28 need to go ahead and scale our data. Now, I haven't run this to see if you really have to scale the data on this. Um but as just a general runtime, I almost do that as the first step of any modeling, even if it's premodeling as we're doing here. Um in neural networks, that is so important with PCA visualization. it's already going to scale it when we do the means and deviation inside the PCA. Uh but just in case it's always good to scale it and then we're going to take our uh PCA with the scikitlearn uses very similar process to other pre-processing functions that come with scikitlearn. We instantiate a PCA object find the principal components using the fit method then apply the rotation and dimensionality reduction by calling transform. We can also specify how many components we want to keep when creating the PCA object. 3:18:29 And so the code for this, oops, getting a little bit ahead. Let me go and run this code. Uh, so the code for this is from sklearn decomposition import PCA. PCA equals PCAN in components equals two. And that's really important to note that uh because we're only going to want to look at two components. I would never go over four components, especially if you're going to demo this with somebody else. If you're showing this to the shareholders, the whole idea is to reduce it to something people can see. Uh and then the PCA fit, we're going to uh is going to take the scaled data that we generated up here. And then you can see we've created our PCA model with in components equals 2. Now whenever I use a new tool, I like to go in there and actually see what I'm using. So let's go to the scikite uh web page for the PCA. 3:19:31 And you can see in here, here's our call statement. It describes what all the different uh setups you have on there. Probably the biggest one to look at would be um well the biggest one is your components. How many components do you want uh which you have to put in there pretty much and then you also might look at the SVD solver. It's on auto right now but you can override that and do different things with it. It does a pretty good job as it is. And if we go down all the way down to um here we go to our methods. If you notice we have fit we have fit transform. Nowhere in here is predict because this is not used for prediction. Uh it's used to look at the data. Again we're in the describe setup. We're fitting the data. We're taking a look at it. Uh we've already looked at our minimum maximum. We've already looked at what's in each 3:20:33 quarter. We've done a full description of the data. This is part of describing the data. Um that's the biggest thing I take away when I come zooming in here. And of course they have examples of it down here if you forget. Um and the biggest one of course is the number of components. And then uh I mean the rest you can play with. um the actual solver, whether you're doing a full or randomize, there's different things, it does pretty good on the auto. And now we can transform this data to its first two principal components. And so we have our XPCA. We're going to set that equal to PCA transform scaled data. Uh so there we go. There's our first transformation. And let's just go ahead and print the scaled data shape and the XPCA data shape. And the reason we want to do this is just to show us u what's going on here. 3:21:33 We've taken 30 features. I think I said 36 or something like that, but it's 30. And we've compressed it down to two features. And we decided we wanted two features. And that's where this comes from. Uh we still have 569 data sets. I mean data rows, not data sets. We still have 569 rows of data, but instead of computing 30 features, we're now only doing our model on two features. So let's go ahead and uh uh plot these and take a look and see what's going on. And uh we're just going to use our PLT figure. We'll set the figure size on here. Here's our scatter plot. Um, XPCA X_PCA of U of one. These are two different perceptions we're using. Uh, and then you'll see right here C for color. Cancer equals target. And so remember, 3:22:35 we have zero, we have one. And if I remember correctly, zero was malignant, one was B9. Uh, so everything in the zero column is going to be one color and the other color is going to be one. And then we're going to use the plasma map just kind of telling it what color it is. Add some labels. First principal component, second principal component. We'll go ahead and run this. And you can see here, instead of having a chart, one of those heat maps with 30 different columns in it, we can look at this and say, "Hey, this one actually did a pretty good job of separating the data." And a couple things when I'm looking at this that I notice is first we have a very clear area where it's clumped together um where it's going to be benign and we have a huge area it's still clumped together more spread out where it's going to be uh malignant or I think I had that backwards and then in the middle because we're dealing with something in this particular case cancer 3:23:39 we would try to separate I would be exploring how to separate this middle group out. In other words, there's an area where everything overlaps and we're not going to have a clear result on it. Uh just because those are the people you want to go in there and have extra tests or treat it differently versus going in and saying just cutting into the can into the cancer so the body absorbs it and it dissipates versus uh actively going in there removing it, testing it, going through chemo and all the different things. That's a big difference, you know, as far as what's going to happen here in that middle line where they overlap is going to be huge. That's domain specific. Uh going back to the data, we can see here uh clearly by using these two components, we can easily separate these two classes. So the next step is what does that mean? Interpreting the components. Unfortunately, with this great power of dimensionality reduction comes the cost of not being able to easily understand what these components represent. I don't 3:24:41 know what principal component one looks work represents or second principle. The components correspond to combinations of original features. The components themselves are stored as an attribute of the filtered PCA object. And so we talk look at that. We can go ahead and do uh look at the PCA components. This is in our model we built. We've trained it. We can run that. And you can see here's the actual components. Uh it's the two components have each have their own array. And within the array, you can see the u what the scores are using. And these actually give weight to what features are doing what. So in this numpy matrix array, each row represents a principal component and each column relates back to the original features. What's really neat about this is we can now go in reverse and drop this onto a heat map and start seeing uh what this means. And so, let me go ahead and just put this down. 3:25:41 Oops, I already got it down here. Uh, we go ahead and put this in here. We're going to use our um DF comp data frame and we do our PCA components. And I want you to notice how easy this is. Uh we're going to set our columns equal to cancer feature names. That just makes it really easy. And we're dumping it into a dataf frame. What's neat about a data frame is when we get to Seabor, it will pull that data frame apart and u and set it up for us where we want. And so we're just going to do the C the Seabor heat map of our dataf frame uh composition. And we'll use the plasma coloring. And it creates a nice little color graph. Here you can see we have the mean radius and all the different features along the bottom. On the right, uh we have a scale. So we can see we have the dark colors all the way to the really light colors which are what's really shining there. This is like the primary stuff we want to look at. 3:26:43 So this heat map and the color bar basically represent the correlation between the various features and the principal component itself. So, you know, very powerful map to look at. And then you can go in here and we might notice that the mean radius, look how how on the bottom of the map it is um on some of this. Uh so you have some interesting correlations here that change the variations on that and what means what. This is more when you get to uh postcribe, you can also use this to try to guess as what these things mean and what you want to change to get a better result. regularization in machine learning. So our agenda on this one is fitting the data, understanding linear regression, bias and variance, what is overfitting, what is underfitting, and those are like the biggest things right now in data science is overfitting and underfitting. What does that mean? And what is 3:27:44 regularization? And then we'll do a quick hands-on demo to take a look at this. So fitting the data. Let's start with fitting the data. And we talk about uh what is data fitting. It's a process of plotting a series of data points and drawing the best fit line to understand the relationship between the variables. And this is what we called data fitting. And you can see here we have a couple of lines we've drawn on this graph. We're going to go in a little deeper on there. Uh so we might have in this case just a two dimensions. We have an efficiency of the car and we have the distance traveled in 1,000 km. And so what is data fitting? Well, it's a linear relationship. And a linear relationship very specifically linear means line. Uh the line used to represent the relationship is a straight line that passes through the data points and the variables have linear relationship. Linear regression. So let's start with uh how linear regression works. So linear regression 3:28:44 uh finds the line that best fits the data point and gives a relationship between the two variables. And so you can see here we have the efficiency of the car um versus the distance traveled. And you can see this nice straight line drawn through there. And when you talk about multiple variables, all you're doing is putting this instead of a line, it now becomes a plane. It gets a little more complicated with multiple variables, but they all come down to this linear kind of uh drawing a line through your data and finding what fits the the data the best. And so we can consider an example. Uh let's say that we want to find the relationship between the temperature outside versus the sales of ice cream. And so we start looking at that. We're looking at the how many ice cream cones we're selling or how much money we sold in ice cream. and we're looking at how uh warm it is outside, which would hopefully draw a lot of people into the ice cream store. And suppose we have two lines. We're going to draw L1 and L2. And we're going to kind of guess which one we think is the best fit and which 3:29:45 claim to describe the relationship between the variables. And so, first we find the square of the distance between the line L1 and each data point and add them all and find the mean distance. And I want you to think about that when we um uh square something, if it's a negative or positive number, it no longer matters because a minus two squared is four. 2^2 is four. So we're removing what side of the line it's on and we're just looking for the error. In this case, the mean distance of each of the little dotted lines you see here. This way of calculating the square of the distance, adding them and then taking the mean is called mean square error or loss function. And we talk about loss. How far off are we? That's what we're really talking about. What did we miss? Uh and we have a positive distance and a negative distance. And of course when we square it, it is neither it just becomes a positive error. And so we take the mean square error. 3:30:46 And a lot of times you'll see it referred to as MSE. Uh, if I look in a code and I'm going through my Python code and I see MSE, I know that's a mean squared error. And we take all the dotted lines and we calculated this error and we add them all together and then we average it or find the means. And in this case, they ran a demo on this and it was uh 1,127.27 for our L1 line. Now we find the loss function for line L2 in a similar fashion and we get the mean square error to be 6,397 and it's computed the same way. So maybe you put this line just way outside the data range and this is the error you get. By analyzing our results we find that the loss function or the mean square error is less for L1 than L2. Hence L1 is the best fit line. Uh this process describes a lot of machine learning processes. 3:31:48 We're going to keep guessing and get as close as we can to find the right answer. We have to have some way to invi to u calculate this and figure out which one's the best and the mean square error is one of the better fits to doing for doing this and most commonly used. We really want to talk about bias and variance. very important terms to know in machine learning and with linear regression. So bias bias occurs when an algorithm has limited flexibility to learn from data. Variance defines the algorithm's sensitivity to specific sets of data. Let's start with bias and variance. You can see here we have um the two different setups. Uh bias you can think is very generalized where variance is very specific. Uh and so we talk about bias such models pay very little attention to the training data and oversimplify the model. Therefore the 3:32:50 validation error or prediction error and training error follow similar trends. And uh with bias, if you oversimplify it so much, you're going to miss your um local uh if if you have like a really good fit, you're going to miss it. You're you're going to just kind of guess what the average is, and that's what your answer is going to be. With variance, a model with a high variance pays a lot of attention to training data and does not generalize. Therefore, the validation error or prediction error are far apart from each other. Such models always lead to a high error on training and test data as a bias does. Where variance, such models usually perform very well on training data but have high error rates on test data. And I want you to think about this. Um when we're talking about a bias, uh the error is going to be high both when you're training it and you're testing it. Why? Because we're just kind of getting an average. We're not really 3:33:50 fitting it close. With variance, we're fitting it so close that the test data does really good. It's going to nail it every time. Uh if you're doing categorical testing, that's a car, that's a truck, that's a bicycle. Um but with variance, suddenly a truck has to have certain features and it might have to be red uh because you had so many red pictures. So if it has if it's an 18-wheeler, it has to be red. If it's uh blue, then it has to be a bicycle. That's the kind of variance we're talking about where it picks up on something and it it cannot get the right answer unless it gets a very specific data. And we see that so that as you're testing it your models and you programmed it, you got to look for how I trained it, what is coming out. And if it's not if it's not looking good on either bias or if it's not looking good on the training or on the test data, then you're bias uh then you're biasing your data. If it really looks good on 3:34:51 the training data, then that's going to be your variance. You've overfitted the data. And those are very important things to know when you are building your models uh in regression of any kind or any kind of uh setup for predicting. So in dart games, if all the data fall on a particular pointer, this can be considered as a biased throw and the player aims for the particular score. for variance. If all the darts fall on different pointers and no two darts fall on the same pointer, then this can be considered as a varied throw and the player aims for various scores. Uh again, the bias sums everything up in one point, kind of averages it together where the variance really looks for the individual uh predictions coming out. So let's go ahead and talk about overfitting. Uh when we talk about overfitting, it's a scenario where the machine learning model tries to learn from the details along with the noise and the data tries to fit each data point on the curve. Uh you can see that 3:35:54 um if you plug in your coordinates, you're just going to get the whatever is fitted every point on the data stream. There's no average. there's no two points that might have the you know why might have two different answers cuz uh if the wind blows a certain way um and your efficiency of your car maybe you have a headwind so your car might alter how efficient it is as it goes and so there's going to be this variance on here and this says no you can't have any variance what's you know that this is it's going to be exactly this it can't be any you can't be the same speed or the same car and have a slightly different efficiency so as a model has very less flexibility. It fails to predict new data points and thus the model rejects every new data point during the prediction. Uh so you'll get like a really high error on here. And so uh reasons for overfitting uh data used for training is not cleaned and contains noise garbage values in it. You can spend so much time cleaning your 3:36:55 data and it's so important. It's so important that if you have if you have some kind of something wrong with the data coming in, it needs to be addressed whether it's a source of the data maybe they use in medical different measuring tools. Uh so you now have to adjust for data that came in from hospital A versus hospital B or even off of machine A and machine B is testing something and those those numbers are coming in wrong. The model has a high variance. Uh again, wind is a good example. I was talking about that with the car, you may have a 100 tests, but because the wind's blowing, it's all over the place. Uh size of training data used is not enough. So a small amount of data is going to also cause this problem. You only have a few points and you try to plot everything. The model is too complex. Uh this comes up a lot. we put too many pieces together and how they interact can't even be tracked um and and so you have to go back break it up 3:37:57 and find out actually what correlates and what doesn't. So what is underfitting? A scenario where machine learning models can neither learn the relationship between the data points nor predict or classify a new data point. And you can see here we have uh our efficiency of our car and our line drawn and it's just going to be way off for both the training and the predicting data. As the model doesn't fully learn the patterns, it accepts every new data point during the prediction. So instead of looking for a general pattern, uh we just kind of accept everything. Data used for training is not cleaned and contains noise, garbage and values. Again, underfitting and overfitting, same issue. You got to clean your data. The model has a high bias. Uh we've seen this in all kinds of things from uh the mo the most common is the driving 3:38:57 cars to facial identification or whatever it is. The model itself when they build it might have a bias towards one thing and this would be an underfitted model would have that bias because it's averaged it out. So if you have um five people from India and 10 people from um Africa and 20 people from the US, you've created a bias uh because it's looking at the 20 people and you only have a small amount of data to work with. Size of training data used is not enough. Uh that goes with the size I was just talking about. So we have a model with a high bias. We have size of training data used is not enough. the model is too simple. Again, that's a one straight line through all the data when it needs has a slight shift to it for other reasons. So, what is a good fit? Uh, a linear curve that best fits the data is neither overfitting or underfitting models, but is just right. And of course, we have 3:39:58 the nice examples here where we have overfitting, lines going up and down, every point's trying to be included, included, underfitting. um the line really is off from where the data is and then a good fit is got to get rid of that minimize that um error coming through. Regularization is taking the guesswork out. You're looking at this graph and you're going oh which one is that really overfit or is that under fit? That was pretty hard to tell. So we talk about regularization. Regularization techniques are used to calibrate the linear regression models and to minimize the adjusted loss function and prevent overfitting or underfitting. So what that means uh in this case we're going to go ahead and take a look at a couple different things. We're going to look at regularization which we'll start with a linear model. We'll look at the ridge regularization and the lasso regularization. And these models are just like uh just like we did the um MLP the multi-layered 3:40:58 positron in the sklearn module. You could bring in the ridge module and you can bring in the lassel module. So when we talk about um ridge regression, it modifies the overfitted or underfitted models by adding the penalty equivalent to the sum of the squares or the magnitude of the coefficients. And so we have a cost function equals loss equals uh lambda times the sum of w uh squared or the absolute value of w depending on how you're doing it. Now remember we talked about error where we either square it or we absolute value it uh because that removes a plus or minus sign on there. And there's reasons to do it either way but is more common to square the value. And then we have our uh um in this case the lambda is going to be the penalty for the errors. We've thrown in a Greek character for you just to confuse everybody. And W is the slope of the curve of the line. So, uh, we're going to look at this and we're going to draw a line. This is 3:41:59 going to be like a linear regression model. So, if you had in skarn, you could import just a standard linear regression model. Uh, it would plot this line across whatever data we're working on. And we look at this. And of course, we're just extrapolating this. Um I know they use some specific data but we don't want to get into the actual domain. And so for a linear regression line let's consider two points that are on the line. And we'll go ahead and have a loss equals zero. Uh considering the two points on the line we'll go ahead and do lambda equals 1. We'll set our w is going to be 1.4. Then the cost function equals 0 + 1 * 1.4^2 which equals 1.96. Uh so really don't get caught up too much in the math on this other than understanding u that this is something that's very easy for a computer to calculate and if you ever see the loss plus the l plus the lambda time w the sum is w ^2 3:43:01 and then let's say we have a ridge uh regression line and it does this we go ahead and plot it and we do the calculations on the data and for the ridge regression let's assume a loss equals 3^2 +2 equ=.13. So when they put all the calculations through of the two points we end up with a 0 62. Uh so we now had a linear regression model. We now had a ridge regression model. And the ridge regression model plots a little differently than the standard linear regression model. And comparing the two models with all the data points, we can see that the ridge regression line fits the model more accurately than the linear regression line. And I find this true on a lot of data I work with. I'll end up using either the ridge regression model or the lasso uh Mars regression model for fitting. Um especially dealing with a lot of like uh stock markets daily um setup, they come out slightly better. Uh you get a slightly better um fit. 3:44:03 And so we have our lasso. We just talked about lasso coming in here. And the cost function equals uh um instead of doing a squared, we're just going to do the absolute value. And so if you remember, this is where ridge regression changes. Where's my ridge regression model? Uh we're squaring the value here. And if you look at this, we're not squaring the value. We're just finding the absolute value on here. And so the loss of the of the squared individuals um and here is our lambda symbol again penalty for errors and w equals the slope of the curve. And comparing the two models with all the data points we can see that the lasso regression line fits the model more accurately than the linear regression line. And this is like I said I I use these two models a lot. uh the ridge and this is important. This is this is kind of the meat of the matter. How do you know which one to use? Some of it is you just do it a bunch of times and then you 3:45:04 figure it out. Uh ridge regularization is useful when we have many variables with relatively smaller data samples. The model does not encourage convergence towards zero but is likely to make them closer to zero and prevent overfitting. The lasser regularization model is preferred when we are fitting a linear model with fewer variables. So in the la in the Iris thing we had four or five variables as we measure the different leaf pieces. Uh you might be doing the measurements on the cancer project which has 36 different variables. Um so as we get down to the iris with four variables, lassolar will probably uh work pretty good where you might use the ridge regularization with more model with if you have something uh significantly larger and it encourages the coefficients of the variables to go towards zero because of the shape of the constraint which is an absolute value. And with any of this we want to go ahead 3:46:04 and uh do a demo in lasso and ridge regression. So let's take a look and see what that looks like in our code and bring up our Jupyter notebook. We'll start with our imports. Pandas as PD, import numpy as np, import mattplot library as plt. Um sklearn, we're going to import our data sets. It's kind of more generic. Um we usually just import one data set instead of all of them, but you know, quick and dirty when you're putting some of these together. Uh we have our sklearn model selection. We're going to import our train test split for splitting our data up and then we'll bring in our linear regression model and we'll go ahead and run these just to load them up and then load our data set. We were just talking about that. Uh you could just um um have imported the load Boston and Boston data set in there instead of loading all the data sets. Um, and then once we've loaded our data set, we want to go ahead and take a look at that data and see what we got here. Let 3:47:06 me just go and pop that down there and go and run it. And so, we've gone ahead and taken our uh Boston uh data. We're going to look, we put it into our pandas data frame. Um, the Boston data set and then the Boston columns. We want to see what's going on with them. Um, we have our target. we have the house price uh etc. And so our x equals Boston um i location. Now remember in pandas the new updates to pandas they want i location if you're going to pull data. We used to be able to leave this off but it does something different. It creates a slice versus a direct um setup. So make sure you're using that i location and the i the output. So this is all just bringing our data together. And we can see here if we do uh we print the Boston um panda's head, we can see here all of our different um aspects we're looking for. 3:48:06 And if you're following the X and the Y, the X is um everything except for the last column where Y is uh all the it's that's what this means. all the rows except for the last column and then Y is all the rows but just the last column. So Y is our house price and the X is the CRM Z and industry Chaz Knox and all these other different um statistics they've collected for house sales in Boston. There we go. Whoops. Control. Ah. So we'll go ahead and split our data. Uh X train and our X uh test Y train Y test equals the train test split which we imported. And we have our Boston um you could have easily used the X and Y on here as opposed to Boston um I location. And we'll create our test size. We're going to take 25% of the data and put it in as a test. 3:49:08 Uh and then we'll go ahead and run this. Uh, need an extra drink there. Uh, so we have our train and test and then of course the print the train data shape. I love doing this kind of thing whenever I'm working with this data. Print out the shape. Make sure everything looks correct. Uh, so that we have 127 by13 and 127 by 1, 379 by3. They should match. And if they're if the the data sets are not quite matching, then you know something's wrong and you're going to get all those errors. I don't know how many times I've gone through here and it's dropped a row on one of them and not on the other or something weird has happened when I'm cleaning the data. This is pretty straightforward and simple because the data comes in a nice prepackaged is all clean for you. So let's go ahead and imply apply the multiple linear regression model and uh we'll call this L reG LREG linear 3:50:09 regression. We're going to go ahead and fit that linear regression model to X-ray and Y train. Then we'll generate the prediction on the test set. Uh so here's our LREG Y predict with our X test going into the prediction and let's calculate that mean square error MSE. I told you you'll see MSSE used a lot. Um people use it in variables and things like that. It's pretty common. And we get our mean squared error equals uh this is just the basic formula we've already been talking about. What's the difference squared? Uh then we look for the average of that. We'll go ahead and just run this. And you can see when we get through the end of this, we have our mean square error on test. We have our total and then we have each column coming down. And at this point, unless you really know the data you're working with, it's not going to mean a whole lot. So, if it's in your domain, you might be know 3:51:09 what you're looking at when you see see these kinds of numbers coming up. Uh, but if it's not, it's just a bunch of numbers, and that's okay. At least that's okay for this demo. Uh, and then we're going to go ahead and plot these so we can see what's going on. And this is always kind of fun. It's always nice to have a nice visual of what you're looking at. And you can see here, um, we plot the coefficient scores on here. And we, the guys in the back did a great job putting some pretty colors together, making it look nice and setting up the columns. You can see here, uh, your NOx has like just a huge coefficient. Um when I look at a table like this, I look for what has very little um different coefficients. They're not using a huge change and what has huge changes. And that flags you for all kinds of things as you're working with the data. But it depends so much on the domain you're working with. These are great things though as just a quick look to see what's going on with your data and what you're looking for. 3:52:10 And of course once we look at this now our motive is to reduce the coefficient score. So now we want to take these and and uh bring them down as much as we can. And for that we're going to work with the ridge regression on here. So let's start by going ahead and we're going to import our ridge model. The ridge regression from the sklearn library or the scikit and we're going to go ahead and train the model. So here's our ridge r equals alpha equals 1. And I mentioned that earlier. Um, when I work with the ridge model, you'll see alpha equals 1. If you set alpha equal to zero, that's a standard linear regression model. So you have alpha equals 1 2 3 4. And you usually use 1 2 or 3 4 and a standard integer on there. And we'll go ahead and fit the ridge model on there with our x-ray and our yrain data. Generate a prediction for that um for our x test. and we'll calculate the mean square error uh just like we did before. This should all look familiar. And we'll go 3:53:12 ahead and print that out and we'll look at the uh ridge coefficients for our data and see what that looks like. Now, if I jump up and down between these two, you'll get a headache. Uh you'll still see the Knox value. Let's let's just look at the Knox because that was the biggest value. It's a minus 9 here. And if we go back up here, the NOX value is a minus8. So, right off the bat, I'm seeing a huge change um in the biggest coefficient there. Uh so, if we're going to do that nice setup, we want to go ahead and just print it and see what that looks like. Here we go. And we've uh set up our um plot subplots. And again, the team put together some nice color so it makes it look good. We're doing an Xbar based on the columns and our um L regress 3:54:13 coefficients, color equals color, ax spine, bottom, and so forth. Uh so just puts together a nice little graph. And you're starting to see uh one this when you compare this, if you put it on the same graph as this one up here, this is up here -8. This is at minus9. And so this graph is half the size of the graph above. Uh the same thing with these values here. They might look the same, but they're actually all almost half the value on here. And then finally, you can do the same thing for the lasso regression. This should all look uh very similar as far as what we worked on before. And I'm just going to ahead and print that on here and run it. And again, let's go up to uh Knox. Look where Knox is. It's all the way down to zero. And if we look at our next biggest coefficient is minus.8. And really here's our 22.73. 3:55:15 We go up here. Um 16.7. And we go up here and we look at the same number. uh 16.69. And so we look at this uh if I was running this and doing a working on a project with this, I would look at these numbers. I start with the 16.69. Uh come down here and compare it to uh 16.78. 69 is better than 78. Uh so from the very beginning, we might start looking at this first model for overall predicting. But there's other factors involved. Uh we might know that uh the NOX value is central and the other ones aren't quite as good. And so we might start looking at just certain setups like what is our what is this particular coefficient because it might have a certain meaning to us and so forth. And so you got look at all those different um items in there again. But the bottom dollar is our 3:56:16 first model did better than our other two models. our mean square error on the test set um continues to come down on this. We're going to cover reinforcement learning today and what's in it for you. We'll start with why reinforcement learning. We'll look at what is reinforcement learning. We'll see what the different kinds of learning strategies are that are being used today in computer models under supervised versus unsupervised versus reinforcement. We'll cover important terms specific to reinforcement learning. We'll talk about Marov's decision process and we'll take a look at a reinforcement learning example. Well, we'll teach a tic-tac-toe how to play. Why reinforcement learning? Training a machine learning model requires a lot of data which might not always be available to us. Further, the data provided might not be reliable. Learning from a small subset of actions will not help expand the vast realm of solutions that may work for a particular problem. And you can see here we have 3:57:16 the robot learning to walk. Um, very complicated setup when you're learning how to walk. And you'll start asking questions like, if I'm taking one step forward and left, what happens if I pick up a 50 lb object? How does that change how a robot would walk? These things are very difficult to program because there's no actual information on it until the it's actually tried out. Learning from a small subset of actions will not help expand the vast realm of solutions that may work for a particular problem. And we'll see here learned how to walk. This is going to slow the growth that technology is capable of. Machines need to learn to perform actions by themselves and not just learn off humans. And you see the objective climb a mountain. Real interesting point here is that as human beings we can go into a very unknown environment and we can adjust for it and kind of explore and play with it. Most of the models the non-reinforcement models in computer u 3:58:18 machine learning aren't able to do that very well. Uh there's a couple of them that can be used or integrated to see how it goes is what we're talking about with reinforcement learning. So what is reinforcement learning? Reinforcement learning is a subbranch of machine learning that trains a model to return an optimum solution for a problem by taking a sequence of decisions by itself. Consider a robot learning to go from one place to another. The robot is given a scenario must arrive at a solution by itself. The robot can take different paths to reach the destination. It will know the best path by the time taken on each path. It might even come up with a unique solution all by itself. And that's really important is we're looking for unique solutions. Uh we want the best solution, but you can't find it unless you try it. So we're looking at uh our different systems or different model. We have supervised versus unsupervised versus reinforcement learning. And with the supervised 3:59:19 learning, that is probably the most controlled environment. uh we have a lot of different supervised learning models whether it's linear regression neural networks um there's all kinds of things in between decision trees the data provided is labeled data with output values specified and this is important because we talk about supervised learning you already know the answer for all this information you already know the picture has a motorcycle in it so you're supervised learning you already know that um the outcome for tomorrow for you know going back a week you're looking at stock you can already have like the graph of what the next day looks like. So you have an answer for it and you have labeled data which is used. You have an external supervision and solves problems by mapping labeled input to known output. So very controlled unsupervised learning and unsupervised learning is really interesting because it's now taking part in many other models. They start with an you can actually insert an unsupervised learning model um in almost either supervised or 4:00:21 reinforcement learning as part of the system which is really cool. Uh data provided is unlabelled data. The outputs are not specified. Machine makes its own predictions used to solve association with clustering problems. Unlabeled data is used. No supervision. Solves problems by understanding patterns and discovering output. Uh so you can look at this and you can think um some of these things go with each other. They belong together. So it's looking for what connects in different ways. And there's a lot of different algorithms that look at this. Um when you start getting into those are some really cool images that come up of what unsupervised learning is. How it can pick out say uh the area of a donut. one model will see the area of the donut and the other one will divide it into three sections based on its location versus what's next to it. So there's a lot of stuff that goes in with unsupervised learning and then we're looking at reinforcement learning. Probably the biggest industry in today's market uh in machine learning or growing 4:01:22 market. It's very it's very infant stage uh as far as how it works and what it's going to be capable of. The machine learns from its environment using rewards and errors used to solve rewardbased problems. No predefined data is used. No supervision. Follows trail and error problem solving approach. Uh so again we have a random at first you start with a random. I try this it works and this is my reward. Doesn't work very well maybe or maybe doesn't even get you where you're trying to get it to do. and you get your reward back and then it looks at that and says well let's try something else and it starts to play with these different things finding the best route. So let's take a look at important terms in today's reinforcement model and this has become pretty standardized over the last uh few years. So these are really good to know. We have the agent uh agent is the model that is being trained via reinforcement learning. So this is your actual uh entity that has however you're doing it whether you're using a neural network or 4:02:24 Q table or whatever combination thereof. This is the actual agent that you're using. This is the model and you have your environment. Uh the training situation that the model must optimize to is called its environment. Uh and you can see here I guess we have a robot who's trying to get a chest full of gems or whatever. And that's the output. And then you have your action. This is all possible steps that can be taken by the model and it picks one action and you can see here it's picked three different uh routes to get to the chest of diamonds and gems. We have a state the current position condition returned by the model. And you could look at this uh if you're playing like a video game. This is the screen you're looking at. Uh so when you go back here uh the environment is a whole game board. So, if you're playing one of those Mobius games, you might have the whole game board going on. Uh, but then you have your current position. Where are you on that game board? What's around that? What's around you? Um, if 4:03:24 you were talking about a robot, the environment might be moving around the yard, where it is in the yard, and what it can see, what input it has in that location. That would be the current position condition returned by the model. And then the reward uh to help the model move in the right direction. It is rewarded. Points are given to it to appraise some kind of action. So yeah, you did good or if uh didn't do as good trying to maximize the reward and have the best reward possible. And then policy. Policy determines how an agent will behave at any time. It acts as a mapping between action and present state. This is part of the model. What what is your action that you're you're going to take? what's the policy you're using to have an output from your agent. One of the reasons they separate a policy as its own entity is that you usually have a prediction um of a different options and then the policy well how am I going to pick the best based on those predictions I'm going to 4:04:26 guess at different options and we'll actually weigh those options in and find the best option we think will work. Uh, so it's a little tricky, but the policy thing is actually pretty cool how it works. Let's go ahead and take out look at a reinforcement learning example. And just in looking at this, we're going to take a look uh consider what a dog um that we want to train. Uh so the dog would be like the agent. So you have your your puppy or whatever. Uh and then your environment is going to be the whole house or whatever it is where you're training them. And then you have an action. We want to teach the dog to fetch. So action equals fetching. Uh and then we have a little biscuit. So we can get the dog to perform various actions by offering incentives such as a dog biscuit as a reward. The dog will follow a policy to maximize this reward and hence will follow every command and might even learn new actions like begging by itself. Uh so you have b you know so we start off with fetching. It goes oh I get a biscuit for that. it 4:05:26 tries something else and you get a handshake or begging or something like that and it goes oh this is also reward-based and so it kind of explores things to find out what will bring it as biscuit and that's very much like how a reinforced model goes is it uh looks for different rewards how do I find can I try different things and find a reward that works the dog also will want to run around and play and explore it environment uh this quality of model is called exploration so there's a little randomness going on an in exploration and explores new parts of the house. Climbing on the sofa doesn't get a reward. In fact, it usually gets kicked off the sofa. So, let's talk a little bit about Marov's decision process. Uh Marov's decision process is a reinforcement learning policy used to map a current state to an action where the agent continuously interacts with the environment to produce new solutions and receive rewards. And you'll see here's all of our different uh uh vocabulary we 4:06:28 just went over. We have a reward, our state, our agent, our environment, interaction. And so even though the environment kind of contains everything um that you you really when you're actually writing the program, your environment is going to put out a reward and state that goes into the agent. Uh the agent then looks at this uh state or it looks at the reward usually um first and it says okay I got rewarded for whatever I just did or I didn't get rewarded and then it looks at the state and then it comes back and if you remember from policy the policy comes in um and then we have a reward. The policy is that part that's connected at the bottom. And so it looks at that policy and it says, "Hey, what's a good action that will probably be similar to what I did?" Or um uh sometimes they're completely random, but what's a good action that's going to bring me a different reward? So, taking the time to just understand these different pieces as they go is 4:07:30 pretty important in most of the models today. Um, and so a lot of them actually have templates based on this that you can pull in and start using. Um, pretty straightforward as far as once you start seeing how it works. Uh, you can see your environment sends it says, "Hey, this is the agent did this. If you're a character in a game, this happened and it shoots out a reward in a state." The agent looks at the reward, looks at the new state, and then takes a little guess and says, "I'm going to try this action." And then that action goes back into the environment. it affects the environment. The environment then changes depending on what the action was and then it has a new state and a new reward that goes back to the agent. So in the diagram shown, we need to find the shortest path between node A and D. Each path has a reward associated with it and the path with a maximum reward is what we want to choose. The nodes A, B, C, Denote the nodes to travel from node uh A to B is an action. Reward is the 4:08:30 cost of each path and policy is each path taken. And you can see here A can go uh to B or A can go to C right off the bat or it can go right to D. And if you explored all three of these uh you would find that A going to D was a zero reward. Um A going to C and D would generate a different reward. Or you could go AC B D. There's a lot of options here. Um and so when we start looking at this diagram, you start to realize that even though uh today's reinforced learning models do really good at um finding an answer, they end up trying almost all the different directions you see. And so they take up a lot of work uh or a lot of processing time for reinforcement learning. They're right now in their infant stage and they're really good at solving simple problems. And we'll take a look at one of those in just a minute in a tic-tac-toe game. Uh but you can see here uh once it's gone through these and it's explored, it's going to find the AC D is the best 4:09:32 reward. It gets a full 30 points for it. So let's go ahead and take a look at a reinforcement learning demo. Uh in this demo, we're going to use reinforcement learning to make a tic-tac-toe game. You'll be playing this game against the machine learning model. And we'll go ahead and we're doing it in Python. So, let's go ahead and go through um I always uh not always actually have a lot of Python tools. Let's go through um Anaconda, which will open up a Jupyter notebook. Seems like a lot of steps, but it's worth it to keep all my stuff separate, and it's also has a nice display when you're in the Jupyter notebook for doing Python. So, here's our Anaconda Navigator. I open up the notebook, which is going to take me to a web page. And I've gone in here and created a new uh Python folder. In this case, I've already done it and enabled it. Change the name to tic-tac-toe. Uh, and then for this example, uh, we're going to go ahead and import a couple things. We're going to, um, import numpy as np. We'll go ahead and import pickle. Numpy, of course, is 4:10:33 our number array. And, uh, pickle is just a nice way sometimes for storing, uh, different information, uh, different states that we're going to go through on here. Uh, and so we're going to create a class called state. We're going to start with that. And there's a lot of uh lines of code to this uh class that we're going to put in here. Don't let that scare you too much. There's not as much here. Uh it looks like there's going to be a lot here, but there really is just a lot of setup going on in the in our class state. And so we have up here, we're going to initialize it. Um we have our board. Um, it's a tic-tac-toe board, so we're only dealing with nine spots on the board. Uh, we have player one, player two, uh, is end. We're going to create a board hash. U, we'll look at that in just a minute. We're just going to store some information in there. Symbol of player equals one. Um, so there's a few things going on as far as the initialization. Uh, then something 4:11:35 simple. We're just going to get the hash um of the board. you get the information from the board on there, which is uh columns and rows. We want to know when a winner occurs. Uh so if you get three in a row, that's what this whole section here is for. Uh let me go ahead and scroll up a little bit. And you can get a copy of this code if you send a note over to SimplyLearn. We'll send you over um this particular file and you can play with it yourself and see how it's put together. I don't want to spend a huge amount of time on this uh because this is just some real general Python coding. Uh but you can see here we're just going through all the rows and you add them together and if it equals three, three in a row. Same thing with columns. Uh diagonal. So you got to check the diagonal. That's what all this stuff does here is it just goes through the different areas. Actually, let me go ahead and put There we go. Um, and then it comes down here and we do our sum and it says true uh minus 4:12:36 three just says did somebody win or is it a tie? So you got to add up all the numbers on there anyway just in case they're all filled up. And next we also need to know available positions. Um, these are ones that don't no one's ever used before. This way when you try something or the computer tries something uh it's not going to give it an illegal move. That's what the available positions is doing. Uh then we want to update our state. And so you have your position going in. We're just sending in the position that you just chose. And you'll see there's a little user interface we put in there. You p pick the row and column in there. And again, I mean, this is a lot of code. Uh so really it's kind of a thing you'd want to go through and play with a little bit and just read through it, get a copy of it. Uh great way to understand how this works. And here is a given reward. Um, so we're going to give a reward. Result equals self-winner. This is one of the hearts of what's going on 4:13:36 here. Uh, is we have a result self.winner. So if there's a winner, then we have a result. If the result equals one, here's our feedback. Uh, if it doesn't equal one, then it gets a zero. So it only gets a reward in this particular case if it wins. And that's important to know because different uh systems of reinforced learning do rewarding a lot differently depending on what you're trying to do. This is a very simple example with a 3x3 board. Imagine if you're playing a video game. Uh certainly you only have so many actions, but your environment is huge. You have a lot going on in the environment. And suddenly a reward system like this is going to be just um is going to have to change a little bit. it's going to have to have different rewards and different setup. And there's all kinds of advanced ways to do that as far as weighing you add weights to it. And so they can add the weights up depending on where the reward comes in. 4:14:38 So it might be that you actually get a reward. In this case, you get the reward at the end of the game. And I'm spending just a little bit of time on this because this is an important thing to note. But there's different ways to add up those rewards. it might have like if you take a certain path um the first reward is going to be weighed a little bit less than the last reward because the last reward is actually winning the game or scoring or whatever it is. So this reward system gets really complicated on some of the more advanced uh setups. Um, in this case though, you can see right here that they give a a 0.1 and a 0.5 reward um just for getting a picking the right value and something that's actually valid instead of picking an invalid value. So, rewards again, that's like key. It's huge. How do you feed the rewards back in? Uh, then we have a board reset. That's pretty straightforward. It just goes back and resets the board to the beginning because it's going to try out all these different things while it's learning. It's going to do it by trial and error. 4:15:39 So, you have to keep resetting it. And then, of course, there's the play. We want to go ahead and play uh rounds equals 100. Depends on what you want to do on here. Um you can set this different. You obviously set that to higher level, but this is just going to go through and you'll see in here uh that we have player one and player two. This is this is the computer playing itself. Uh, one of the more powerful ways to learn to play a game or even learn something that isn't a game is to have two of these models that are basically trying to beat each other. And so they always they keep finding explore new things. This one works for this one. So this one tries new things, it beats this. We've seen this in um chess, I think, was a big one where they had the two players in chess with reinforcement learning. uh is one of the ways they train one of the top um computer chess playing algorithms. Uh so this is just what this is. It's going to choose an action. It's going to try something and the more it tries 4:16:40 stuff um the more we're going to record the hash. We actually have a board hash where they self get the hash set up on here where it stores all the information. And then once you get to a win, one of them wins, it gets the reward. Uh then we go back and reset and try again. And then kind of the fun part we actually get down here is uh we're going to play with a human. So we'll get a chance to come in here and see what that looks like when you put your own information in. And then it just comes in here and does the same thing it did above. It gives it a reward for its things um or sees if it wins or ties. Um looks at available positions, all that kind of fun stuff. And then finally, we want to show the board. Uh so it's going to print the board out each time. Really um as an integration is not that exciting. What's exciting uh in here is one looking at this reward system. Whoops. Play one more up. The reward system is really the heart of this. How do you reward the different uh setup and 4:17:41 the other one is when it's playing it's got to take an action. And so what it chooses for an action is also the heart of reinforcement learning. How do we choose that action? And those are really key to right now where reinforcement learning is uh in today's uh technology is uh figuring this out. How do we reward it and how do we guess the next best action? So we have our uh environment and you can see the environment is we're going to be or the state uh which is kind of like what's going on. We're going to return the state depending on what happens. And we want to go ahead and create our agent. Uh in this case, our player. So each one is let me go and grab that. And so we look at a class player. Um this is where a lot of the magic is really going on is what how is this player figuring out how to maneuver around the board? And then the board of course returns a state uh that it can 4:18:42 look at and a reward. Uh so we want to take a look at this. We have a name uh self state. This is class player. And when we say class player, we're not talking about a human player. We're talking about u just a uh the computer players. And this is kind of interesting. So remember I told you depending on what you're doing, there's going to be a decay gamma. Um explore rate. Uh these are what I'm talking about is how do we train it? Um as you try different moves, it gets to the end. The first move is important, but it's not as as important as the last one. And so you could say that the last one has the heaviest weight. And then as you as you get there, the first one, let's see, the first move gives you a five reward. The second gives you a two reward. And the third one gives you a 10 reward because that's the final ending. You got it. The 10's going to count more than the first step. Uh and here's our uh we're going to, you know, get the board information coming in and then choose an action. This was the second 4:19:42 part that I was talking about that was so important. Uh so once you have your training going on, we have to do a little randomness. And you can see right here is our NP random u uniform. So it's picking out a random number. Take a random action. This is going to just pick which row and which column it is. Um and so choosing the action. This one you can see we're just doing random states. uh choice, length of positions, action position, and then it skips in there and takes a look at the board uh for P and positions. You it's actually storing the different boards each time you go through so it has a record of what it did so it can properly weigh the values. And this simply just appends a hash state. What's the last state? Pinned it to the uh to our states on here. Here's our feedback reward. the reward comes in and it's going to take a look at this and say is it none uh what is the reward and here is that formula remember I was telling 4:20:42 you about up here um that was important because it has decay gamma times the reward this is where as it goes through each step and this is really important this is this is kind of the heart of this of what I was talking about earlier uh you have step one and And this might have a a reward of two. You have step two. I probably should have done ABC. This has a step three. Uh step four. So on till you get to step in. And this might have a reward of 10. Uh so reward of 10. We're going to add that. But we're not adding uh let's say this one right here. Uh let's say this reward here right before 10 was um let's say it's also 10. That just makes the the uh math easy. So we had 10 and 10. Uh we had 10. This is 10 and 10 in whatever it is. But it's time it's 0.9. Uh so instead of putting 4:21:45 a full 10 here, we only do nine. That's uh 0.9 times 10. And so this formula um as far as the decay times the reward minus the cell state value uh it basically adds in it says here's one or here's two. I'm sorry I should have done this ABC would have been easier. Uh so the first move goes in here and it puts two in here. Uh then we have our self uh setup on here. You can see how this gets pretty complicated in the math, but this is really the key is how do we train our states and we want the the final state, the win to get the most points. If you win, you get most points. Um, and the first step gets the least amount of points. So, you're really training this almost in reverse. You're training, you're training it from the last place where you have like it says, "Okay, this is now where I where need to sum up my rewards and I want to sum them up going 4:22:47 in reverse and I want to find the answer in reverse." Kind of an interesting uh uh play on the mind when you're trying to figure this stuff out. And of course, we want to go ahead and reset the board down here. Uh save the policy, load policy. These are the different things that are going in between the agent and the state to figure out what's going on. Let's go ahead and load that up. And then finally, we want to go ahead and create a human player. And the human player is going to be a little different uh in that uh you choose an action row and column. Here's your action. Uh if action is if action in positions, meaning positions that are available, uh you return the action. If not, it just keeps asking you until you get an action that actually works. And then we're going to go ahead and append to the hash state, which uh we don't need to worry about because it returns the action up here. And feed forward. Uh again, this is 4:23:48 because it's a human. Um at the end of the game, bat propagate and update state values. This part isn't being done because it's not programming uh the model. Uh the model is getting its own rewards. So, we've gone ahead and loaded this in here. Uh, so here's all our pieces. And the first thing we want to do is set up uh P1, player one, uh, P2, player two. And then we're going to send our players to our state. So, now it has P1, P2, and it's going to play, and it's going to play 50,000 rounds. Now, we can probably do a lot less than this, and it's not going to get the full results. In fact, you know what? Uh, let's go ahead and just do five. Um, just to play with it because I want to show you something here. Oops. Somewhere in there I forgot to load something. There we go. I must have forgot to run this run. Oops, forgot a reference there for the 4:24:50 board rows and columns 3x3. There is actually in the state it references that. We just tack it on on the end. It was supposed to be at the beginning. Uh, so now I've only set this up with um, see where are we going here? I've only set this up to train five times. And the reason I did that is we're going to uh, come in and actually play it and then I'm going to change that and we can see how it differs on there. There we go. And it didn't make it through a run. And we're going to go ahead and save the policy. Um, so now we have our player one and our player two policy. Uh, the way we set it up, it has two separate policies loaded up in there. And then we're going to come in here and we're going to do uh player one is going to be the computer experience rate zero. Load policy one human player human. And we're going to go ahead and play this. Now remember, I only went through it um 4:25:51 uh just one round of training. In fact, minimal training. And so it puts an X there. And I'm going to go ahead and do row zero, column one. You can see this is very uh basic on here. And so I put in my zero. And then I'm going to go zero, block it, zero, zero. And you can see right here, it let me win. Uh just like that, I was able to win. Zero two. And woo, human wins. So I only trained it five times. We're going to run this again. And this time, uh, instead of five, let's do 5,000 or 50,000. I think that's what the guys in the back had. And this takes a while to train it. This is where reinforcement learning really falls apart. Look how simple this game is. We're talking about a 3x3 set of columns. And so for me to train it on 4:26:52 this um I could do a Q table which would take which would go much quicker. Um you could build a quick Q table with almost all the different options on there and uh you would probably get a the same result much quicker. We're just using this as an example. So when we look at reinforcement learning, you need to be very careful what you apply it to. It sounds like a good deal until you do like a large neural network where you're doing um you set the neural network to a learning increment of one. So every time it goes through it learns and then you do your actions. So you pick from the learning uh setup and you actually try actions on the learning setup until you get the what you think is going to be the best action. So you actually feed what you think is right back through the neural network. There's a whole layer there which is really fun to play with. and then it has an output. Well, think of all those processes. I mean, that is just a huge amount of work it's going to do. Uh, let's go ahead and skip ahead 4:27:52 here. Give it a moment. It's going to take a a minute or two to go ahead and run. Now, to train it, uh, we went ahead and let it run. And it took a while. This this took, um, I got a pretty powerful processor, and it took about five minutes plus to run it. and we'll go ahead and uh run our player setup on here. Oops, it brought in the last Whoops, it brought in the last round. So, give me just a moment to reddo the policy save. There we go. I forgot to save the policy back in there and then go ahead and run our player again. So, we we've saved the policy and then we want to go ahead and load the policy for P1 as a computer. And we can see the computer's gone in the bottom right corner. I'm going to go ahead and go uh one one which is the center and it's gone right up the top. And if you have ever played tic-tac-toe, you know the computer has me. Uh but we'll go ahead and play it out. Row zero, 4:28:55 column two. There it is. And then it's gone here. And so I'm going to go ahead and go row 01 two. No, 01. There we go. and column zero. That's where I wanted. Oh, and it says I Okay, you your action. There we go. Boom. Uh, so you can see here we've got a didn't catch the win on this. It said tie. Um, kind of funny that it didn't catch the win on there. But if we play this a bunch of times, you'll find that it's going to win more and more. The more we train it, the more the reinforcement happens. This lengthy training process uh is really the stopper on reinforcement learning. As this changes, reinforcement learning will be one of the more powerful uh packages evolving over the next decade or two. In fact, I would even go as far as to say it is the most important uh machine learning tool and artificial intelligence tool out there as it learns not only a simple tic-tac-toe board, but we start learning 4:29:56 environments. And the environment would be like in language. If you're translating a language or something from one language to the other, so much of it is lost if you don't know the context it's in. What's the environments it's in? And so being able to attach environment and context and all those things together is going to require reinforcement learning to do. We will get started by a brief introduction to LLMs and chatbots. Later we will dive into setting up the development environment. Then we will understand data collection and preparation. Followed by that we will understand the implementation of LLMs. Later we will check into chunking and embedding for vector search or rag. Followed by that we will learn implementing query processing and recommendations. Next we have zeros short text classification and lastly the sentiment analysis with LLMs. Hope I made myself clear with the agenda. Now handing over the session to our experts. Hi welcome all. Welcome to simply learn session on how to create LLM chatbot. In 4:30:57 this course, we are going to talk about what is LLM, what are chatbots, we'll try to see how do we start developing a chatbot using large language models where we'll try to understand how do we set up the environment. Then we talk about how do we collect and prepare the data for LLMs to understand. Then how do we implement LLMs chunk and embedding vectors that is required for retrieval augmentation? So that is embedded of the data chunks. I will talk about those things. We'll further talk about how do we implement query processing and recommendation systems. We'll give an understanding on prompt engineering of zerosot text classification which is the type of prompt engineering. And we talk about finally with the sentiment analysis with LMS. So we can create multiple types of LLMs and we can create sentiment analysis LM. At the end of the session, we'll try to develop or go through with a piece of code using lang chain to 4:31:57 create a chat model using open AI APIs and we will work on that and try to put that into production environment using streamllet. That would be the agenda for the day. So how do we create LLM chatbots and we'll start with what is an LLM? LLMs are nothing but large language models which are trained on very huge amount of text and they have the capability of generating humanlike test. So they are slightly enhanced version of the natural language processing tools that we have seen before in the deep neural network architectures wherein those architectures using LSTM models or GRU models or similar models with respect to or the RNN models. These models were able to understand the text 4:32:59 and give an understanding of those text that what exactly is the inherent meaning about those text messages. However, the large language models are a step ahead of the previous versions and they are able to gener not only understand the text but they are able to generate the text based upon the information given to them. So that is what we call as a large language models. These are primarily trained on a very huge amount of data. They do not have any kind of predefined resources. They they are trained on a very humongous amount of data. Now how it work? If I talk about how LLM works, LLM typically takes up a huge amount of text and breaks it down into the pieces we call them as the tokens. Now what is the tokens? as a very small level a very basic level I can say that tokens are nothing but the words at a 4:34:00 very broader perspective you can understand tokens as words so words in any context in any paragraph let's say you have 10 words or 20 words or 1,000 each word can be considered as one token at times we can also consider a entire sentence as a word as a token so that is dependent upon which kind of modeling technique being used. We are using sentence tokens or we are using word tokens. But yes, at a very basic level, at a very grassroot level, you can think of tokens as simple words which are leotized or stem. So stemmed or words stemming and lematization are the basic concepts which are coming from the natural language processing part where we try to cut down the words to a basic root level grassroot level words. So that is the idea behind stemming so that we get similar words for every problem. 4:35:01 Just for an example you can think of a simple example if I write down few words for you. I can write down a word break. So we were talking about how LLM works. So in general terms, if we talk about how LLM works, LLM will be trying to process my entire text data and create tokens out of it. So out of those tokens, the tokens can be considered as single words or sentences at times depending upon the mechanism that is being used. But you can at a very broader level we can consider tokens as the piece of words which are at a root level words. For example, breaking will become break or into will remain into or breaks will also become break. So depending which are the root words which generates other words. We'll try to contextualize all words into a single entity which are of similar nature. 4:36:03 The word transformer might become a transform. Architectures might become just an architect. So depending upon different kind of words, you might have some basic root words that will come to the picture. That is what we call as a tokenization, stemming and natural language processing. So that's what we try to do. After tokenization we get small little words as I've mentioned you words or sub words and we try to convert them into vector representation and we call them as numerical representation of those words. Let's say every single word in my entire word dictionary I will give them a particular number. Let's say K is at number one, B is at two, lamb is at three, so on and so forth. So each particular word out of my entire contextual words will have a number associated with them. I'm giving a random example and with that we can assume that those numbers I can represent in 4:37:03 different form maybe in hex code form or in in a binary coded form or some other form I can represent them and we can use that numerical representation of each word in order to understand those words in numerical form because it would be the numerical representation of the data that will help in making things clearer and understandable. Right after this LLMs once we got the the relevant tokens then we it uses the attention mechanism. Now what is an attention mechanism? There's a famous research paper on this which is attention is all you need published in 2017 from Google brain team. That paper talks about a self attention mechanism which is the primary source of all transformer models. LMS also use transformer modeling approach. So that is where it contains of a self attention layer and mask multi attention layers. So that's the basic underlying principle behind all the LMS. 4:38:03 So we have an encoder block and we have a decoder block and we work on those two blocks together in order to understand what is the input being given and what could be the potential text that could be generated for the given input. That is what attention mechanism allows us to do. We can discuss the cell potentation mechanism in detail in another separate video. That's what transformer talks about. So these are very different deep learning architectures which actually does not use a neuron kind of thing. If you have studied about deep learning architectures, you would have seen that every deep learning architecture at the hidden level has certain neurons at the center which takes the input and process it and gives the output. In LMS we use a self attention mechanism module where we replace those neurons by self attention blocks. The self attention blocks is two important portions. One is an encoder, other one is a decoder. And again certain LLMs may be just coder module. 4:39:05 Certain LMS might be just a decoder module. Certain would be a combination of ports. All the generated ones are the models that are combination of both encoding and decoding part. If I talk about types of chatbots, the chat bots is another example of using large language model. What does chatbot do for us? We ask the question, we put up a prompt, we put up a query in front of a machine and then machine is able to respond back based upon the query being put up. There can be two classification of the chatbot based upon these two versions. The first is a rulebased chatbot and second one is AI based chatbot. What are the rulebased chatbots? So rulebased chatbots are those where they have a defined set of rules and pre-written scripts for a particular question. Let's say how are you? So if I have mentioned already or defined if someone asks you how are you it'll give me a particular answer. If 4:40:06 that question is not into the vocabulary it will say that sorry I'm not able to answer that question. I'm not trained under that part. So those are called as rulebased chatbot or rule based LLMs. Typically these kind of rule-based LLMs use decision algorithms or random forest autobased algorithms in order to understand and create rules and then give the answers. Typically that's the underlying logic board that goes behind the rule based chat bots. Typically not into practice too much these days we have AI powered chat bots which are much more responsive and much more better. So we'll use in this class as well we will work on AI based chat. the rulebased chatbots which are very simple to implement and very easy to put up through they will not be able to handle very complex wordings because you will not be able to give sufficient amount of examples right then you have AI based chat bots you can put up any kind of queries I'm pretty much sure most of us would have used AI 4:41:07 based chat bots like chat GPT or entropic right or Gemini you would have used some of you might have use those some common names that I've taken out. So all these are AI based chat bots right depending upon my requirement what requirement that we have what kind of chatbot should I use is very much important because I need to look at many factors like how much customization is required what is the cost involved how do we I want to deployment what is my deployment requirements how much opensource do I want it make make it to be open source availability for Last and most most important factor is how much is a private data that means a data which is not available publicly for open AI models or opensource models to learn from. So do I want to include that data or not? That is also an important factor. If I have to include the data 4:42:09 the type of AI based chatbots will also vary because there will be two types of AI chatbot. one that we use with the pre-trained models which will work in this class and the one the other one that uses pre-trained models along with that it also takes up a chunk of data or it can also get trained from some other data as well that is we call as rag approach retrieval augmented approach all right so this is what we have seen so far setting up the development environment in order to create development environment we can choose many things there are multiple APIs which are available but in this particular section we will use openAI API it is easily and freely available right so we require a coding environment I'm going to use Jupyter lab for it some libraries to name few of them I'm going to use streamllet we are going to use lang chain or else that would be more than sufficient numpy and mattplot would also be required that's it so these are 4:43:10 the few libraries whether I want to do a cloud-based deployment or Onromises deployment depends that dependency needs to be understanded because cloud-based deployments would require a little more resources. We need to ensure about the correct API access. The API access that I'm going to use is my own personal open AI access. So you will I would mention OpenAI key at the place of the code where it is required to put up the OpenAI key. All right. Thank you. will require understanding of basic Python understanding how do we write Python scripts how do we integrate APIs with the Python scripts two important things we'll use Jupyter notebook in this case and VS code or either you can use any technology because we are going to write down a py so whatever you're comfortable with Jupyter notebook vs code or just python working environment I'm okay with that Python editor so API Access it can be requested from 4:44:11 OpenAI Coher or Hugging Face. I'm going to use OpenAI in this class. So I'll show you how to gain a OpenAI access. You can go to platform.openai.com register yourself and you can generate your OpenAI API key. Right? So transformers I can use blank chain will which will require me to develop a chatbot logic and that's what we're going to do. We can use llama index for data retrieval or you can use fast API gradio that can allow fast API and gradio will allow me to put the deployment part but we're not going to use that. You can use cloud-based services like AWS, Azure or cloud. We're not going to cover that too as well because that's not within this. So data collection and preparation part. So we need to collect the data in the form of either CSV, JSON or web scrapping data. go to numpy pandas create the data and refine the data but in this particular section we are not going to deal with NLT or spacy library 4:45:13 we are not going to train the model as of now we're going to use pre-trained models from openAI API so how do we create LLM chatbots so that will be practical parts that we'll try to understand how do we can create LLM chatbots what we require is few understanding if I'm going to train up a model for example I'm going to train up an LLM model you need a model architecture which can be implemented which can be downloaded from transfer learning methodologies you can get all those models either from hugging face or directly from transformers library or directly from tensorflow or pytor whichever way you're trying to implement we can get it them from there apart from that what kind of model is required That is also an important thing because if I'm doing a sentiment analysis, I'll require a sentiment analysis. If I'm looking for a question answering approach, I would require a question and answering approach. If I'm requiring 4:46:14 general question answers, generic models, so I can use generic model like chart GPT. So depending upon my requirement, I would have to choose the correct model and correct APIs accordingly. That is must first important task that we need to right. That's we have talked about if I'm trying to use different LLMs are required different kind of things for general versatility GP is good open source customization lamas are good mistrol for efficiency falcon for scalability so right model will depend on many factors like performance cost and deployment needs we can get right models whatever models that you want from hugging face or API based models API based models would include like I have open API access and on open API we have a chat GPT 40 mini version which is available for access with me. So I'll use that. Now how to create an LM chatbot? For this we need to understand what is retrieval augmented generation. So what is that 4:47:15 retrieval augmented generation? Suppose I'm trying to do a search for example I typed in a query what is the role of Python? Just a simple word what is the role of Python. In this scenario, it will try to find out out of my entire context that I have given. What is the role of Python? It will try to find out what are the most relevant words with respect to the question being asked, the meaning that it has and based upon that it creates a architecture of most important keywords and that keyword is called as R A or retrieval argumented generation. So after that it finds out what are the most important keywords and based upon that it performs the extensive search through the data that it has and finds out the correct responses matching keywords from different resources then from all different resources learn everything and then come back with my solution. So that is what it is going to do for us. What it allows us to do is the rag approach is my model or my NLM is not going to give me random vague answers. 4:48:15 not only create or generate answers without any context. It will always try to find out some semantic information and give good contextual answers. Same thing happens with the chunking and numbering in vector search. It it tries to break down the entire text into small little manageable pieces. We call them tokens again converted to numbers are called as vectors. Again it can be done through many other libraries like chunking and embedding can be done by lang chain character text splitter we can do through NLTK or we can do it from tick token. Tick token is not to be misunderstood with tik tok. It's a different entity algether. Token is a library that allows us to tokenize my text. Then we have transformers like s and transformers available which are allows me to create the vectors. Vectors means again numerical representation of my text. Then we store that in the database. Any simple database can work for us. Then we look for the similarity scores like cosign similarity, ukidian 4:49:16 similarity scores or product similarity scores to find out what kind of matching architectures as I've told you rag uses this approach finds out similar context words. So from there it will try to get me those similarity words and find out similar contextual information. Then we talk about the implementation of query processing and recommendation. In query processing the idea again change is nothing but but it you ask a question. LLM works around with that again breaks it down into a text form. From text it converts vectors and since it's a question so it becomes a question answer kind of approach. So it will find out 10 answers and try to filter out the best suitable answer for any query that is being done. Now what is zeros text classification? In a zero sort text classification, I do not train my model explicitly. Right? So what that is zero sort classification where I'm not putting up 4:50:17 any additional resource. What is that meaning is I have a pre-trained model like GPT that is being trained on very generic knowledge. Very generic knowledge that may not be very specific about the context that I'm asking. Say for example I have chat GP which is trained on almost everything world but it might not be trained on my organization's specific issues but I can still ask this question about my organization. It may not be able to give me a very specific answer but it will be able to give me a generic answer. That is what we call zeros text classification where I'm not training a LLM on a specific data rather I'm just creating an LLM from a pre-trained model and asking it for new data installation. Right? How can you find out some classification models? There are lots and lots of available. I can just show you very quickly pre-trend classification model. You can go on to huggingface.co 4:51:19 that would be a place you can find a lot of pre-trend classification models available. You can find out models based upon your requirement. You can go to the models and you can click by the task whatever task that you let's say I'm trying to do some text natural language processing. That's a zero sort classification. I have lot many models here. But just for zero shot classification, these are the models available. I have bought large M& life from Facebook. That's one of the zeros classification model. You can look at that. Go to files and versions. This is the entire model. You can see that you can read out this reading.md file and find out the information about it. So there are a lot of models which are available which you can use. Again it's a GitHub. So you can clone this live entire part and you can clone it from directly from hugging face. Clone the repository and use it locally. Okay. So any model can be used. So b large 4:52:22 mini mli that's one classification model that can be used out. There can be a lot of things that can be done in zero sort classification. Apart from that you can create transform of pipelines wherein I'm trying to do one transformation followed by another one followed by another one and so on. So that can be created up. We can use a scikit matrix like procedure recall or f1 sports to find out we have correct classification. We can implement those two. Finally we'll talk about the sentiment analysis with LLMs. LMS can also be very much useful in doing the sentiment analysis part. So in sentiment analysis we try to look at how we can determine the emotional tone of any text uh allowing or enabling chat bots to understand the user sentiment. So we try to train the chat bots on uh emotional cont on a on data which contains emotional aspects. We can define it whether it's a positive or emotion or a negative emotion or sad emotion or happy 4:53:22 emotion. We can pray the alms of God and based upon that training my alms would be able to tell me whether any particular emotions being reflected is what kind of emotion it is. It may not be able to mimic that emotion but it will be able to tell me what emotion has been reflected in the context. It can be with the audio, it can be with the video or it can text as well. That is the sentiment analysis. Again distb is one of the very good classification model for sentiment analysis that is what we can use. Sentiment analyzer is available with many other sentiment analyzer is available with distbut robbert llama everywhere we have a sentiment analyzer available. It's a one of the class in a pre-trend model which is available to analyze the sentiments. So this is what we will talk about through the entire understanding of your LLMs theoretically. Let's try to practically look at how do we implement that. So I will open up. 4:54:26 Let me open up my Anaconda Navigator. So I'm going to open up Anaconda Navigator. Here I have a pre-written script. I'll walk you through that and I'll explain you each line what it is doing. Hopefully that helps. So here it is. I have just got my Anaconda Navigator opened up. I'm going to open up my Jupyter Lab environment from here. Wait for that to open up. Should be up and running in a moment from now. So once that opens up we will be able to start doing the coding part of creating a chart GPT kind of approach where that would be in the implementation of chart GPT through chart GPT open API that we can use at our own local servers or at our own particular end. Essentially that is the replica of chat GPT that you can put up. 4:55:26 Okay, I already have this piece of code written down for you. So what are we going to do here? So I'll put down certain piece of codes here. This file will be made available in the description too or you can copy it from here. Okay. So what is each of these things that we're going to do? So I have named that as I have created a Python script here. For that I've gone to file new and I've used a python file. I went into that option and I create a python file. First that I wrote down is import stream. So this will allow I'll put up certain libraries to be done. Libraries import prior to that you might be wondering if I don't have those libraries. So you need to install these. I'm putting that as a comment pip install. Uh or if you're using an environment, you need to put that into your environment. So I'll put up that pip install. You need to put up lang chain. 4:56:27 I'm using lchain here space. You would require streamlet. Okay, that should be good. These two will be good. Okay, you need to install these two libraries langchain and streamllet. What I'm using streamllet for lang chain I'm just putting this notes and chain supports or lchain for the purpose of building chatbot logic okay and streamlet for designing UI. I'm not going to give too much into designing part. We'll take a simple UI as of now. Idea is not to do the designated designing part. Designing the user interface. Okay. So a web based user interface I say that designing a web based user 4:57:29 interface. A separate session on streaml can be taken up to design all that part. So streamllet is separate library al together. So we will import streamllet as ST that allows me to import streamllet from langchain chat modules. Now this submodule allows me to open or connect or call up the keys or open API keys from the open AI servers. Okay. So that is a class that is available chat openai that will allow me to create or contain my open AI tools. Then another thing that we need to put up lang chain.chain chains no conversation chain now what does that do it allows me to create a chain of conversations that means suppose if I ask one question there's an answer given then I can ask a probing question further so that allows me to remember the previous task as well in context with the current conversation it allows me to create a conversation chain rather than one question one answer and stops instead of that allows 4:58:31 me to repeat things on a simultaneous basis lang chainmemory that allows me to remember the buffer memory. It allows me to remember my previous conversation. Suppose I have started with one conversation and then I want to continue with another conversation. My previous conversation can be saved and used it can be reloaded. OS I'm using for very generic purpose to create environment variables. If you want to create envir environment variables otherwise it's your choice if you can avoid OS as well if you're not using environment variables. So first thing is to set up your open API API key securely. So for that I'm creating a variable open AI API key and I'm putting that into my streamlet secrets. Now where are these streamllet secrets right? So these are typically stored in a TML file. I'll just show that. So that will be in your default folder where your anaconda is installed. You 4:59:32 will have a dot streamllet folder. You need to go into that and install will be in default user account. Inside that you will find a under streamllet folder you can find there is a file by the name secrets. ML. If it is there you can put it up. If it is not there, you need to create a new text document like this. Inside this, I've just opened it up. You need to write down anything. I have used a word open AI API key is equal to and you need to mention within quotes your API key whatever you're using it up here and save this document. save as and you go to this place, select all files and save this document as secret tl. So that allows you to take your key into or transmit it into your network or transmit it to your model with encryption. So that can be saved 5:00:33 up. So you can just need to save that file. I have already done that secrets.tml. This file contains my API key, right? I already have that file here. So that allows me to tell it streaml go to the secrets and find open API key if it is available in open secrets if it is available in there else you can get it from the environment variable or else otherwise you can create up here OS environment those who do not want to use that you can put up osenviron and create up the same variable by the name open this is an optional Okay. So open API key and you can mention is equal to port your API key whatever you want to use your open AI API key 5:01:34 that should work. So I'll put a comment. This is an optional thing right we'll get this this thing work I have put this again in statement this is for the purpose of else os dot get environment open key so if we do not have a key available in secrets it will try to fetch it from the environment all right now we need to initialize our lm model how do we initialize my lm model lm is equal to chat openai that's the name of the function that will connect me to openi servers OpenAI API key is equal to open AI API key. I have kept my API key. If you do not have anything else available, just write down your open AI key directly here. You don't have to create anything at all. Right? You can paste it up directly here as well. That will expose your open AI key and you may not want to expose that securely. Then the temperature, it's the amount of randomness that we want. Now what does that mean? It means how much randomly generic answers I want to 5:02:36 create. the temperature part. Higher the number, more is the randomness I'm trying to bring into my answers. The bigger the temperature value is, the better your answers would be. Okay. Lastly, the model name. Based upon your access to OpenAI API, you would be able to access either some of the models. I able to access GPD4 or many model. I mentioned that model. If you're able to access GPT4, you can just mention GPD4 or whichever model you have an access or 3.5 turbo depending upon your access you can use that particular model. After we have initialized the LLM part, we will move on to the next part where I'll set up the memory part. Now what is that memory part? In this on my streamllet platform I just wanted to make sure if there is any previous memory available it should be able to bring that memory for me. If it is not available I'll start my find session from a new piece. So I have created a variable memory if memory not 5:03:37 in session state right dot session state. Assertion state is a variable that creates my value and I'm looking for memory but if there would be any memory this flag will be true whether it will be false. So if memory not in session state if it is not present I want to create a memory s that I can assign a memory value to it using conversation buffer memory. So whatever memory that we have I'll start with that memory. So that will blank at the moment. Then I'll start my conversation. Now this function conversation chain it actually allows me to create the chain of conversation. The model that I'm going to use is LLM model. The memory is the current memory state that is blank currently blank. So as soon as we keep on moving the memory states gets on updated verbos will try to make sure that if there is any kind of warnings or something in between these are not being displayed that verbose false that ensures that part. So we do not see any 5:04:38 warnings or anything. Apart from that now we need to design the interface that's the model lm model part dot we will design our interface st set page config so whatever the web browser page that I'm going to design I want to put the title as llm chatbot page icon if you want to put something let's say put up anything you can put up a gif image or whatsoever you want if I can have hey you can leave it I'm writing down and simply I do not have that small little images right now. So you can put a page icon like this. Then title now this title will appear up in the center of your page right on the first page on your screen. The lang chain chatbot by simply learn. Okay. So that will appear up in there. Now we will now use the same place that will create my interface. That means I'll get a web page whose title will be lm chatbot. page icon will look like 5:05:39 simply lands name written on that title would be lang chain chatbot by simply that will appear up somewhere in the center of my screen then I'll put up a blank box to receive user input so user input is equal to the name of the function is st text input st is my streaml library in text input I'm asking this part to display asking you to it to display the word u followed by key is equal to input so it will display up a box and the key input will be displayed up within the box. So you get to know that here I have to put in the input value. Then if I get a user input my response is conversation which is my conversation chain model that we have created here conversation.predict the user input. So based upon the input that I give it will create up a response. Once it gets the response, I will add to the memory to the chat memory. So session state memory dot chat memory dot add user message 5:06:42 predefined function. So I'll put up user input and add AI message as response. I have added two functions there and then I'm writing up the response. So I'm putting up now on my screen st.right is going to put my response. So I'm writing down a formatted string with a markdown language of bot that will appear in bold and the response. So whatever the response from LLM model that is came up that will be printed up here at the last I'm putting up this is an optional thing completely optional wherein I'm trying to tell you if you want to see the previous histories you can put that up by doing this how so there is a checkbox I'm creating if ST do checkbox show chart history that will be displayed in front of it there will be checkbox so if I select it this becomes true if I do not select it that remains false for message in ST state memory chat memory messages. I'll try to see see I have added user messages and 5:07:43 AI messages. So that is available in my session state memory chat memory right. So I'll go to session state memory chat memory and I want to recollect all messages. So I'll retrieve all messages from there and I'll put up what the role this particular U if message type is human else bot and I'll put down the entire content. So that's what will be printed out on my screen. That completes your entire LLM creation part. Let's try to work around this. Now for this you need to save this file as chatbot py. Once you have done this, open up your terminal. I'll open up a terminal that is nothing but my Windows terminal, PowerShell terminal. And I'll run this command by putting up streamllet space run space name of my Python script. So it's chatbot. py that is my Python script. When I execute this, 5:08:44 I press enter key on my keyboard and say that you can now see your streamllet app. I'll just show you this. You can now view your streamllet app. It's starting up the app on the back end. But I'll just show you here on your browser. So that has already opened up a app on my browser. I'll show you that. But it says that local URL HTTP localhost 8505 and my network URL is this. So it has gotten an IP address URL as well. I can use either one of those. But if I go to my web browser and see it says that my window title of I show you. You see that llm chatbot here. That's my title on the top. Put up I don't I had an emoji to come up but that did not came up last but you can see here lang chain chatbot by simply lang. That's what I put up here. That's the name and it has a context box of view and I have a box to write down. I have a show chart history option. Let's try to search how 5:09:47 what is or let's say today's news I'll win champions league 2025. Now that's a very generic question. I'm pressing enter to apply. If everything is good, my API is running, I would get an answer. It says I cannot predict the future. So I don't know who will win the Champions League 2025. The tournament is filled with so many talented teams and anything can happen in football. So you can ask me any you can ask put up any questions. If you don't like can put up a new question here. Tell me the names depending upon how much availability of all participating. So depending upon your prompt you can read up. So it tells me does not know that in the top teams from various leagues including Premier League, La Liga, Sira, 5:10:48 Bundesliga and League One along with some lesserk known leagues compete for a spot. So you can see the some team names that can be there. Essentially you can also see below. So show chat history. If I put that on you can look at all the things that has been done in this particular you can see my chat history is available. So that can be viewed. I removed that show chat history. The chat history will be part again depending upon the machine that you're using. It is running on my local server. So depending upon hardware it might be slow or fast. That is how you can do it. The next option that you can do is to deploy this. In order to deploy this, you need to go on to deploy option. You have multiple choices available like you can go on stream with community cloud, you can go on snowflake or you can deploy on your custom platforms. If I want to go on community cloud, I can click on deploy. Now I need to access to my GitHub account. 5:11:50 I need to put this code onto GitHub and then I can deploy. That can be discussed in a separate session. all together. So that would be it everyone and I would really like you to think of questions and answers. If you have something put them up into your comment section and we'll definitely respond to it. Thank you very much. Today we are going to explore K nearest neighbors or KN&N which is one of the most popular algorithms in data science. Python is a powerful tool for data science and KN&N is great for classifying data by predicting the category of sample base on its closest neighbor. This algorithms is used in many field like healthcare, finance and agriculture helping us make decision based on data. The best part it is really easy to use. You just need to pick a number for K and choose a distance function to compare data points. However, KN&N has it downsides. It doesn't work well with the large data set and it require proper scaling of the 5:12:51 data to get accurate result. In this video, we will show you how cann work with real data set the data set. We'll walk you through simple Python code and demonstrate how to find the best key value to maximize your model's accuracy. So stay tuned to seekn in action. So welcome to the demo part. So I'm here using Google collab. So you can use any of your favorite ID like Jupyter notebook, Intelligi, Visual Code Studio, anything. Okay. So let me rename this file as KNN classification. Okay, cool. So let me tell you that KN&N can be used for the classification, regression, predictive problems. So KN falls in the supervised learning family of algorithms. Okay. So we will measure the distance between the K neighbors and the first step will be we will choose the number of K of neighbors. Then uh we'll take the K nearest neighbors of 5:13:52 the new data point according to your distance metric. And the step three will be our among these case neighbors count the number of data points of each category. Okay. Step four we will assign the new data points to the category where you counted the most neighbors. Okay. So let's start. First let's import some library. import numpy as np and let's import pandas sp. So everyone knows what is numpy and the pandas. Okay. So numpy is a library for the python programming language adding support for uh you know large multi-dimensional arrays. Okay. along with the large collection of uh what to say uh highlevel mathematical functions and various pandas is a software library written for the Python programming language for the data manipulation and analysis uh all the data frames and uh data structures it offers for the manipulating numerical 5:14:52 tables okay and the time series you can see so moving forward uh we'll import our data set so you can download the data set from the description box below okay data that equals to pb dot read csv the data name is iris dot csv okay this is how you read uh your data in python okay yeah data set is loaded so data set dot shape shape okay yeah so data uh set dotshape is used for how many numbers of uh rows and columns present in your data set. Okay, 150 rows and six columns. So let me tell you brief about data set this data set. So I data set include three ID species with uh 50 samples each as well as some properties about each flower. So 5:15:54 one flower species is linearly separable from the other two you can say but the other two are not linearly separable from each other. Okay. And this shape I told you we can get a quick idea of how many instances of rows and columns are present in our data set. So let's see our data set data set dot head. So head is used for uh you know by you can see top five rows of your data set using head and if you will use tail you instead of head you can see the last five rows of your data set. Cool. Okay. So columns are ID sample length sample width petal length petal width and the species. Cool. Then moving forward let's describe our data sets. So these are the basics uh basic function. Okay. of Python you can say. So data set.escribed what describes do 5:16:54 is it will give you count of all the rows. Mean value, standard deviation value, minimum value, what is the 25% okay of all the values in the particular row. What is the 50%? What is the 75%? What is the maximum? Maximum is 150 you can say. Okay. and 25% of 150 is 38.25 25 this okay of all the columns if it is normal uh you know character so it won't give you any data okay cool yeah so moving forward uh let's now take a look at the number of instances row belong to each classes okay so we will write data set dot group by species dot size. Okay. Uh S is capital that's why it's showing the error. Yeah. So you can see Iris Satossa 5:17:55 are 50, Iris verical are 50 and virginica is 50. Okay. And the data type type is integer. Cool. So as you can see data set contains six columns like ID, sample length, sample width and petal length, petal width and spaces. The actual features are described by columns 1 to four. the last columns labels or samples. Okay. So firstly we need to split data into two arrays like X features and Y labels. So how we will do this? By writing code like feature columns equals to sele width petal length petal width. Just remember you are writing correct name. Okay. Then x = to data set feature columns. Okay. Dot values. Then y = to 5:18:57 data set species dot values. Cool. Then let me run it. So this is uh how we can split the data set okay into two arrays X and the Y. Okay. In X there are feature columns. These four columns are there and in Y species column is there. Okay. And what is the species column this satossa venica and all this. Cool. Then now we will do label encoding. So as you can see labels are categorical. Kmer classifier does not accept string labels. So we need to use label encoder to transform them into numbers. Okay. Then iris satossa correspond to zero. Iris vericy color correspond to one and I is virginica correspond to two. Okay. 012. Cool. So how can that from skarn dot pre-processing 5:19:57 import label encoder okay so what we'll do label encoder transform them into numbers okay so I will write l equals to label encoder okay my bad label encoder. Okay. Then y = to ele alate transform y. Okay. So now I will run it. Yeah. Correct. So splitting data set into training set and the test set now. Okay. So now we'll split data set into training set and test set to check later on whether or not a classifier work correctly or not. Okay. So here I will write from skarn dot not cross. I will write here skarn domodel selection import import train test split. So what is train test split? Train test split is a 5:20:57 model validation procedure that reveals how your model performs on your new data. Okay. And what is x train access y train y test in python. Okay. Let me first write it and then I will let you know. Okay. Then I will write here x train comma x test comma y train comma y test. Okay train test split then x comma y comma test size 0.2 and the random is this. Okay. Okay. Some error came. Okay. Underscore model selection. Yeah. Cool. So what is X train X test? Y train Y test. Okay. So X train and Y train sets are used for training and fitting the model. Okay. So the X test 5:21:59 and the Y test are the set used for testing the model and it's predicting the right outputs level. Okay. So here you can see test size is 0.2. into means 80% is for testing or sorry 80% is for training and 20% is for testing for the new data. Cool. Yeah. So now we will see some uh let's do some data visualization. Okay. So here I will write import mattplot lib dotpipplot as plt then import cb as sns then here I will write person mattplot lib in line. So what is mattplot lib? Mattplot lib is a plotting library for the python programming language and it's numerical mathematic extension. Okay. So numpy it provides an object API for 5:23:01 embedding plots into application using generating purpose GUI toolkits like kintter and python or gtk. Okay. Whereas seaborn seaborn is a library for making statical graph in python. It builds on the top of mattplot lip and integrates closely with pandas data structure. Okay, seborn helps us to explore and understand the data. Okay, so I will run it here. I will write from pandas dot plotting import parallel coordinates. Then plt dot figure size should be 15, 10. Okay. Then parallel coordinates. 5:24:03 Okay. Then data set dot drop. I don't need id, x is one. Okay. then comma spaces then plt dot title and let parallel coordinates plot okay and you can give some font size equals to 20 then font weight equals to okay Let's add bold only bold then plt dot x label then features comma font size to 15 then plt 5:25:04 dot y label then I'll write here features values comma font size equals to 15. Okay. then plt dot legend then loc = to 1 comma I will already have frame on equals to true comma shadow equals to true comma face color equals to white should be capital and comma edge color equals to 5:26:04 okay plt dot show okay some error is there plt dot figure size okay spelling mistake Take. Okay. One more error. PLT. Legend. Okay. Face color. Okay. Some spelling stick. So yeah, let me make it output in full screen. Yeah. So parallel coordinates is a plotting technique for plotting you know multivariate data. So it allows one to see clusters in the data and to estimate other stat visually. So using parallel coordinate points uh you know are represented as the connected line segments as you can see. Okay. And each vertical line represent one attribute and one set of connected line segments represent one data point. Okay. And points that tend to cluster will appear closer together. Okay. So this uh this color is iris satossa and this is irisy 5:27:08 color and this burpa one is iris virginica as you can see in the legend. Okay, cool. So moving forward let's create another graph and curves. Okay so here I will write from p and dotplotting import scatter. Oh, this uh plotting import Andreo curves. Okay, then plt dot figure. It's AI based. So it's giving me suggestions. Suggestions. Suggestions. Okay. So sometimes suggestions are good but not always. Yeah. Let's carry on. Figure size is 15, 10. Then Andrew C then I will add data set dot drop id access spaces and plt and c plot. Okay fine. Okay, let me add we don't need X 5:28:13 label and all. Let me add legend plot legend. Then same LOC equals to 1. Then proposition size. Then I will write here size is 15 of frame on equals to two comma shadow equals to true. So this is uh totally based upon you if you want to add legend or not or you can skip. If you want to skip you can skip. Okay. Face color equals to white. Then edge color equals to black. Okay. Then plt dot show. Yeah. So no error is there. So let me first view out put in full screen. Okay. 5:29:15 So Andrew curves these are the endoc curves. Okay. You can see the graph in the curve. So and curve allow one to plot multivariate data as a large number of curves. So that are created using the attributes of samples okay as coefficient for 4 year series. Okay. So by coloring these curves differently for each class it is possible to visualize data clustering. So curves belongs belonging to samples of the same class will usually be closer together and they form large structure. Okay. As you can see here and this is the legend why we are setting the four color is should be white and yeah and the edge color should be black okay and frame on shadow should be there you can see the shadow okay like this if you want to skip you can skip this part legend legend part okay but like it's good to have it's good practice to have this cool so let's 5:30:15 create one small pair plot okay so I will write here plt dot dot figure then I will write SNS dot pair plot then I will write data set dot drop we'll drop again id we don't need comma xis is one then I will write u equals to species size equals to three. Then markers equals to O SD. Yeah. Cool. Then plt dot show. It's running. Yeah. So first let me make it to full screen. Yeah. So here pair wise is useful when you want to visualize the distribution of the variable or the relationship between the 5:31:15 multiple variable separately within subsets of your data set. Okay. So here this blue one is stoa verol and the virginica. Okay. So these are some uh graph you can say or here you can see sample length. Okay. So green one is virginica and versol are almost having same saple length. Okay. And here are the different types of graphs. Okay. If you don't want to uh let's say if you don't know how to read this graph you can use this graph or you can use this graph. Either you can use this graph. Okay. That's the power of pair pair wise plots you can say. And the sample width cm. Okay. Satossa. No. Okay, virginica and vertical again having almost same sample width. Okay, and here as well. Okay, this stoa is in different form. Okay. Yeah. So, we'll create one small 5:32:18 uh pair of u one small graph then we'll move forward. Okay. Uh I will write here plt dot. So, now we are creating box plot figure. Okay. Then data set dot drop. Then again ID commais should be one dot box plot. Okay. Then figure size I chose this. Yeah. Let's run it. Yeah. Again see this is the box plot. Petal length same petal weight sample length sle width. Okay. According to width it is showing like from this to this width we have the veric color and from this to this width this length sorry sample length we have uh that virginica lies here Iris virginica and from here to here iristosa lies okay the sample cool and like you can use 3D models you can 5:33:22 use different types of charts okay I did four and four are enough to uh read the data set. Okay. So now we will do uh some cannon classification. Okay. We will make prediction and we will see the accuracy of our data set. Okay. So now what I will do? I will write here from skarn dot neighbors import k neighbors. Okay. write from skarn dot neighbors import k neighbor classifier. Okay. Then I will write here from skarn dot matrix import 5:34:22 confusion matrix comma accuracy accuracy score. Okay, then I will write from skarn dot model selection import cross value score. Okay, so here what we I did uh we are fitting the classifier to the training set and loading the libraries basically. Okay, then we'll initiate a learning model K equals to three. Okay. So here I will write classifier. Let me give one space. Classifier equals to neighbors. Classifier and neighbors three. Okay. Then fitting the model. I will write here classifier 5:35:24 dot fit x train, y train. Okay. Then uh now we will predicting the test uh test set results. Okay. So y prediction equals to classifier dot predict x test. Cool. Okay. From Okay. Spelling mistake. Okay. Okay. Yeah. I guess it's fine now. So now uh let's evaluate the prediction. So here I will uh build the confusion matrix. Okay. So here I will write cm confusion matrix equals to confusion matrix 5:36:25 uh y test y prediction. Okay. Then here I will write cm. Okay. So what is confusion matrix basically? So I confusion matrix uh you know is a table that shows how well a model performs by comparing its prediction to the actual values. Okay. So what it show is a confusion uh matric displays the number of correct and incorrect prediction of each class in models whose either it can give you true positive true negative false positive false negative either it can give you zero or one. Okay. So yeah moving forward let's calculate the model accuracy. This is the main part. If the model accuracy is low it means uh your analysis of you know classification is not good. Okay. So accuracy it should be more than 80 at least. accuracy equals to accuracy score 5:37:26 y test comma y prediction into 100 otherwise it will give me in points so I will write print model canon model accuracy is oh I will write plus STR I will round it. Okay. Accuracy 5:37:59 I will add the person. So why I wrote this accuracy to round? So I don't want after points I need only two numbers. Okay. I don't want like 6 7 8 9 10 11 12 like this. Okay. I need only like 80.20 like this. Cool. Let's run this. see KN&N model accuracy is 96.67 67 that's why I wrote two here and the percent should be there. So 96 which is very very very good. Okay. So this is how you can find uh the accuracy. So now let's find the optimal number of neighbors in K. Okay. Basically finding the best K. So we will use uh using cross validation parameter. Okay. Tuning. So first I will create the list of K for KN. Okay. So here I will write k list equals to list range 1 comma 50A 2. 5:39:00 Here I'm I will create the list of CV score. Okay. So here I will write CV scores. Okay. Okay. I have to give brackets. Yeah. So we'll here perform the 10fold cross validation. Okay, I will explain you what is cross validation. Don't worry. So first let me write for K N K list KNN equals to K neighbor classifier and here I will add N neighbor neighbors equals to K then scores to cross value code KNN then X train Y train okay 5:40:02 I will write here cross validation equals to 10 comma scoring equals to I will write here accuracy okay and then here CV course dot append and to course dome. Okay. So now yeah let me run it. Okay some error came. Okay the error is the scoring parameter. Yeah why? Because here accuracy you can see and I did the spelling mistake. Okay. So now what is cross validation? Of course, cross validation uh you know determine the accuracy of your machine learning model by partitioning the data into two different groups. Okay, called training set and testing set. You can see train test and the testing set. Okay, X and Y. So the data is randomly 5:41:03 separated into a certain number of groups or subsets called folds. Okay, you can see the 10 folds we have wrote. Each fold contains about the same amount of Okay, and there is one more thing validation. So, validation is a technique for assessing the accuracy of the model on data set. Okay. And this cross validation we did on new data set. Cool. So, now let's find the best K. Okay. So, here I will write best K equals to K list. Okay. Before that I will write one thing. I will write here MSE will change into mclassification error. Okay. So equals to one that's X for X in for X in CV scores. Okay. list I will write MSE dot index 5:42:04 minimum MSE I will use this bracket square bracket okay so and I will write print the best optimal number of neighbors is percent D person best K. Okay, let's run it. See the best optimal number of neighbors. Okay, N neighbors is 9. Okay, so in the K nearest neighbor KN algorithms, okay, so K represent the number of neighbors that are considered when classifying a query point. Okay. See these if we will classify this particular point you will get the six. Okay. 1 2 3 4 5 6. Okay. And uh let me show you. If you will 5:43:06 classify this portion only. So you will get 1 2 3 4 5 6 points like this. Okay. So the best optimal number of neighbor is nine. So what are confusion matrices and why do we need them? So in machine learning classification is used to divide data into different categories. But after we have clean, prepared the data and trained our model, how we can tell if the model is performing well. So there is where confusion metrics come in handy. So a confusion metric is a tool that helps measure the performance of a classifier in detail. It goes beyond just giving an overall accuracy score. It shows exactly where the model is making mistake and how it is classifying each category. For example, if there is an imbalance in the data where one category has many more instances than other, the model might predict the majority category most of the time and still show a high accuracy. But this wouldn't be helpful because the model is not accurately predicting the minority categories. The confusion matrix help 5:44:07 visualize these outcome by showing a table of all the predicted and the actual values allowing use to see where the model is performing well and where it needs improvement. So moving forward let's see confusion matrices parts or how to create 2x2 matrix. So we can get four different outcomes when comparing the predict actual values from a classifier. The first one is true positive. This is when the model correctly predicts a positive outcome. You predicted positive and it was actually positive. The second one is false positive. This happens when the model incorrectly predicts a positive outcome for something that is actually negative or a predictive positive but it was actually negative. The third one true negative. This is when the model correctly predicts a negative outcome. You predicted negative and it was actually negative. And the fourth one false negative. This occurs when the model incorrectly predicts a negative outcome for something that is actually 5:45:07 positive Q predictive negative and but it was actually positive. So moving forward let's see some matrices of confusion matrix. So this is a graph. So we know there are four parts. True positive, false positive, false negative and true negative. So this one is true positive. This one is false positive. This one is false negative. This one is true negative. So just consider a confusion matrix made for a classifier that classify people based on whether they speaks English or they speak Spanish. Okay. From this diagram you can see that fine. So these are some values TP, FN, FP, TN. There is nothing too positive, two negative like this. Just from looking at the matrix the performance of a model is not very clear. So to find out how accurate our model is, we use the following matrices. The first one is accuracy. So this is the formula of accuracy. TP means true positive means this 86 value. 5:46:11 So the accuracy is used to find the portion of correctly classified values. It tells us how often our classifier is right. It is the sum of all the true values divided by total values. So in this case this is 88%. Okay, 86 + 79 2 positive plus 2 negative divided by this it will come 88.23. Okay. And the second one is precision. So precision is used to calculate the model ability to classify positive value correctly. It is the true positive divided by the total number of predicted positive value. So this is the formula. It is true positive divided by true positive plus false positive. So in this case the value will come 87.75%. Okay. And the third one is recall. So recall is used to calculate the model's ability to predict positive values. How often does the model predict the correct positive values? So it is true positives divided by the total number of actual positive values. So in this case the 5:47:13 value is 88.93. Okay. And the last one is f_sub_1 score. So it is the harmonic mean of recall and precision. It is useful when you need to take both precision and recall into an account. So in this case the value is 88.77%. So now let's jump into the demo part and see how we can get these values accuracy precision recall and F1 score from our data set using hands. So I'm performing this in Google Collab. So first I will rename it to confusion matrix. Okay. So yes let's start. So first we will import some basic libraries of python like numpy and the pandas. So here I will like import numpy as np and import pandas as pd. Why I'm writing this np and pd? because I don't want to write again and again numpy and pandas. Okay, 5:48:14 this is a short form np. So everyone knows I guess numpy and pandas because these are the basic library. So numpy is used for mostly linear algebra stuff and pandas is used for the creating data frames, data processing or if you want to read files, CSV files like that. Okay. Yeah. So now let's import our data. Okay. So data equals to pd dot read csv then file name data dot csv. So I will upload this file on the description box below. You guys can check out from there. Okay. Yes. So let okay what is saying? No such file or direct on data or CSV. I guess it's there. Okay, it's not. Let me import it. Okay. Yeah. 5:49:15 Okay. Now file is there. Yeah, it's working fine. So now let's check. Okay. Five rows. Yeah. So this is our data. You can see we have columns with data dot columns. Okay. So we have this 32 columns in our data set. ID, diagnosis, radius means, texture means, parameter mean. So I just simply you know took this data. There is nothing related to confusion matrix and all. Okay. We have to just we can perform you know confusion matrix to you know any data. So head is used for displaying top five rows of of our data set. Okay. If I will write data simply you can see the full data. Okay. With 33 columns and all the rows. Right. So uh now we don't need this 5:50:18 ID and one is this unnamed data because there is no values. Okay. So what I will do I will write data dot drop id comma okay let me copy it because I don't want any spelling mistake yeah copy paste here okay let me write ais equ= to 1 then comma in is equals to true. Okay, let me run it. Okay, if you will check data dot head now I guess there will be no ID and all. See there is now no ID and all. Okay, this we remove that large column as well and name 32. 5:51:18 Okay. So now what I have to do I will write here data dot diagnosis equals to 1 if each was equals to m. Okay. as zero for each in data dot diagnosis. Diagnosis. Yeah. So if you can see there is mm value and there is you know other values as well. So for M I am putting one for for the rest I will put zero. Okay. Let's check again. Yeah. Okay. You can see it's done. 5:52:21 Replacement is done basically. Okay. So let's check the info of the data. So these are some basic uh what to say functions of Python. So these are the column these are the non null values these are the data values okay float we have or int we have okay so we have only two t type of data sets so now what we will do we will do normalization okay y equals to data dot diagnosis diagnosis dot values okay so here I will write X data equals data dot drop diagnosis comma access equals to 1. 5:53:23 Okay, here I will write x equals to x data minus np dot minimum value and the x data and divided by so I'm put using that formula if you guys know okay divided by np So I'm basically what I'm finding is accuracy. Okay, I'm using that formula. NP dot max of X data then minus NP dot min value then X data. Okay. Okay. Um, okay. Access value is wrong. 5:54:26 Sorry, spelling is wrong. Now fine. Yes, it's fine. So now we will do train test split. So what is train test split? Okay. So uh first let me route selection import train test split. Okay. So what is train test split? So what we do we you know split our data set into training and the testing. Mostly we train and the some part of data we test. Okay. So here I will set the ratio. So x train comma x test 5:55:26 comma y train comma y test equals to train test split. Then x comma y comma test size equals to 0.15 means 85% we are on the training and uh 15% we are on the testing part. Okay, random state equals to 42. Okay, let me run it. It's working fine. Yeah, it's working fine. So now let's see the accuracy from the random forest. So I will write from skarn dot and symbol 5:56:27 import random random forest classifier. Okay. Then RF equals to random forest classifier and n estimators equals to 100 and here I will set random state to one. Okay. Then RF this is a short form of random forest dot fit fit x train comma y train then print random forest score rf dot score 5:57:27 then xers _ test comma y test. Okay. And now let's check how much the accuracy. So accuracy is coming 95%. Okay. Which is very good. So now what I will do? I will create confus confusion matrix. Y prediction equals to RF dot predict X test. Okay. Then Y true equals to Y test. Okay. So here now let's create the array skarn dot matrix 5:58:27 import confusion matrix. Okay. Then I will write cm short form of confusion metric. Here I will write y true comm, y prediction then confusion matrix. So this is our array. Okay. the true positive and this is false negative and this is false positive like this. Okay. So now let's create the visualization of confusion matrix. Okay. So here I'll write import seabborn as SNS and import mattplot lib dot piplot 5:59:29 as plt. plt means plot. Okay the short form f comma ax = to plt dot subplots. Let's give the figure size equals to 5A 5 then SNS dot heat map then confusion matrix comma node equals to true then comma line width equals to 0.5 five comma line color equals to let's give red then fmt equals to 6:00:30 I don't need any you know uh that decimal values comma ax = to x okay then pl dot x label y prediction then plt dot y label then y true add okay forgot to add this braces then plt dot Show. Yeah. So as you can see this is the Y true values and this is the Y prediction values. Okay. This is the heat map you have created. So this is how you can visualize your confusion matrix. Fine. Stable diffusion. One of the most advanced AI tools for generating 6:01:30 stunning photorealistic images from just text. Whether you are describing a vibrant sunset, a futuristic city, or a sural dreamscape, stable diffusion can turn your imagination into reality within seconds. The latest version, stable diffusion XL, brings even higher quality results thanks to a larger network and improved techniques. Not only you can generate images, but you can also enhance them with features like in painting, where you can edit parts of an image or outpainting, which expand image beyond its original borders. So, how does it works? The AI starts by breaking down an image into noise, then cleverly reverse that process to recreate a clear and detailed picture. We will also show you how to create effective prompts to get the best result from stable diffusion. Whether you're using web- based version or running it on your own computer and yes, you can even use it for commercial purposes. Stick around because I will be giving you a live demo and showing you step by step how to create your own images with 6:02:31 this powerful tool. So without any further ado, let's get started. So hello guys, welcome back to the demo part of the stable diffusion. So first we will I will open stability AI. Okay. So this is the artificial intelligence company which launched stable diffusion text to image generator. Okay. So we have multiple models in this. Okay. So we have image model, we have video model, audio 3D languages. Okay. Let's go to this image models. Yes. So we have two series SD3 series and SD XL series. SD3 large is there. Tur large turbo is there. SD3 medium is there. in SD XL see stable diffusion XL is there, SDXL turbo is there and Japanese stable diffusion XL is there. So there are two ways of using stable diffusion. The first is you 6:03:35 can install the stable diffusion locally and you can use it but there are some requirements you should have on your system. Okay, just like there should be you know uh GPU should be there, graphic card, Nvidia graphic card should be there or another graphic card will be fine, right? So here you can uh you know use the API or you can get the license or you can download the code. Okay, or you can read about this table if you use Excel. Yeah, right. So I will show you how to download and install this stable diffuser. For a while I don't have any graphic card on my system. Okay. So I can't use but I will show you properly how to use and how to run it. So first step I will give you this link. Okay. This is the hugging face. So here SDXL is you know their recently 6:04:38 launched model. Okay. So here you can uh read it about all the configuration or you want okay how you can install. So first you have to install Python. Okay. First you have to install Python latest version. And then second you have to install after installing Python you have to install git not get copilot just get bash okay this you have to install windows either Mac OS or Linux okay so here what you have to do I will give you this link and you have to go to files and version and you have to download this one sdxl LP 1.0 this one or you have to download it. So see I have already downloaded it. Okay. So this file is all around 6.5 GB. 6:05:40 Okay. For a while I'm canceling it because as you can see here I already downloaded. Okay. So after downloading this you have to go to you know you have to write stable web UI stable diffusion web UI. Okay I will give you this link as well. Okay here what you have to do you have to go here and download zip file. Okay again zip file is there but again let me download it for you. Okay, this is done. Okay, after that what you have to do, you have to unzip this stable diffusion. Okay, then this folder will come. Okay, then you have to go down and here you can see web UI UI user for Windows batch file. You have to run this batch file. Okay, if you're you Mac 6:06:40 user, you can uh run this shell script. Okay, so I will install this. I have already installed but you have to just double click this and everything will be installed. Okay, so it will launch one page after installing this. It will take like half an hour because it will download multiple files of 4455 GB. Okay, for a while. Let me run it. See this page will come. So as you can see here I am running stable diffusion locally 127.0 this. Okay this is local. So here so now we downloaded first file right? If you remember we downloaded this file. So what you have to do you have to go to downloads then you have to copy this file downloaded file then you go you have to go here here you have to go to 6:07:41 models then here you have to disable diffusion then you can copy paste here your file okay so these are the models so this is the latest models okay it will install with v15 prune model but we want to use latest model. Okay. So that's why we are copying it. Okay. So while installing it will show you some these type of things here. It will download multiple things right. So after installing this just refphase and you can see two models are there. Okay. You can select either. Okay. I'm selecting this here. So I will write astronaut riding horse but it will give me error. Okay I it will write generate. So what error is coming? See found no Nvidia driver on your system. Okay I don't have 6:08:41 any drivers installed in my system. I don't have any graphic card. But if you have graphic card it will run smoothly. It will give you all the outputs. But again we can use this stable diffusion online as well web. Okay here see stable diffusion 2.1 demo. I will give you this link as well. Okay. So let me write again then the same thing as not riding horse generate image. So it will take 11 second as it is showing. You have to wait. Okay. It's scanning. Almost done processing. See astronaut riding horse. Okay. Okay. Let's go to charg and ask some funny give me some funny 6:09:47 text to image generators prompts. Okay. So let's get okay a carriering chef at a taping. This one is cool. Okay. Let's copy this and paste it here. Okay, let's read. A penguin dressed as a pirate searching for treasure on a ice flow with a parrot that only squawks. Okay, see pirate hat. See pirate hat. Okay, let's try something else. A robot trying to blend at a grumpy beer sitting in a therapist of Okay, this one is cool, I guess. Okay, let me run it again. It will take some 11 seconds. But 6:10:48 this, you know, if you run locally, this will work definitely. I'm sure. Okay, because in other than my system, it's running smoothly. See a grumpy beer sitting in a therapist office discussing its feeling about something. See sitting this one. So this is how you can use a staple diffusion. Okay. Locally and using web right this is better than DAL because DAL is again expensive. Today we are exploring hugging face an amazing tool that makes working with language and AI super easy. If you're curious about using advanced technology to understand or create text, this video is perfect for you. Hugging phase is a company that helps people use AI models for language tasks like translation, text analysis, or even generating new text. They have created a library called transformer which comes with pre-trained models. So you don't have to build everything from scratch. 6:11:49 It's simple, powerful, and perfect for developers, researchers, or even beginner. So in this video I will show you three cool things you can do with hugging face speech to text. Turn spoken words into written text easily. Great for captions or voice apps. Second one is sentiment analysis. Find out if a text is positive, negative or neutral. Helpful for understanding reviews or comments. The third one is text generation. Create humanlike text that sounds natural. Perfect for chat bots or creative writing. I will also explain some important basics like how pipelines make using hugging face model super easy and how tokenization helps AI understand text. By end of this video, you will know how to use hugging face to start building your own projects. It's simple, fun and really powerful. So without any further ado, let's get started. So welcome to this demo part of this video. So here as you know we will be doing three things. First thing speech to text 6:12:49 recognition. The second thing text generation from a particular sentence or a word. And the third thing we will do sentiment analysis. Okay. So we will perform this one by one. So let's start with something called speech to text recognition. Okay. Using hugging face. So first I will write rename this. I will write here hugging face. speech to text. Okay. Yeah. So, first I will install transformers library. It is already installed on my system. But again, just for you guys I'm doing this. Okay. PIP install transformer. So now let's see what is transformers. So transformers is a powerful Python library created by hugging face. So that allows you to download, manipulate and run thousands of pre-trained open-source 6:13:51 AI model. Fine. So as you can see requirement already satisfied. It means like already installed. So these transformer models cover multiple task across you know modities like NLP, natural language processing, computer vision, audio and multimodel learning like many things. Fine. So now I will do from transformers import pipeline. Okay. So now let's run it. So now what is pipeline? Okay. So a transformer pipeline describes the flow of data from origin system to destination system. Fine. because you already know transformer means you can run or manipulate thousands of pre-trained opensource AI model. So pipeline describes the flow of data from origin system to destination system and defines how to transform you 6:14:52 the data along the way. Okay. So let's check the versions transform mer 6:15:11 version. Okay that long tab. Okay. Why it is coming? Import transformers. Yeah. So we have currently 4.42.4 version of the transformer. Okay. So I'm using Google Collab. Okay. So you can use either Jupyter notebook, Visual Code Studio or Collab. Okay. So now let's import libraries. import librosa. Okay. So what is librosa? So librosa is a python package for audio and music analysis. Right? Because we are doing speech to text. So we need this. So it provides various functions to quickly extract key audio features and metrics from the audio files. 6:16:11 Okay. And this librosa can also be used to analyze and manipulate audio files in a variety of formats such as wav, mp3, m4a and like that. Okay. So next we will import torch. I hope everyone know torch. So torch is nothing pytorch. It is a machine learning library based on the torch library used for applications such as computer vision and NLP and originally it was developed by the meta and now the part of Linux foundation you know umbrella let's import one more thing import so now let's import IPython Okay. Capital ipython dot display 6:17:14 as display. So now you will be wondering what is this IPython display. Okay. So it is an interactive command line uh for the terminal for Python and it uh you know it can provide a IPython terminal and the web-based notebook platform for Python computing and this uh IPython have you know more advanced features than the Python standard interpreter and we quickly execute a single line of Python code nothing okay for that I'm using this and the Next is from transformers import wav to vectorizer for CTC and WAV 6:18:15 to vectorizer to tokenizer. Okay. So now what is this? So WA2 vectorizer for CTC is supported by the notebook on how to fine-tune a speech recognition model. Okay. And this tokenizer. So tokenizer is nothing tokenization is a conversion of a text into meaningful lexical tokens belonging to categories defined lexa program. in case of NLP. So those categories include nouns, verbs, adjective, punctuation, etc. Okay. Now, and the last library, let's import numpy, s np. I hope everyone know numpy. What is numpy? Again, numpy is a python library used for working with arrays. It al it also has a function you know for working in domain like linear algebra 6:19:15 fer transform and matrices and many others fine I hope everyone know about these library which we have imported okay so let's move forward by tokenizer go to to see to tokenizer dot from pre-trained. This is why I love this Google collab. You'll decide just some words and it will show the suggestions you know Facebook. So this is again one pre uh trained model. Okay. So we are just importing it base 6:20:16 960th. This is nothing the name. Okay. Then model equals to WAV2 for CTC dot from retrained then Facebook WV2 vectorizer 2 then base 96 fine. Now let's run it. So now you can see so we are loading this okay they're downloading okay so you can ignore these warning so now let's load the audio file so here I will write audio 6:21:16 sampling rate equals to librosa dot load. Okay. So you know about libroser, right? Then I have v dot m4 a. So we I have already one speech or one audio you can say. So I will play it. Don't worry. before the final output I will you know show you 16,000 okay so now I will write okay okay already loaded I guess okay 6:22:18 okay no issues I will load again. Okay, the file is loaded. I will rename it to V. Yeah, fine. So now it won't there won't come again. We have V.MP4. Okay. So now what we have to do? Okay, let me try it. We have V.M. MP4A. But I don't know why it is not coming. Okay, let me copy the path. And now it will run. I guess it's running. Yeah. So now I will write 6:23:21 here audio, comma, sampling rate. Okay. Now listen carefully. Then I will write display display dot audio. Then path comma comma auto play equals to true. Okay. Hello and welcome. This is an AI voice message. I guess you heard but again let me play it again. Hello and welcome. This is an AI voice message. Okay. So it is saying hello and welcome. This is an AI voice message. Fine. So 6:24:22 now what I will do? I will input some values. Input values equals tokenizer then audio comma return tensors equals to pt fine dot input values. Okay. Then here input values. Okay. Input values. Okay. Yeah. So now logits will come here. So we have to now store the logits which means non-normalized predictions. Okay. 6:25:23 So logits equals to model input values dot logits. Okay. Then here I'll write logits. Okay. It's running. Done. So now what we will do? We will store predicted ids. Then we will pass the logits to values to softmax to get the predictive value. Okay. So here I will write predicted ids equals torch dot arg max. Okay. Then logit dimension equals to minus one. Okay. Then I will pass the you know 6:26:24 prediction uh to the tokenizer decode to the transcription. Okay. So here I will write transcriptions equals to tokenizer tokenizer dot decode predicted ids zero running fine. So now let's see our output transcriptions. So now you can see hello and welcome. This is an AI voice voice message. So now let's play it again. Hello and welcome. This is an AI voice message. Amazing right? So this is how you can use hugging face for this piece to text recognition. It's a very small code line of code as you can see. Okay. So now 6:27:26 let's move forward and do the sentiment analysis. Okay. Or text generation. So let me open new drive. So yeah. So now I will write here. I will write sentiment slash text generation hugging face. Okay. So first of all let's import the files. So first I'll write import warnings then warnings dot filter warnings okay I will write here ignore then we'll import numpy you already know what is numpy and 6:28:28 import panda so these are some bas basic uh Python library and I hope everyone knows and import mattplot li for the plots mattplot lib dot piplot as plt then I will import cbond for the graphs the statistics graph okay SNS then SNS dot set. So now we'll import skarn model train split. So skarn is nothing scikitlearn is a probably the most useful library for machine learning python. So, so this uh library contains a lot of efficient tools for machine learning and you know statical modeling including classification you can do regression you can do clustering you can do from this 6:29:28 escal okay from skarn dot model selection Import import train test split from SQL dot matrix import f1 Comma confusion matrix comma ro Aore. So again we will import from 6:30:29 transformers import pipeline. Everyone know what is this? Then import torch. Okay. Now let's run it. You have too many active session. Terminate existing to continue. If you're interesting using more session. Okay. Wait. Yeah. Fine. Now which one is open, bro? Terminate this. Terminate this. Terminate this. Okay. Fine. So now let's do sentiment analysis. So uh we will explore sentiment analysis using a pre-trained transform model. Okay. The hugging face library provides you know convenient pipeline as you already know function that allows us to 6:31:29 easily perform sentiment on the text. So now let's first import the necessary dependencies and create a sentiments pipeline using this line. So I will write here classifier equals to pipeline sentiment analysis. then type classifier. Okay. So it will download the pre-trained sentiment analysis pipeline. Pipeline is not defined. How? Okay. Okay. Error is there. I hope it will run now. Yeah. So now we can uh pass a single 6:32:31 sentence or a list of sentence to the classifier and now and get the predictive sentiment labels and associate confidence score. Fine. So now just for the testing classifier. So let's write this is a great movie. Okay, now let me run it. So now you can see here label positive. So label positive typically refers to the outcome or a class of interest that the model is designed to predict. So here we are just checking the sentiment analysis model. Okay. So this is why I wrote this. Okay. So let's check one more. 6:33:33 This was a great course. Then I did not understood any of it. Now let's check this. Yeah, perfect. And the score you can see the accuracy score 99%, 99%, which is almost close to 100%. And which is amazing. So now you have access to a GPU. So you can also utilize this for the faster processing by specifying the device using the parameter. Okay. So now what I will do first I will okay wait. Yeah fine. So now I will 6:34:33 import data set airline tweets equals to PD dot read. PD means pandas library here we are using. Okay. Now first import I will import here itself. So I have twitter dot tweets dot csv. Okay. Tweets dot CSV. Let it upload. Yeah. Done. So now let me airline tweets. Y dot head means you it will show me the top five rows. Okay. 0 1 2 3 4 5. Okay. You can see tweet a line sentiment neutral 6:35:35 positive neutral negative. Then this is this this. Okay. So now let's do something. Okay. So what I will do df equal df means data frame a line to its then I will write a line sentiment we have airline sentiment this column okay text I need these two columns again df do head five. So yeah, air a cime neutral and this is what this text is all about. Okay, because these two are the main things text and the sentiment. So now let's make plot count plot 6:36:38 then I will write df comma x = to a line sentiment then p validate equals to is then here I will write plt dot x label a line sentiment. Okay. Then plt dot variable count plt do. So it will draw one graph. Okay. Okay. Spelling is wrong. 6:37:41 Yeah. So it will show neutral positive sentiment and the negative. So as you can see the negative sentences or the sentiments are the more. Okay. So now so we have now three classes which do not match the two class available in the hugging face pipeline. So therefore we will filter out all the rows which have been labeled as neutral. Okay. So, DF equals to DF and again DF airline sentiment fine was not equals to neutral. Okay. Then DF target equals to DF airline sentiment 6:38:42 dot uh map then I will write here positive positive 1 and the negative find negative will be zero. Okay. Then print number of rows comma df dot shape. Okay. So now you can see number of rows are 11,541. Okay. So now I will write predictions five 6:39:43 it will okay predictions is not defined. Okay. So now what I will do? So here I will write text= to TF text text and to list dot to list then here I will add predictions equals to classifier text. Okay. So here write probabilities equals to predictions then score. If predictions label dot 6:40:44 starts with starts with P means positive. Okay. else 1 minus prediction score prediction score okay then I will write for prediction and prediction why it is not running this is taking time too much time I don't know why So as you can see finally we have the output predictions values. So this depends on you know system. So system my system took almost 17 minutes 47 seconds to complete. Okay. So now let's run it. Okay. Predictions is now defined. Now 6:41:47 predictions. Yeah. So now I will write here predictions equals to np dot array. np means numpy numpy dot array then I will write one if prediction label is positive dot starts with p. Okay. else zero for prediction and prediction values. Yep. Okay. Fine. So now let's check the accuracy of our model. Branch 6:42:47 accuracy. Okay, then I will do round up the values. So here I will write np dot mean then df then the target right? Yeah. Then I will write equals equals to predictions. Then I will write into 100 comma two. Then I will write percentage. Okay. Fine. Looks good. Yes. So as you can see our accuracy is 88.99% which is you know very good again. So now let's do some confusion matrix 6:43:49 confusion matrix then TF target predictions comma normalize equals to true. Okay. Then I will plot confusion matrix. Okay. DF then target comma predictions comma normalize equals to true. Okay. Okay. My bad. My bad. My bad. 6:44:50 that confusion matrix comma labels. Okay. So here uh I will you know plot a confusion matrix using cbond. Okay. So here I will use args which is confusion matrix np array. So which is you know labels list. So I will write plt dot figure then figure size equals to 8 comma 6 that's sn dot set font scale equals to 1.4. Okay. Then let's create the heat map 6:45:54 fusion matrix comma and not will be true. Okay. Then I will write fmpt equals to g then confusion map equals to blues. Then X labels equals to labels. Then Y labels equals to labels. Okay. Yes. So now I'll write plt dot title will be confusion matrix 6:46:54 then plt dox label will be predicted values then plt doy label will be actual values then plt dot show. Okay. Why the chart is not coming? Okay. So I have to write plot confusion matrix then write cm then negative comma positive. Okay. Now the chart will come. Okay. 6:47:58 Yeah. So now you can see here this is you know actual and this is a confusion matrix and the negative and the positive ratio is there. Okay. So now let's print the let's check the ROC score. So I will write here print ro A score then here I will write OC A score then TF target props. Okay. So 94. Okay. So first let me tell you what is this ROC AC score. So this is the area under the ROC curve. So what it does it sum up how well a model can 6:49:00 produce relative scores to discriminate between positive and the negative instance across all the classification threshold. So with this ROC score of 940.94 which is 94% we can conclude that the that a pre-trained sentiment analysis model has achieved the high level of accuracy and effectiveness. So in predicting the sentiment labels so this indicates that the model is capable of accurately classifying text into positive or the negative sentiment categories. Okay. So now we'll do text generation. Okay. So text generation involves generating creative and coherent text based thing. So I will write here text. Okay. So text generation involves generating creative and coherent text based on a given prompt or starting point. So what we will do first? We will import the necessary dependencies and load the data data set of the poem. Okay. So here I am 6:50:01 write poems. Let me write poems equals to PD read CSV. Don't worry, I will give you these files. Okay, description box below I will add. So here I will write robot frost with dot CSC. Fine. And then I will write poems dot head five or head just have to write it module pandas has okay not doc csv yeah okay it will show the top five stopping by woods on a snowy evening fire and ice the aim was song collection content, year of publish. 6:51:02 Okay. So now what we will do? We will write content equals to poems 6:51:21 content dot drop na to to list. Okay. So to generate text we extract individual lines from the poems and use the pipeline text generation function to create a text generation pipeline. Fine. So here I will write lines equals to then I will write for poem and content. Okay. For line and poem dot split into the next line. Okay. Then lines dot append. Then I will add line dot write strip 6:52:24 to the right. It will add. Okay. Fine. So now lines equals to line for line in lines. If length of line zero then show me the lines five. Okay. So now you have seen here whose words these are I think I know. Then the next line his house is in the village though the next line he will not sing. Okay. Like this. So now let's uh you know import that pipeline text generation module. Okay. Gen equals to pipeline. 6:53:26 So these are the some pre-trained model you already know generation. Okay. So now I will write here lines. Let's run it. Yeah, so in line zero you have we have whose votes these are. I think I know. Okay. So now we can now generate text by providing a prompt and specifying the parameters such as max length and num return sequence. Okay. Why? Because we have imported this tag generation module. Okay. For example, see gen. Okay, sorry. Lines zero dot max length 6:54:27 max length equals to 20. So now it will generate the this to the maximum 20. Okay. till 20 word maximum length. Okay. Check. Okay. Uh okay. Expression cannot contain perhaps double equals to where okay now it will run. So see the line was this much only. Whose words these are? I think I know. Whose words these are? I think I know. But here the generated text I wish to go to church because I feel like okay this is how you can do you know text generation. Now let's check for the more gen lines 1. Okay. Then max length equals to 30, 6:55:30 num return sequence says sequences equals to two. Okay. So our first line was this. His house is in the village though. Okay. 0 1 2 3 4 5. Okay. So here you can see see his house in the village though. However you might say that the place was the same with the place this this this. So these are the generated text. Okay. And this is another you know return sequence second. So there are two one and the second. Okay. So now let me you know import text. Okay. Then creating function wrap x. I don't need this. 6:56:34 Then return text wrap dot fill x comma replace y space wide space equals to false comma uh fix sentence endings equals to true. Okay. So now out equals to generated lines zero to maximum length equals to 30. 6:57:36 Then print wrap out to zero. Then generated text. Okay. So now we are setting uh the P tokens to EOS tokens. Okay. So whose these are I think I know. And this is the maximum 30 till 30. Okay. So now I will write here okay preview equals to okay. So now what you can do you can you know generate a prompt to generate text on a specific topic like this prompt equals to transformers have a wide variety 6:58:37 of applications application in NLB B. Okay. So this is my prompt. Okay. This I'm not importing from the data set. Okay. So I will write out equals to gen prompt comma max length equals to 100. print wrap out. Okay, here I will write anyways here I will write generated text prompt. 6:59:39 Okay, so it is running. Let's wait. Yeah. So, okay. Somewhere is there. 7:00:11 Okay. So, here the issue is with 100 words I go with. We'll go till 50. Yeah. So let me do it again. 100. Yeah. So now you can see we have we can generate text using by giving a prompt. So we have covered you know three topics in this. First thing is piece to text using hugging face. Second thing is sentiment analysis using hugging face. And the third is text generation using hugging face. Okay. And in this text generation we have we did with two methods. One with the data set and second thing with the you know by giving prompt like in charge you can say. Hello and welcome to this tutorial on deep learning. My name is Moan and in the next about one one and a half hours I will take you through what is deep learning and into tensorflow environment 7:01:13 to show you an example of deep learning. Now there are several applications of deep learning really very interesting and innovative applications and one of them is identifying the geographic location based on a picture. And how does this work? The way it works is pretty much we train an artificial neural network with millions of images which are tagged. Their geoloccation is tagged and then when we feed a new picture, it will be able to identify the geoloccation of this new image. For example, you have all these images especially with maybe some significant monuments or or u significant locations and you train with millions of such images and then when you feed another image it need not be exactly one of those that you have trained. It can be completely different. That is the whole idea of training. It will be able to recognize for example that this is a picture from Paris because it is able to recognize the Eiffel Tower. So the way 7:02:16 it works internally if we have to look a little bit under the hood is these images are nothing but this is digital information in the form of pixels. So each image could be a certain size. It can be 256 x 256 pixel kind of a resolution and then each pixel is either having a certain grade of color and all that is fed into the neural network and it then gets trained in and it's able to based on these pixels pixel information it is able to get trained and able to recognize the features and extract the features and thereby it is able to identif ify these images and the location of these images and then when you feed a new image it kind of based on the training it will be able to figure out where this images from. So that's the way a little bit under the hood how it works. So what are we going to do in this tutorial? We will see what is deep 7:03:17 learning and what do we need for deep learning and one of the main components of deep learning is neural network. So we will see what is neural network what is a perceptron and how to implement logic gates like and or nor and so on using perceptrons the different types of neural networks and then applications of deep learning and we will also see how neural networks works. So how do we do the training of neural networks and at the end we will end up with a small demo code which will take you through in TensorFlow. Now in order to implement deep learning code there are multiple libraries or development environments that are available and TensorFlow is one of them. So the focus at the end of this would be on how to use TensorFlow to write a piece of code using Python as a programming language. And we will take up a an example which is a very common one which is like the hello world of 7:04:18 deep learning the handwriting number recognition which is a mnest commonly known as mnest database. So we will take a look at emnest database and how we can train a neural network to recognize handwritten numbers. So that's what you will see in this particular video. So let's get started. What is deep learning? Deep learning is like a subset of what is known as a highlevel concept called artificial intelligence. You must be already familiar must have heard about this term artificial intelligence. So artificial intelligence is like the highle concept if you will and in order to implement artificial intelligence applications we use what is known as machine learning. And within machine learning, a subset of machine learning is deep learning. Machine learning is a little bit more generic concept. And deep learning is one type of machine learning if you will. And we will see a 7:05:19 little later in maybe the following slides a little bit more in detail how deep learning is different from traditional machine learning. But to start with we can mention here that deep learning uses one of the differentiators between deep learning and traditional machine learning is that deep learning uses neural networks and we will talk about what are neural networks and how we can implement neural networks and so on and so forth as a part of this tutorial. So a little deeper into deep learning. Deep learning primarily involves working with complicated unstructured data. Compared to traditional machine learning where we normally use structured data in deep learning the data would be primarily images or voice or maybe text file. So and it is large amount of data as well. And deep learning can handle complex operations. It involves complex operations. And the other difference between traditional machine learning and deep learning is that the feature extraction happens pretty much 7:06:20 automatically. In traditional machine learning, feature engineering is done manually. The data scientists, we data scientists have to do feature engineering, feature extraction. But in deep learning that happens automatically and of course deep learning for large amounts of data, complicated unstructured data, deep learning gives very good performance. Now as I mentioned one of the secret sources of deep learning is neural networks. Let's see what neural networks is. Neural networks is based on our biological neurons. The whole concept of deep learning and artificial intelligence is based on human brain and human brain consists of billions of tiny stuff called neurons. And this is how a biological neuron looks. And this is how an artificial neuron looks. So neural networks is like a simulation of our human brain. Human brain has billions of 7:07:24 biological neurons and we are trying to simulate the human brain using artificial neurons. This is how a biological neuron looks. It has dendrites and the corresponding component with an artificial neural network is or an artificial neuron are the inputs. They receive the inputs through dendrites and then there is the cell nucleus which is basically the processing unit in a way. So in artificial neuron also there is a piece which is an equivalent of this cell nucleus and based on the weights and biases. We will see what exactly weights and biases are as we move the input gets processed and that results in an output. In a biological neuron the output is sent through a synapse and in an artificial neuron there is an equivalent of that in the form of an output. And biological neurons are also interconnected. So there are billions of neurons which are interconnected. In the same way artificial neurons are also 7:08:25 interconnected. So this output of this neuron will be fed as an input to another neuron and so on. Now in neural network one of the very basic units is a perceptron. So what is a perceptron? A perceptron can be considered as one of the fundamental units of neural networks. It can consist at least one neuron but sometimes it can be more than one neuron but you can create a perceptron with a single neuron and it can be used to perform certain functions. It can be used as a basic binary classifier. It can be trained to do some basic binary classification. And this is how a basic perceptron looks like. And this is nothing but a neuron. You have inputs x1, x2, x uh to xn and there is a summation function and then there is what is known as an activation function and based on this input what is known as the weighted sum. The 7:09:26 activation function either gets gives an output like a zero or a one. So we say the neuron is either activated or not. So that's the way it works. So you get the inputs. These inputs are each of the inputs are multiplied by a weight and there is a bias that gets added and that whole thing is fed to an activation function and then that results in an output. And if the output is correct, it is accepted. If it is wrong, if there is an error, then that error is fed back and the neuron then adjusts the weights and biases to give a new output and so on and so forth. So that's what is known as the training process of a neuron or a neural network. There's a concept called perceptron learning. So perceptron learning is again one of the very basic learning processes. The way it works is somewhat like this. So you have all these inputs like x1 to xn and each of these inputs is multiplied by a weight and then that sum this is the formula 7:10:27 the equation. So that sum wi xi sigma of that which is the sum of all these product of x and w is added up and then a bias is added to that. The bias is not dependent on the input but or the input values but the bias is common for one neuron. However, the bias value keeps changing during the training process. Once the training is completed, the values of these weights W1, W2 and so on and the value of the bias gets fixed. So that is basically the whole training process and that is what is known as the perceptron training. So the weights and biases keep changing till you get the accurate output and the summation is of course passed through the activation function. As you see here, this wixi summation plus B is passed through activation function and then the neuron gets either fired or not and based on 7:11:27 that there will be an output. That output is compared with the actual or expected value which is also known as labeled information. So this is the process of supervised learning. So the output is already known and um that is compared and thereby we know if there is an error or not and if there is an error the error is fed back and the weights and biases are updated accordingly till the error is reduced to the minimum. So this iterative process is known as perceptron learning or perceptron learning rule and this error needs to be minimized. So till the error is minimized this iteratively the weights and biases keep changing and that is what is the training process. So the whole idea is to update the weights and the bias of the perceptron till the error is minimized. The error need not be zero. The error may not ever reach 7:12:30 zero. But the idea is to keep changing these weights and bias so that the error is minimum. the minimum possible that it can have. So this whole process is an iterative process and this is the iteration continues till either the error is zero which is uh unlikely situation or it is the minimum possible within these given conditions. Now in 1943 two scientists Warren Melikch and Walter Pittz came up with an experiment where they were able to implement the logical functions like and or and nor using neurons and that was a significant breakthrough in a sense. So they were able to come up with the most common logical gates. they were able to implement some of the most common logical gates which could take two inputs like a and b and then give a corresponding result. So for example in 7:13:31 case of an andgate a and b and then the output is a b in case of an orgate it is a plus b and so on and so forth and they were able to do this using a single layer perceptron. Now most of these gates it was possible to use single layer perceptron except for XR and we will see why that is in a little bit. So this is how an AND gate works. The inputs A and B the output should be fired or the neuron should be fired only when both the inputs are one. So if you have 0 0 the output should be zero. For 0 1 it is again 0 1 0 again 0 and 1 one the output should be one. So how do we implement this with a neuron? So it was found that by changing the values of weights it is possible to achieve this logic. So for example if we have equal weights like 7.7 and then if we take the sum of the weighted product. So for example 7 into 0 and then 7 into 0 will 7:14:34 give you zero and so on and so forth. And in the last case when both the inputs are one you get a value which is greater than one which is the threshold. So only in this case the neuron gets activated and the output is there is an output. In all the other cases there is no output because the threshold value is one. So this is implementation of an AND gate using a single perceptron or a single neuron. Similarly an orgate. In order to implement an argate in case of an argate the output will be one if either of these inputs is one. So for example 01 will result in one or rather in all the cases it is one except for 0 0. So how do we implement this using a perceptron once again if you have a perceptron with weights for example 1.2. Now if you see here if in the first case when both are zero the output is zero. In the second case when it is 0 and 1 1.2 2 into 0 is 0 and then 1.2 into 1 is 1 and in the second case similarly the 7:15:34 output is 1.2 in the last case when both the inputs are one the output is 2.4. So during the training process these weights will keep changing and then at one point where the weights are equal to w1 is equal to 1.2 and w2 is equal to 1.2 the system learns that it gives the correct output. So that is implementation of orgate using a single neuron or a single layer perceptron. Now XR gate this was one of the challenging ones. They tried to implement an XR gate with a single level perceptron but it was not possible and therefore in order to implement an XR. So this was like a a roadblock in the progress of U neural network. However, subsequently they realized that this can be implemented. An XR gate can be implemented using a multi-level perceptron or MLP. So in this case there are two layers instead of a single layer. And this is how you 7:16:35 can implement an XR gate. So you will see that X1 and X2 are the inputs and there is a hidden layer and that's why it is denoted as H3 and H4. And then you take the output of that and feed it to the output at 05 and provide a threshold here. So we will see here that this is a numerical calculation. So the weights are in this case for X1 it is 20 and minus 20 and once again 20 and minus 20. So these inputs are fed into H3 and H4. So you'll see here for H3 the input is 0 1 1 and for H4 it is 1 0 1 1 and if you now look at the output final output where the threshold is taken as one if you use a sigmoid with the threshold one you will see that in these two cases it is zero and in the last two cases it is one. So this is the implementation of XR. In case of XR only when one of the 7:17:37 inputs is one you will get an output. So that is what we are seeing here. If we have either both the inputs are one or both the inputs are zero then the output should be zero. So that is what is an exclusive or gate. So it is exclusive because only one of the inputs should be one and then only you'll get an output of one which is satisfied by this condition. So this is a special implementation. An XR gate is a special implementation of a perceptron. Now that we got a good idea about perceptron, let's take a look at what is a neural network. So we have seen what is a perceptron, we have seen what is a neuron. So we will see what exactly is a neural network. So neural network is nothing but a network of these neurons and they are different types of neural networks. There are about five of them. These are artificial neural network, convolutional neural network, then recursive neural network or recurrent neural network, deep neural network and deep belief network. So, and each of these types of neural networks have a 7:18:39 special you know they can solve a special kind of problems. For example, convolutional neural networks are very good at performing image processing and image recognition and so on. Whereas RNN are very good for speech recognition and also text analysis and so on. So each type has some special characteristics and they can uh they are good at performing certain special kind of tasks. What are some of the applications of deep learning? Deep learning is today used extensively in gaming. You must have heard about Alph Go which is a game created by a startup called Deep Mind which got acquired by Google and Alph Go is an AI which defeated the human world champion Lee Sadal in this game of Go. So gaming is an area where deep learning is being extensively used and a lot of research happens in the area of gaming 7:19:39 as well. In addition to that nowadays there are neural networks of special type called generative adversarial networks which can be used for synthesizing either images or music or text and so on and they can be used to compose music. So the neural network can be trained to compose a certain kind of music and autonomous cars. You must be familiar with Google. Google's self-driving car and today a lot of automotive companies are investing in this space and uh deep learning is a core component of this autonomous cars. The cars are trained to recognize for example the road the the lane markings on the road signals any objects that are in front any obstruction and so on and so forth. So all this involves deep learning. So that's another major application and uh robots we have seen several robots including Sophia you may 7:20:39 be familiar with Sophia who was given a citizenship by Saudi Arabia and there are several such robots which are very humanlike and the underlying technology in many of these robots is deep learning. Medical diagnostics and health care is another major area where deep learning is being used. And within healthcare diagnostics again there are multiple areas where deep learning and image recognition image processing can be used. For example for cancer detection as you may be aware if cancer is detected early on it can be cured. And one of the challenges is in the availability of specialists who can diagnose cancer using these diagnostic images and various scans and and so on and so forth. So the idea is to train neural network to perform some of these activities so that the load on the cancer specialist doctors or oncologists 7:21:40 uh comes down and there is a lot of research happening here and there are already quite a few applications that are claimed to be performing better than human beings in this space. Can be lung cancer, it can be breast cancer and so on and so forth. So healthcare is a major area where deep learning is being applied. Let's take a look at the inner working of a neural network. So how does an artificial neural network let's say identify can we train a neural network to identify the shapes like squares and circles and triangles when these images are fed. So this is how it works. Any image is nothing but it is a digital information of the pixels. So in this particular case, let's say this is an image of 28x 28 pixel and this is an image of a square. There's a certain way in which the pixels are lit up. And so these pixels have a certain value maybe from 0 to 256 and 0 indicates that it is 7:22:45 black or it is dark and 256 indicates it is completely it is white or lit up. So that is like an indication or a measure of the how the pixels are lit up. And so this is an image is let's say consisting of information of 784 pixels. So all the information what is inside this image can be kind of compressed into these 784 pixels. The way each of these pixels is lit up provides information about what exactly is the image. So we can train neural networks to use that information and identify the images. So let's take a look how this works. So each neuron the value if it is close to one that means it is white whereas if it is close to zero that means it is black. Now this is a an animation of how this whole thing works. So these pixels one of the ways 7:23:47 of doing it is we can flatten this image and take this complete 784 pixels and feed that as input to our neural network. The neural network can consist of probably several layers. There can be a few hidden layers and then there is an input layer and an output layer. Now the input layer take these 784 pixels as input. The values of each of these pixels and then you get an output which can be of three types or three classes. One can be a square, a circle or a triangle. Now during the training process there will be initially obviously you feed this image and it will probably say it's a circle or it will say it's a triangle. So as a part of the training process, we then send that error back and the weights and the biases of these neurons are adjusted till it correctly identifies that this is a square. That is the whole training mechanism that happens out here. 7:24:49 Now let's take a look at a circle. Same way. So you feed these 784 pixels. There is a certain pattern in which the pixels are lit up and the neural network is trained to identify that pattern. And during the training process once again it would probably initially identify it incorrectly saying this is a square or a triangle and then that error is fed back and the weights and biases are adjusted finally till it finally gets the image correct. So that is the training process. So now we will take a look at same way a triangle. So now if you feed another image which is consisting of triangles. So this is the training process. Now we have trained our neural network to classify these images into a triangle or a circle and a square. So now this neural network can identify these three types of 7:25:52 objects. Now if you feed another image and it will be able to identify whether it's a square or a triangle or a circle. Now what is important to be observed is that when you feed a new image it is not necessary that the image or the the triangle is exactly in this position. Now the neural network actually identifies the patterns. So even if the triangle is let's say positioned here not exactly in the middle but maybe at the corner or in the side it would still identify that it is a triangle and that is the whole idea behind pattern recognition. So how does this training process work? This is a quick view of how the training process works. So we have seen that a neuron consists of inputs. It receives inputs and then there is a weighted sum which is nothing but this x i wi summation of that plus the bias and this is then fed to the 7:26:52 activation function and that in turn gives us a output. Now during the training process initially obviously when you feed these images when you send maybe a square it will identify it as a triangle and when you maybe feed a triangle it will identify as a square and so on. So that error information is fed back and initially these weights can be random. Maybe all of them have zero values and then it will slowly keep changing. So the as a part of the training process the values of these weights W1, W2 up to WN keep changing in such a way that towards the end of the training process it should be able to identify these images correctly. So till then the weights are adjusted and that is known as the training process. So and these weights are numeric values. It could be 0.5.25.35 and so on. It could be positive or it could be negative. And the value that is coming here is the pixel value as we have seen. It can be anything between 0 to 1. You can scale it between 0 to 1 or 7:27:56 0 to 256 whichever way 0 being black and 256 being white. And then all the other colors in between. So that is the input. So these are numerical values. this multiplication or the product wi xi is a numerical value and the bias is also a numerical value. We need to keep in mind that the bias is fixed for a neuron. It doesn't change with the inputs whereas the weights are one per input. So that is one important point to be noted. So but the bias also keeps changing. Initially it will again have a random value but as a part of the training process the weights the values of the weights W1 W2 WN and the value of B will change and ultimately once the training process is complete these values are fixed for this particular neuron W1 W2 up to WN and plus the value of the B is also fixed for this particular neuron and in this way there will be multiple neurons and each there may be multiple levels of neurons here and that's the 7:28:56 way the training process works. So this is another example of multilayer. So there are two hidden layers in between and then you have the input layer values coming from the input layer. Then it goes through multiple layers hidden layers and then there is an output layer. And as you can see there are weights and biases for each of these neurons in in each layer and all of them gets keeps changing during the training process. And at the end of the training process all these weights have a certain value and that is a trained model and those values will be fixed once the training is completed. All right. Then there is something known as activation function. Neural networks consists of uh one of the components in neural networks is activation function and every neuron has an activation function and there are different types of activation functions that are used. It could be a relu, it could be sigmoid and so on and so forth. And the activation function is what decides whether a neuron should be fired 7:29:58 or not. So whether the output should be zero or one is decided by the activation function and the activation function in turn takes the input which is the weighted sum. Remember we talked about wixi plus b. That weighted sum is fed as a input to the activation function and then the output can be either a zero or a one. And there are different types of activation functions which are covered in an earlier video you might want to watch. All right. So as a part of the training process we feed the inputs the labeled data or the training data and then it gives an output which is the predicted output by the network which we indicate as yhat and then there is a labeled data because we for supervised learning we already know what should be the output. So that is the actual output and in the initial process before the training is complete obviously there will be error. So that is measured by what is known as a cost function. So difference between the predicted output and the actual output is the error and 7:31:01 the cost function can be defined in different ways. There are different types of cost functions. So in this case it is like the average of the squares of the error. So and then all the errors are added which can sometimes be called as sum of squares sum of square errors or SSC and that is then fed as a feedback in what is known as backward propagation or back propagation and that helps in the network adjusting the weights and biases and so the weights and biases get updated till this value the error value or the cost function is minimum. Now there is a optimization technique which is used here called gradient descent optimization and this algorithm works in a way that the error which is the cost function needs to be minimized. So there's a lot of mathematics that goes behind this. For example, they find the uh local minima 7:32:02 and the global minima using the differentiation and so on and so forth. But the idea is this. So as a training process as the as the part of training the whole idea is to bring down the error which is like let's say this is the function the cost function at certain levels it is very high the cost value of the cost function or the output of the cost function is very high. So the weights have to be adjusted in such a way and also the bias of course that the cost function is minimized. So there is this optimization technique called gradient descent that is used and this is known as the learning rate. Now gradient descent you need to specify what should be the learning rate and the learning rate should be optimal because if you have a very high learning rate then the optimization will not converge because at some point it will cross over to the side. On the other hand, if you 7:33:02 have very low learning rate, then it might take forever to convert. So you need to come up with the optimum value of the learning rate. And once that is done using the gradient descent optimization, the error function is reduced and that's like the end of the training process. All right. So this is another view of gradient descent. So this is how it looks. This is your cost function. the output of the cost function and that has to be minimized using gradient descent algorithm and these are like the parameters and weight could be one of them. So initially we start with certain random values so cost will be high and then the weights keep changing and in such a way that the cost function needs to come down and at some point it may reach the minimum value and then it may increase. So that is where the gradient descent algorithm decides that okay it has reached the minimum value and it will kind of try to stay here. This is known as the global 7:34:05 minima. Now sometimes these curves may not be just for explanation purpose this has been drawn in a nice way but sometimes these curves can be pretty erratic. There can be some local minima here and then there is a peak and then and so on. So the whole idea of gradient descent optimization is to identify the global minima and to find the weights and the bias at that particular point. So that's what is gradient descent and then this is another example. So you can have these multiple local minima. So as you can see at this point when it is coming down it may appear like this is a minimum value but then it is not. This is actually the global minimum value and the gradient descent algorithm will make an effort to reach this level and not get stuck at this point. So the algorithm is already there and it knows how to identify this global minimum and that's what it does during the training process. Now in order to implement deep learning there are multiple platforms 7:35:06 and languages that are available but the most common platform nowadays is tensorflow and so that's the reason we have uh this tutorial we have created this tutorial for tensorflow. So we will take you through a quick demo of how to write a tensorflow code using python and tensorflow is uh an opensource platform created by Google. So let's just take a look at the details of TensorFlow. And so this is a a library a Python library. So you can use Python or any other languages. It's also supported in other languages like Java and R and so on. But Python is the most common language that is used. So it is a library for developing deep learning applications especially using neural networks and it consists of primarily two parts if you will. So one is the tensors and then the other is the graphs or the flow. That's the way the name that's the reason for this kind of a name called tensorflow. 7:36:08 So what are tensors? Tensors are like multi-dimensional arrays if you will. That's one way of looking at it. So usually you have a one-dimensional array. So first of all you can have what is known as a scalar which means a number. And then you have a one-dimensional array something like this which means this is like a set of numbers. So that is a one-dimensional array. Then you can have a two-dimensional array which is like a matrix and beyond that sometimes it gets difficult. So this is a three-dimensional array. But TensorFlow can handle many more dimensions. So it can have multi-dimensional arrays. That is the strength of TensorFlow and which makes computation deep learning computation much faster and that's the reason why TensorFlow is used for developing deep learning applications. So TensorFlow is a deep learning tool and this is the way it works. So the data basically flows in the form of tensors and the way the programming works as well is that you first create a 7:37:10 graph of how to execute it and then you actually execute that particular graph in the form of what is known as a session. We will see this in the TensorFlow code as we move forward. So all the data is managed or manipulated in tensors and then the processing happens using this graphs. There are certain terms called like for example ranks of a tensor. The rank of a tensor is like a dimensional dimensionality in a way. So for example if it is scalar so there is just a number just one number. The rank is supposed to be zero and then it can be a one-dimensional vector in which case the rank is supposed to be one and then you can have a two-dimensional vector typically like a matrix. then in that case we say the rank is two and then if it is a three-dimensional array then it rank is three and so on. So it can have more than three as well. So it is possible 7:38:11 that you can store multi-dimensional arrays in the form of tensors. So what are some of the properties of tensorflow? I think today it is one of the most popular platform. TensorFlow is the most popular deep learning platform or library. It is open source. So developed by Google, developed and maintained by Google, but it is open source. One of the most important things about TensorFlow is that it can run on CPUs as well as GPUs. GPU is a graphical processing unit just like CPU is central processing unit. Now in earlier days GPU was used for primarily for graphics and that's how the name has come and one of the reasons is that it cannot perform generic activities very efficiently like CPU but it can perform iterative actions or computations extremely fast and much faster than a CPU. So they are really good for computational activities and in 7:39:11 deep learning there is a lot of iterative computation that happens. So in the form of matrix multiplication and so on. So GPUs are very well suited for this kind of computation and TensorFlow supports both GPU as well as CPU. And there's a certain way of writing code in TensorFlow. We will see as we go into the code. And of course, TensorFlow can be used for traditional machine learning as well. But then that would be an overkill. But just for understanding, it may be a good idea to start writing code for a normal machine learning use case so that you get a hang of how TensorFlow code works and then you can move into neural networks. So that is um just a suggestion but if you're already familiar with how TensorFlow works then probably yeah you can go straight into the neural networks part. So in this tutorial we will take the use case of recognizing handwritten digits. This is like a hello world of deep learning. And 7:40:12 this is a nice little emnest database is a nice little database that has images of handwritten digits nicely formatted because very often in deep learning and neural networks. We end up spending a lot of time in preparing the data for training. And with MNEST database, we can avoid that. you already have the data in the right format which can be directly used for training and MNEST also offers a bunch of built-in utility functions that we can straight away use and call those functions without worrying about writing our own functions and that's one of the reasons why MNEST database is very popular for training purposes initially when people want to learn about deep learning and TensorFlow this is the database that is used and it has a collection of 70,000 handwritten digits and a large part of them are for training. Then you have test just like 7:41:13 in any machine learning process and then you have validation and all of them are labeled. So you have the images and their label and these images they look somewhat like this. So they are handwritten images collected from a lot of individuals. People have these are samples written by human beings. They have handwritten these numbers. These numbers going from 0 to 9. So people have written these numbers and then the images of those have been taken and formatted in such a way that it is very easy to handle. So that is MNEST database and the way we are going to implement this in our TensorFlow is we will feed this data especially the training data along with the label information and uh the data is basically these images are stored in the form of the pixel information as we have seen in one of the previous slides. All the images are nothing but these are pixels. 7:42:13 So an image is nothing but an arrangement of pixels and the value of the pixel either it is lit up or it is not or in somewhere in between. That's how the images are stored and that is how they are fed into the neural network and for training. Once the network is trained when you provide a new image it will be able to identify within a certain error of course and for this we will use one of the simpler neural network configurations called softmax and for simplicity what we will do is we will flatten these pixels. So instead of taking them in a two-dimensional arrangement we just flatten them out. So for example, it starts from here. It is a 28x 28. So there are 784 pixels. So pixel number one starts here. It goes all the way up to 28. Then 29 starts here and goes up to 56 and so on. And the pixel number 784 is here. So we 7:43:14 take all these pixels, flatten them out and feed them like one single line into our neural network. And this is a what is known as a softmax layer. What it does is once it is trained it will be able to identify what digit this is. So there are in this output layer there are 10 neurons each signifying a digit and at any given point of time when you feed an image only one of these 10 neurons gets activated. So for example, if this is trained properly and if you feed a number nine like this, then this particular neuron gets activated. So you get an output from this neuron. Let me just use uh a pen or a laser to show you here. Okay. So you're feeding a number nine. Let's say this has been trained. And now if you're feeding a number nine, this will get activated. Now let's say 7:44:16 you feed one to the trained network then this neuron will get activated. If you feed two this neuron will get activated and so on. I hope you get the idea. So this is one type of a neural network or an activation function known as softmax layer. So that's what we will be using here. This is one of the simpler ones for quick and easy understanding. So this is how the code would look. We will go into our lab environment in the cloud and uh we will show you there directly but very quickly this is how the code looks and uh let me run you through briefly here and then we will go into the Jupyter notebook where the actual code is and we will run that as well. So as a first step first of all we are using Python here and that's why the syntax of the language is Python and the first step is to import the TensorFlow library. So and we do this by using this line of code saying import tensorflow as 7:45:17 TF. TF is just for convenience. So you can name give any name and once you do this TF is TensorFlow is available as an object in the name of TF and then you can run its uh methods and accesses its attributes and so on and so forth and MNEST database is actually an integral part of TensorFlow and that's again another reason why we as a first step we always use this example MNEST database example. So you just simply import mnest database as well using this line of code and you slightly modify this so that the labels are in this format what is known as one hot true which means that the label information is stored like an array and uh let me just uh use pen to show what exactly it is. So when you do this one hot true what happens is each label is stored in the form of an array of 10 digits and let's say the number is 7:46:19 uh 8. Okay. So in this case all the remaining values there will be a bunch of zeros. So this is like array at position zero. This is at position one position two and so on and so forth. Let's say this is position 7. Then this is position 8 that will be one because our input is 8 and again position 9 will be zero. Okay. So one hot encoding this one hot encoding true will kind of load the data in such a way that the labels are in such a way that only one of the digits has a value of one and that indicates. So based on which digit is one we know what is the label. So in this case the eighth position is one. And therefore we know this sample data the value is 8. Similarly if you have a two here let's say then the labeled information will be somewhat like this. So you have your labels. So you have this as zero. The zeroth position the 7:47:20 first position is also zero. The second position is one because this indicates number two. And then you have third as zero and so on. Okay. So that is the significance of this one hot true. All right. And then we can check how the data is uh looking by displaying the the data. And as I mentioned earlier, this is pretty much in the form of digital form like numbers. So all these are like pixel values. So you will not really see an image in this format. But there is a way to visualize that image. I will show you in a bit. And uh this tells you how many images are there in each set. So the training there are 55,000 images in training and in the test set there are 10,000 and then validation there are 5,000. So altogether there are 70,000 images. All right. So let's uh move on and we can view the actual image by uh using the mattplot clip library. And 7:48:22 this is how you can view this is the code for viewing the images. And you can view them in color or you can view them in grayscale. So the cap is what tells in what way we want to view it. And what are the maximum values and the minimum values of the pixel values. So these are the max and minimum values. So of the pixel values. So maximum is one because this is a scaled value. So one means it is uh white and uh zero means it is black and in between is it can be anywhere in between black and white. And the way to train the model there is a certain way in which you write your TensorFlow code and um the first step is to create some placeholders and then you create a model. In this case, we will use the softmax model, one of the simplest ones. And um placeholders are primarily to get the data from outside into the neural network. So this is a very common mechanism that is used. And 7:49:24 uh then of course you will have variables which are your remember these are your weights and biases. So for in our case there are 10 neurons and uh each neuron actually has 784 because each neuron takes all the inputs. So if we go back to our slide here actually every neuron takes all the 784 inputs right this is the first neuron it has it receives all the 784. This is the second neuron. This also receives all the 7. So each of these inputs needs to be multiplied with the weight. And that's what we are talking about here. So these are this is a a matrix of 784 values for each of the neurons. And uh so it is like a 10x 784 matrix because there are 10 neurons and uh similarly there are biases. Now remember I mentioned bias is only one per neuron. 7:50:24 So it is not one per input unlike the weights. So therefore there are only 10 biases because there are only 10 neurons in this case. So that is what we are creating a variable for biases. So this is uh something little new in tensorflow you will see unlike our regular programming languages where everything is a variable. Here the variables can be of three different types. You have placeholders which are primarily used for feeding data. You have variables which can change during the course of computation. And then a third type which is not shown here are constants. So these are like fixed numbers. All right. So in a regular programming language you may have everything as variables or at the most variables and constants. But in TensorFlow you have three different types placeholders, variables and constants. And then you create what is known as a graph. So TensorFlow programming consists of graphs and tensors as I mentioned earlier. So this can be considered ultimately as a tensor 7:51:24 and then the graph tells how to execute the whole implementation. So that the execution is stored in the form of a graph. And in this case what we are doing is we are doing a multiplication. TF you remember this TF was created as a TensorFlow object here. One more level one more. So TF is available here. Now, TensorFlow has what is known as a matrix multiplication or MATML function. So, that is what is being used here in this case. So, we are using the matrix multiplication of TensorFlow so that you multiply your input values X with W. Right? This is what we were doing. XW plus B. You're just adding B. And this is in very similar to one of the earlier slides where we saw sigma xi wi. So that's what we are doing here. Matrix multiplication is multiplying all the input values with the corresponding weights and then adding the bias. So that is the graph we created. And then 7:52:25 we need to define what is our loss function and what is our optimizer. So in this case we again use the tensorflow's APIs. So tf.n NN softmax cross entropy with logits is the uh API that we will use and reduce mean is what is like the mechanism whereby which says that you reduce the error and optimizer for doing deduction of the error. What optimizer are we using? So we are using gradient descent optimizer. We discussed about this in couple of slides uh earlier. And for that you need to specify the learning rate. You remember we saw that there was a a slide somewhat like this and then you define what should be the learning rate. How fast you need to come down. That is the learning rate and this again needs to be tested and tried and to find out the optimum level of this learning rate. It shouldn't be very high in which case it 7:53:26 will not converge or shouldn't be very low because it will in that case it will take very long. So you define the optimizer and then you call the method minimize for that optimizer and that will kickstart the training process and so far we've been creating the graph and in order to actually execute that graph we create what is known as a session and then we run that session and once the training is completed we specify how many times how many iterations we want it to run. So for example in this case we are saying thousand steps. So that is a exit strategy in a way. So you specify the exit condition. So a training will run for thousand iterations. And once that is done we can then evaluate the model using some of the techniques shown here. So let us get into the code quickly and see how it works. So this is our cloud environment. Now you can install TensorFlow on your local machine as well. I'm showing this demo on our 7:54:29 existing cloud but you can also install TensorFlow on your local machine and uh there is a separate video on how to set up your TensorFlow environment. You can watch that if you want to install your local environment or you can go for other any cloud service like for example Google cloud, Amazon or cloud labs any of these you can use and uh run and try the code. Okay. So it has got started. We will log in. All right. So this is our deep learning tutorial uh code and uh this is our TensorFlow environment and uh so let's get started. The first we have seen a little bit of a code walk through uh in the slides as well. Now you will see the actual code in action. So the first thing we need to do is 7:55:29 import tensorflow and then we will import the data and we need to adjust the data in such a way that the one hot is encoding is set to true one hot encoding right as I explained earlier. So in this case the label values will be shown appropriately. And if we just check what is the type of the data. So you can see that this is a uh data sets python data sets. And if we check the number of images the way it looks. So this is how it looks. It is an array of type float 32. Similarly, the number if you want to see what is the number of training images, there are uh 55,000 then there are test images 10,000 and then validation images 5,000. Now let's take a quick look at the data itself visualization. So we will use um mattplot lip for this. And um if we take a look at the shape now shape gives us 7:56:31 like the dimension of the tensors or or or the arrays if you will. So in this case the training data set if we sees the size of the training data set using the method shape it says there are 55,000 and 55,000 by 784. So remember this 784 is nothing but the 28x 28 28 into 28. So that is equal to 784. So that's what it is uh showing. Now we can take just uh one image and just see what is the the first image and see what is the shape. So again size obviously it is only 784. Similarly you can look at the image itself the data of the first image itself. So this is how it it shows. So large part of it will probably be zeros because as you can imagine in the image only certain areas are written rest is uh blank. So that's why you will mostly see zeros either it is black or white but then there are these values are so 7:57:31 the values are actually they are scaled so the values are between zero and one okay so this is what you're seeing so certain locations there are some values and then other locations there are zeros so that is how the data is stored and loaded if we want to actually see what is the value of the handwritten image If you want to view it, this is how you view it. So you create like do this reshape and um mattplot lib has this um feature to show you these images. So we will actually use the function called um im show and then if you pass this parameters appropriately you will be able to see the different images. Now I can change the values in this position. So which image we are looking at right? So we can say if I want to see what is there in maybe 5,000 right? So 7:58:32 5,000 has three similarly you can just say five what is in five five as 8 what is in 50 again eight. So basically, by the way, if you're wondering uh how I'm executing this code, shift enter. In case you're not familiar with Jupyter notebooks, shift enter is how you execute each cell, individual cell. And if you want to execute the entire program, you can go here and say run all. So that is how this code gets executed. And um here again we can check what is the maximum value and what is the minimum value of this pixel values. So as I mentioned this is it is scaled. So therefore it is between the values lie between 1 and zero. Now this is where we create our model. The first thing is to create the required placeholders and variables and that's what we are doing here as we have seen in the slides. So we create one 7:59:34 placeholder and we create two variables which is for the weights and biases. These two variables are actually matrices. So each variable has 784x 10 actual values. Okay. So one for this 10 is for each neuron. There are 10 neurons and 784 is for the pixel values inputs that are given which is 28 into 28. And the biases as I mentioned one for each neuron. So there will be 10 biases. they are stored in a variable by the name B. And this is the graph which is basically the multiplication of these matrix multiplication of X into W and then the bias is added for each of the neurons and the whole idea is to minimize the error. So let me just execute. I think this code is executed. Then we define what is our the Y- value is basically the label value. So this is another 8:00:35 placeholder. We had x as one placeholder and y true as a second placeholder. And this will have values in the form of uh 10digit 10digit uh arrays. And uh since we said one hot encoded the position which has a one value indicates what is the label for that particular number. All right. Then we have cross entropy which is nothing but the loss loss function and we have the optimizer. We have chosen gradient descent as our optimizer. Then the training process itself. So the training process is nothing but to minimize the cross entropy which is again nothing but the loss function. So we define all of this in the form of a graph. So the up to here remember what we have done is we have not exactly executed any tensorflow code till now we are just preparing the 8:01:37 graph the execution plan that's how the TensorFlow code works. So the whole structure and format of this code will be completely different from how we normally do programming. So even with people with programming experience may find this a little difficult to understand it and it needs quite a bit of practice. So you may want to view this uh video also maybe a couple of times to understand this flow because the way TensorFlow programming is done is slightly different from the normal programming. Some of you who let's say have done uh maybe spark programming to some extent will be able to easily understand this. Uh but even in spark the the programming the code itself is pretty straightforward. Behind the scenes the execution happens slightly differently but in tensorflow even the code has to be written in a completely different way. So the code doesn't get executed uh in the same way as you have 8:02:39 written. So that that's something you need to understand and a little bit of practice is needed for this. So so far what we have done up to here is creating the variables and feeding the variables and um or rather not feeding but setting up the variables and uh the graph that's all defining maybe the uh what kind of a network you want to use for example we want to use a softmax and so on. So you have created the variables, how to load the data, loaded the data, viewed the data and prepared everything but you have not yet executed anything in TensorFlow. Now the next step is the execution in TensorFlow. So the first step for doing any execution in TensorFlow is to initialize the variables. So anytime you have any variables defined in your code, you have to run this piece of code always. So you need to basically create what is known as a a node for initializing. So this is 8:03:39 a node. You still are not yet executing anything here. You just created a node for the initialization. So let us go ahead and create that. And here onwards is where you will actually execute your code uh in TensorFlow. And in order to execute the code, what you will need is a session. TensorFlow session. So tf session will give you a session. And there are a couple of different ways in which you can do this. But one of the most common methods of doing this is with what is known as a with loop. So you have a with tf do session as says and with a colon here. And this is like a block starting of the block and these indentations tell how far this block goes. And this session is valid till this block gets executed. So that is the purpose of creating this width block. This is known as a width 8:04:40 block. So with tf do session as you say ces do.run in it. Now ces.run run will execute a node that is specified here. So for example here we are saying ces run. CS is basically an instance of the session right. So here we are saying tf dot session. So an instance of the session gets created and we are calling that sess and then we run a node within that one of the nodes in the graph. So one of the nodes here is in it. So we say run that particular node and that is when the initialization of the variables happens. Now what this does is if you have any variables in your code in our case we have w is a variable and b is a variable. So any variables that we created you have to run this code you have to run the initialization of these variables otherwise you will get an 8:05:40 error. Okay so that is the that's what this is doing. Then we within this width block we specify a for loop and we are saying we want the system to iterate for thousand steps and perform the training. That's what this for loop does. Run training for thousand iterations. And what it is doing basically is it is fetching the data or these images. Remember there are about 50,000 images but it cannot get all the images in one shot because it will take up a lot of memory and performance issues will be there. So this is a very common way of performing deep learning training. You always do in batches. So we have maybe 50,000 images but you always do it in batches of 100 or maybe 500 depending on the size of your system and so on and so forth. So in this case we are saying okay get me 100 uh images at a time and 8:06:43 get me only the training images. Remember we use only the training data for training purpose and then we use test data for test purpose. You must be familiar with machine learning. So you must be aware of this but in case you are not in machine learning also not this is not specific to deep learning but in machine learning in general you have what is known as training data set and test data set. your available data typically you will be splitting into two parts and using the training data set for training purpose and then to see how well the model has been trained you use the test data set to check or test the validity or the accuracy of the model. So that's what we are doing here and you observe here that we are actually calling an MNEST function here. So we are saying mnest train next batch right. So this is the advantage of using mnest database because they have provided some very nice helper functions which are readily available otherwise this activity itself we would have had to 8:07:45 write a piece of code to fetch this data in batches that itself is a a lengthy exercise. So we can avoid all that if we are using mnest database and that's why we use this for the initial learning phase. Okay. So when we say fetch what it will do is it will fetch the images into X and the labels into Y and then you use this batch of 100 images and you run the training. So says run basically what we are doing here is we are running the training mechanism which is nothing but it passes this through the neural network passes the images through the neural network finds out what is the output and if the output obviously initially it will be wrong. So all that feedback is given back to the neural network and thereby all the W's and B's get updated till it reaches thousand iterations. In this case the exit criteria is 1,000 but you can also 8:08:46 specify probably accuracy rate or something like that for the as an exit criteria. So here it is it it just says that okay this particular image was wrongly predicted. So you need to update your weights and biases. That's the feedback given to each neuron and that is run for thousand iterations and typically by the end of this thousand iterations the model would have learned to recognize these handwritten images. Obviously it will not be 100% accurate. Okay. So once that is done after so this happens for thousand iterations. Once that is done, you then test the accuracy of these models by using the test data set. Right? So this is what we are trying to do here. The code may appear a little complicated because if you're seeing this for the first time, you need to understand uh the various methods of TensorFlow and so on. But it is basically comparing the output with what 8:09:46 has been what is actually there. That's all it is doing. So you have your test data and uh you're trying to find out what is the actual value and what is the predicted value and seeing whether they are equal or not tf.equal right and how many of them are correct and so on and so forth and based on that the accuracy is uh calculated as well. So this is the accuracy and uh that is what we are trying to see how accurate the model is in predicting these uh numbers or these digits. Okay. So let us run this. This entire thing is in one cell. So we will have to just run it in one shot. It may take a little while. Let us see. And uh not bad. So it has finished the thousand iterations. And what we see here as an output is the accuracy. So we see that the accuracy of this model is around 91%. Okay. Now which is pretty good for such a short exercise within such a short 8:10:48 time we got 90% accuracy. However, in real life this is probably not sufficient. So there are other ways in to increase the accuracy. We will see probably in some of the later tutorials how to improve this accuracy, how to change maybe the hyperparameters like number of neurons or number of layers and so on and so forth and uh so that this accuracy can be increased beyond 90%. Hello and welcome to the TensorFlow object detection API tutorial. In this video, I will walk you through the TensorFlow code to perform object detection in a video. So let's get started. This part is basically you're importing all the libraries. We need a lot of these libraries for example numpy. We need image io datetime and pill and so on and so forth. And of course mattplot lib. So we import all these libraries. And then there are a bunch of variables which have some paths 8:11:49 for the files and folders. So this is regular stuff. Let's keep moving. Then we import the mattplot lib and make it inline and uh a few more imports. All right. And then these are some warnings. We can just ignore them. So if I run this code once again, it will go away. All right. And then here onwards we do the model preparation. But what we're going to do is we're going to use an existing neural network model. So we are not going to train a new one because that really will uh take a long time and uh it needs a lot of computation resources and so on and it is really not required. There are already models that have been trained and in this case it is the SSD with mobile net. That's the model that we are going to use and uh this model is trained to detect objects and uh it is readily available as open source. So we can actually use this and if you want to use other models there are a few more models available. So you can click on this link here and uh let 8:12:52 me just take you there. There are a few more models but we have chosen this particular one because this is uh faster. It may not be very accurate but that is one of the faster models but on this link you will see a lot of other models that are readily available. These are trained models. Some of them would take a little longer but they may be more accurate and so on. So you can probably play around with these other models. Okay. So we will be using that model. So this piece of code this line is basically importing that model and this is also known as frozen model. The term we use is frozen model. So we import download and import that and then we will actually use that model in our code. All right. So these two cells we have downloaded and imported the model and then once it is available locally we will then load this into our program. All right. So we are loading this into 8:13:52 memory and uh you need to perform a couple of additional steps which is basically we need to to map the numbers to text. As you may be aware when we actually build the model and when we run predictions the model will not give a text the output of the model is usually a number. So we need to map that to a text. So for example if the network predicts that the output is five. We know that five means it is an aeroplane things like that. So this mapping is done in this next cell. All right. So let's keep moving. And then we have a helper code which will basically load the data or load the images and transform into numpy arrays. This is also used in doing object detection in images. So we are actually going to reuse because video is nothing but it consists of frames which in turn are images. So we are going to pretty much use reuse the same code which we used 8:14:53 for doing object detection in images. So this is where the actual detection starts. So here this is the path for where the images are stored. So this is here once again we are reusing the code which we wrote for detecting objects in an image. So this is the path where the images were stored and this is the extension and this was done for about two or three images. So we will continue to use this and uh we go down. I'll skip this section. So this is the cell where we are actually loading the video and converting it into frames and then using frame by frame we are detecting the objects in the image. So in this code what we are doing basically is there a few lines of code what they do is basically once they find an object a box will be drawn around those uh each of those objects and the input file the name of the input video file is uh traffic it is the extension is mp4 and uh we have this video reader it's a 8:15:55 excellent object which is basically part of this class called image IO so we can read and write videos using that and uh the video that we are going to use is traffic.mpp4. You can use any MP4 file but in our case I picked up video which has uh like car. So let me just show you. So this is in this object detection folder. I have this MP4 file. I'll just quickly play this video. It's a little slow. Yeah. Okay. So here we go. This is the video. It's a short one. relatively small video. So that for this particular demo and what it will do is once we run our code it will detect each of these cars and it will annotate them as cars. So in this particular video we only have cars. We can later on see with another video. I think I have cat here. So we can also try with that. But let's first check with this uh traffic video. So let me go back. So we will be reading this frame by frame and um no actually we 8:16:57 will be reading the video file but then we will be analyzing it frame by frame and we will be reading them at 10 frames per second that is the rate we are mentioning here and analyzing it and then annotating and then writing it back. So you will see that we will have a video file named something like this traffic annotated and um we will see the annotated video. So let's go back and run through this piece of code and then we will come back and see the annotated uh video. This might take a little while. So I will pause the video after running this particular cell and then come back to show you the results. All right. So let's go ahead and run it. So it is running now. And it is also important that at the end you close the video writer so that it is similar to a file pointer. When you open a file, you should also make sure you close it so that it doesn't hog the resources. So it's very similar at the end of it. The 8:17:57 last piece or last line of code should be video_riter.close. All right. So I'll pause and then I'll come back. Okay. So I will see you in a little bit. All right. So now as you can see here the processing is done. The hourglass has disappeared. That means the video has been processed. So let's go back and check the annotated video. We'll go back to my file manager. So this was the original traffic.mpp4 and now you have here traffic_an annotated mp4. So let's go and run this and see how it looks. You see here it has got each of these cars are getting detected. Let me pause and show you. So we pause here. It says car 70%. Let us allow it to go a little further. It detects something on top. What is that truck? Okay. So I think because of the board on top it somehow thinks there is a truck. Let's play some more and see if it detects anything else. So this is again a car looks like. 8:18:59 So let us Yeah. So this is a car and it has confidence level of 69%. Okay. This is again a car. All right. So basically till the end it goes and detects each and every car that is passing by. Now we can quickly repeat this process for another video. Let me just show you the other video which is a cat. Again there is uh this cat is not really moving or anything but it is just standing there staring and moving a little slowly. And uh our application will our network will detect that this is a cat and uh even when the cat moves a little bit in the other direction it'll continue to detect and show that it is a cat. Okay. So yeah. So this is how the original video is. Let's go ahead and change our code to analyze this one and see if it detects our network detects this cat. Close this. Here we go. And I'll go back to my code. All we need to do is change this traffic to cat. The extension it 8:20:02 will automatically pick up because it is given here and then it will run through. So very quickly once again what it is doing is this video reader video reader has a a neat little feature or interface whereby you can say for frame in video reader. So it will basically provide frame by frame. So you're in a loop frame by frame and then you take that each frame that is given to you. You take it and analyze it as if it is an image individual image. So that's the way it works. So it is uh very easy to handle this. All right. So now let's once again run just this cell. The rest of the stuff remains the same. So I will run this cell again. It will take a little while. So the hourglasses come back. I will pause and then come back in a little while. All right. So the processing is done. Let's go and check the annotated video. Go here. So we have cat annotated.mpp4. Let's play this. All right. So you can see here it is detecting the cat. And in the beginning you also saw it detected 8:21:04 something else here. There looks like it detected one more object. So let's just go back and see what it has detected yet. Let's see. Yes. So what is it trying to show here? It's too small. Not able to see. But uh it is trying to detect something. I think it is saying it is a car. I don't know. All right. Okay. So in this video there's only pretty much only one object which is a cat. And uh let's wait for some time and see if it continues to detect it when the cat turns around and moves as well. Just in a little bit that's going to happen and we will see. There we go. And in spite of turning the other way, I think our network is able to detect that it is a cat. So let me freeze and then show here. It is actually still continues to detect it as a cat. All right. So that's pretty much it. I think that's the only object that it detects in this particular video. Okay, so close this. So that's pretty much it. Thank 8:22:04 you very much for watching this video and you have a great day and in case you have any questions, please uh put them below the video here and we will be more than happy to get back to you and make sure you put your email id so that we can contact you in case you have any questions. Thank you once again. Bye-bye. Today we're going to be covering the convolutional neural network tutorial. Do you know how deep learning recognizes the objects in an image? And really this particular neural network is how image recognition works. It's very central, one of the biggest building blocks for image recognition. It does it using convolution neural network. And we over here we have the basic picture of a hummingbird. Pixels of an image fed as input. You have your input layer coming in. So it takes that graphic and puts it into the input layer. You have all your hidden layers and then you have your output layer and your output layer. one of those is going to light up and say, "Oh, it's a bird." We're going to go into depth. We're going to actually go back and forth on this a number of times today. So, if you're not catching all the image, um, don't worry. We're going to get into the 8:23:05 details. So, we have our input layer accepts the pixels of the image as input in the form of arrays. And you can see up here where they've actually, um, labeled each block of the bird in different arrays. So, we'll dive into deep as to how that looks like and how those matrixes are set up. your hidden layer carry out feature extraction by performing certain calculations and manipulation. So this is the part that kind of reorganizes that picture multiple ways until we get some data that's easy to read for the neural network. This layer uses a matrix filter and performs convolution operation to detect patterns in the image. And if you remember that convolution means to coil or to twist. So we're going to twist the data around and alter it and use that operation to detect a new pattern. There are multiple hidden layers like convolution layer relu is how that is pronounced and that's the rectified linear unit that has to do with the activation function that's used. Pooling layer also uses multiple filters to detect edges, corners, eyes, feathers, 8:24:07 beak, etc. And just like the term says, pooling is pooling information together. And we'll look into that a lot closer here. So if you're if it's a little confusing now, we'll dig in deep and try to get you uh squared away with that. And then finally, there is a fully connected layer that identifies the object in the image. So we have these different layers coming through in the hidden layers and they come into the final area and that's where we have say one node or one neural network entity that lights up that says it's a bird. What's in it for you? We're going to cover an introduction to the CNN. What is convolution neural network? how CNN recognizes images. We're going to dig deeper into that and really look at the individual layers in the convolutional neural network. And finally, we do a use case implementation using the CNN. We'll begin our introduction to the CNN by introducing pioneer of convolutional neural network, Yan Leon. He was the director of Facebook AI research group. Built the first convolutional neural network called Lynette in 1988. So these 8:25:07 have been around for a while and have had a chance to mature over the years. It was used for character recognition tasks like reading zip code digits. Imagine processing mail and automating that process. CNN is a feed forward neural network that is generally used to analyze visual images by producing data with a grid-like topology. A CNN is also known as a convenet. And very key to this is we are looking at images. That was what this was designed for. And you'll see the different layers as we dig in mirror some of the other some of them are actually now used since we're using uh TensorFlow and KAS in our code later on. You'll see that some of those layers appear in a lot of your other neural network frameworks. Uh but in this case, this is very central to processing images and doing so in a variety that captures multiple images and really drills down into their different features. In this example here, you see flowers of two varieties, orchid and a rose. I think the orchid is much more dainty and beautiful and the rose smells quite beautiful. I have a couple rose bushes in my yard. Uh they 8:26:08 go into the input layer. That data is then sent to all the different nodes in the next layer of one of the hidden layers based on its different weights and its setup. It then comes out and gives those a new value. Those values then are uh multiplied by their weights and go to the next hidden layer and so on. And then you have the output layer and one of those nodes comes out and says it's an orchid and the other one comes out and says it's a rose depending on how was well it was trained. What separates the CNN or the convolutional neural network from other neural networks is a convolutional operation forms a basis of any convolutional neural network. In a CNN, every image is represented in the form of arrays of pixel values. So here we have a real image of the digit 8 uh that then gets put onto its pixel values represented in the form of an array. In this case you have a two-dimensional array. And then you can see in the final in form we transform the digit 8 into its representational form of pixels of zeros and one where the ones represent in this case the black part of the eight and the 8:27:09 zeros represent the white background. To understand the convolution neural network or how that convolutional operation works, we're going to take a side step and look at matrices. In this case, we're going to simplify it. We're going to take two matrices A and B of one dimension. Now kind of separate this from your thinking as we learn that you want to focus just on the matrix aspect of this and then we'll bring that back together and see what that looks like when we put the pieces for the convolutional operation. Here we've set up two arrays. We have uh in this case are a single dimension matrix and we have a= 537597 and we have b= 1 2 3. So in the convolution as it comes in there it's going to look at these two and we're going to start by doing multiplying them. a * b. And so we multiply the arrays elementwise and we get 5 6 where five is the 5 * 1. 6 is 3 * 2 and then the other six is 2 * 3. And since the two arrays aren't the same size, they're 8:28:11 not the same setup. We're going to just truncate the first one and we're going to look at the second array multiplied just by the first three elements of the first array. Now that's going to be a little confusing. Remember, a computer gets to repeat these processes hundreds of times. So, we're not going to just forget those other numbers later on. We'll see. We'll bring those back in. And then we have the sum of the product. In this case, 5 + 6 + 6= 17. So, in our A * B, our very first digit in that matrix of A * B is 17. And if you remember, I said we're not going to forget the other digits. So, we now have 325. We move one set over and we take 325 and we multiply that times B. And you'll see that 3 * 1 is 3, 2 * 2 is 4, and so on and so on. We sum it up. So now we have the second digit of our A * B product in the matrix. And we continue on with that same thing. So on and so on. So then we would go from uh 375 to 759 to 597. This short matrix that that we have for A, we've now covered all the 8:29:12 different entities in A that match three different levels of B. Now, in a little bit, we're going to cover where we use this math at this multiplying of matrices and how that works. Uh, but it's important to understand that we're going through the matrix and multiplying the different parts to it to match the smaller matrix with the larger matrix. I know a lot of people get lost at is, you know, what's going on here with these matrixes. Uh, scary math. Not really that scary when you break it down. We're looking at a section of A and we're comparing it to B. So when you break that down in your mind like that, you realize, okay, so I'm I'm just taking these two matrices and comparing them and I'm bringing the value down into one matrix A * B. We're juicing that information in a way that will help the computer see different aspects. Let's go ahead and flip over again back to our images. Here we are back to our images. Talking about going to the most basic two-dimensional image you can get to. Consider the following two images. the image for the symbol backslash. When you press the backslash, the above image is 8:30:13 processed. And you can see there for the image for the forward slash is the opposite. So we click the forward slash button that flips. Uh very basic. We have four pixels going in. Can't get any more basic than that. Here we have a little bit more complicated picture. We take a real image of a smiley face. Um then we represent that in the form of black and white pixels. So if this was an image in the computer, it's black and white. And like we saw before, we convert this into the zeros and ones. So where the other one would have just been a matrix of just four dots, now we have a significantly larger image coming in. So don't worry, we're going to bring this all together here in just a little bit. Layers in convolutional neural network. When we're looking at this, we have our convolution layer. And that really is the central aspect of processing images and the convolutional neural network. That's why we have it. And then that's going to be feeding in. And you have your relu layer which is you know as we talked about the rectified linear unit. We'll talk about that a little bit later. The relu is an 8:31:14 how it act is how that layer is activated is the math behind it. What makes the neurons fire. You'll see that in a lot of other neural networks when you're using it just by itself. It's for processing smaller amounts of data where you use the atom activation feature for large data coming in. Now, because we're processing small amounts of data in each image, the relu layer works great. You have your pooling layer. That's where you're pulling the data together. Pooling is a neural network term. It's very commonly used. I like to use a term reduce. So, if you're coming from the map and reduce side, you'll see that we're mapping all this data through all these networks and then we're going to reduce it. We're going to pull it together. And then finally, we have the fully connected layer. That's where our output's going to come out. So we have started to look at matrixes. We've started to look at the convolutional layer and where it fits in and everything. We've taken a look at images. So we're going to focus more on the convolution layer since this is a convolutional neural network. A convolution layer has a number of filters and perform convolution 8:32:15 operation. Every image is considered as a matrix of pixel values. Consider the following 5x5 image whose pixel values are only 0 and one. Now, obviously when we're dealing with color, there's all kinds of things that come in on color processing, but we want to keep it simple and just keep it black and white. And so, we have our image pixels. Uh, so we're sliding the filter matrix over the image and computing the dotproduct to detect the patterns. And right here, you're going to ask where does this filter come from? This is a bit confusing because the filter is going to be derived uh later on. We build the filters when we program or train our model. So you don't need to worry what the filter actually is, but you do need to understand how a convolution layer works is what is the filter doing filter. And you'll have many filters. You don't have just one filter. You'll have lots of filters that are going to look for different aspects. And so the filter might be looking for just edges. It might be looking for different parts. We'll cover that a little bit more detail in a minute. Right now, we're just focusing on how the filter works as 8:33:16 a matrix. Remember earlier we talked about multiplying matrices together. And here we have our two-dimensional matrix. And you can see we take the filter and we multiply it in the upper left image. And you can see right here 1 * 1, 1 * 0, 1 * 1. We multiply those all together, then sum them. And we end up with a convolved feature of four. We're going to take that and sliding the filter matrix over the image and computing the dotproduct to detect patterns. So we're just going to slide this over. We're going to predict the first one and slide it over one notch. Predict the second one and so on and so on all the way through until we have a new matrix. And this matrix which is the same size as a filter has reduced the image and whatever filter whatever that's filtering out is going to be looking at just those features reduced down to a smaller uh matrix. So once the feature maps are extracted the next step is to move them to the relu layer. So the relu layer the next step first is going to perform an elementwise operation. So 8:34:17 each of those maps coming in if there's negative pixels. So it sets all the negative pixels to zero. Um and you can see this nice graph where it just zeros out the negatives and then you have a value that goes from zero up to whatever value is um coming out of the matrix. This introduces nonlinearity to the network. Uh so up until now we have a when we say linearity we're talking about the fact that the feature has a value. So it's a linear feature. This feature um came up and has let's say the feature is the edge of the beak. You know it's like or that backslash that we saw. um you'll look at that and say, "Okay, this feature has a value from -10 to 10 in this case." Um if it was one, it' say, "Yeah, this might be a beak. It might not might be an edge right there." A minus 5 means no, we're not even going to look at it's a zero. And so we end up with an output and the output takes all these featured features. Remember, we're not just running one filter on this, we're running a number of filters on this image. And so we end up with an rectified feature map that is looking at 8:35:18 just the features coming through and how they weigh in from our filters. So here we have an input of a it looks like a toucan bird very exotic looking real image is scanned in multiple convolution and the relu layers for locating features and you can see up here it's turned it into a black and white image and in this case we're looking in the upper right hand corner for a feature and that box scans over. A lot of times it doesn't scan one pixel at a time. A lot of times it will skip by two or three or four pixels uh to speed up the process. That's one of the ways you can compensate if you don't have enough resources on your computation for large images. And it's not just one filter slowly goes across the image. Uh you have multiple filters have been programmed in there. So you're looking at a lot of different filters going over the different aspects of the image and just sliding across there and forming a new matrix. One more aspect to note about the relu layer is we're not just having one relu coming in. Uh so 8:36:18 not only do we have multiple features going through but we're generating multiple relu layers for locating the features. That's very important to note you know so we have a quite a bundle. We have multiple filters multiple railu uh which brings us to the next step forward propagation. Now we're going to look at the pooling layer. The rectified feature map now goes through a pooling layer. pooling is a downsampling operation that reduces the dimensionality of the feature map. That's all we're trying to do. We're trying to take a huge amount of information and reduce it down to a single answer. This is a specific kind of bird. This is an iris. This is a rose. So, you have a rectified feature map. And you see here we have a rectified feature map coming in. Um, we set the max pooling with a 2x two filters and a stride of two. And if you remember correctly, I talked about not going one pixel at a time. Uh well that's where the stride comes in. We end up with a 2x two pulled feature map but instead of moving one over each time and looking at every possible combination we 8:37:18 skip a we skip a few there. We go by two. We skip every other pixel and we just do every other one. Um and this reduces our rectified feature map which is you can see over here 16x 16 to a 4x4. So we're continually trying to filter and reduce our data so that we can get to something we can manage. And over here you see that we have the max uh 3 4 1 and 2 and in the max pooling we're looking for the max value a little bit different than what we were looking at before. So coming from the rectified feature we're now finding the max value and then we're pooling those features together. So instead of think of this as image of the map think of this as how valuable is a feature in that area. How much of a feature value do we have? And we just want to find the best or the maximum feature for that area. They might have that one piece of the filter of the beak said, "Oh, I see a one in this beak in this image." And then it skips over and says, "I see a three in this image." And says, "Oh, this one is rated as a four." We don't want to sum it together cuz then, you know, you might have like five ones and it'll say, 8:38:19 "Ah, five." But you might have uh four zeros and one 10. And that 10 says, "Well, this is definitely a beak." Where the ones will say, "Probably not a beak." A little strange analogy since we're looking at a bird, but you can see how that pulled feature map comes down. And we're just looking for the max value in each one of those matrixes. Pooling layer uses different filters to identify different parts of the image like edges, corners, body, feathers, eyes, beak, etc. Um, I know I focus mainly on the beak, but obviously uh each feature could be each a different part of the bird coming in. So, let's take a look at what that looks like. Structure of a convolution neural network. So far, this is where we're at right now. We have our input image coming in and then we use our uh filters and there's multiple filters on there that are being developed to kind of twist and change that data. And so we multiply the matrixes. We take that little filter maybe it's a 2x two we multiply it by each piece of the image. And if we step two then it's every other piece of the image that generates multiple 8:39:21 convolution layers. So we have a number of convolution layers we have um set up in there is looking at that data. We then take those convolution layers. We run them through the relu setup. And then once we've done through the relu setup and we have multiple relu going on, multiple layers that are relu then we're going to take those multiple layers and we're going to be pooling them. So now we have the pooling layers or multiple poolings going on. Up until this point we're dealing with u sometimes it's multiple dimensions. You can have three dimensions. Some strange data setups that aren't doing images but looking at other things they can have four, five, six, seven dimensions. Uh so right now we're looking at 2D image dimensions coming in into the pooling layer. So the next step is we want to reduce those dimensions or flatten them. So flattening flattening is a process of converting all of the resultant two-dimensional arrays from pulled feature map into a single long continuous linear vector. So over here you see where we have a pulled feature map. Maybe that's the bird wing and it has values 6847 and we want to just flatten this out and turn it into 6847 8:40:23 or a single linear vector. And we find out that not only do we do each of the pulled feature maps, we do all of them into one long linear vector. So now we've gone through our convolutional neural network part and we have the input layer into the next setup. All we've done is taken all those different pooling layers and we've flattened them out and combined them into a single linear vector going in. So after we've done the flattening, we have uh just a quick recap because we've covered so much. So it's important to go back and take a look at each of the steps. We've gone through the structure of the network so far. So we have our convolution where we twist it and we filter it and multiply the matrices. We end up with our convolutional layer which uses the relu to figure out the values going out into the pooling. as you have numerous convolution layers that then create numerous pooling layers pooling that data together which is the max value which one we want to send forward. We want to send the best value and then we're going to take all of that from each of the pooling layers and we're going to flatten it and we're going to combine them into a single 8:41:25 input going into the final layer. Once you get to that step you might be looking at that going boy that looks like the normal input to most neural network and you're correct it is. So once we have the flattened matrix from the pooling layer that becomes our input. So the pooling layer is fed as an input to the fully connected layer to classify the image. And so you can see as our flattened matrix comes in in this case we have the pixels from the flattened matrix fed as an input back to our toucan or whatever that kind of bird that is. Um I need one of these to identify what kind of bird that is. It comes into our forward propagation network. Uh, and that will then have the different weights coming down across. And then finally, it selects that that's a bird and that it's not a dog or a cat in this case, even though it's not labeled. The final layer there in red is our output layer. Our final output layer that says bird, cat, or dog. So, quick recap of everything we've covered so far. We have our input image, which is twisted and multiply. The filters are 8:42:25 multiplied times the uh matri the two matrixes multiplied all the filters to create our convolution layer. Our convolution layers there's multiple layers in there because it's all building multiple layers off the different filters. Then goes through the relu as this activation and that creates our pooling. And so once we get into the pooling layer, we then the pooling look for who's the best, what's the max value coming in from our convolution. And then we take that layer and we flatten it and then it goes into a fully connected layer. our fully connected neural network and then to the output. And here we can see the entire process how the CNN recognizes a bird. This is kind of nice because it's showing the little pixels and where they're going. You can see the filter is generating this convolution network and that filter shows up in the bottom part of the convolution network. And then based on that, it uses the relu for the pooling. The pooling then find out which one's the best and so on all the way to the fully connected layer at the end or the classification in the output layer. So that'd be a classification neural network at the end. So we covered a lot 8:43:25 of theory up till now and you can imagine each one of these steps has to be broken down in code. So putting that together can be a little complicated. Not that each step of the process is overly complicated, but because we have so many steps. Uh we have 1 2 3 4 five different steps going on here with substeps in there. We're going to break that down and walk through that in code. So in our use case implementation using the CNN, we will be using the CR10 data set from Canadian Institute for Advanced Research for classifying images across 10 categories. Unfortunately, they don't let me know whether it's going to be a toucan or some other kind of bird. But we do get to find out whether it can categorize between a ship, a frog, deer, bird, airplane, automobile, cat, dog, horse, truck. So that's a lot of fun. And then if you're looking anything in the news at all of our automated cars and everything else, you can see where this kind of processing is so important in today's world and very cutting edge as far as what's coming out in the 8:44:26 commercial deployment. I mean, this is really cool stuff. We're starting to see this just about everywhere in industry. Uh so great time to be playing with this and figuring it all out. Let's go ahead and dive into the code and see what that looks like when we're actually writing our script. Before we go on, let's do uh one more quick look at what we have here. Let's just take a look at data batch one keys. And remember in Jupyter notebook, I can get by with not doing the print statement. If I put a variable down there, it'll just display the variable. And you can see under data batch one for the keys, since this is a dictionary, we have the batch one label, data, and file names. Uh so you can actually see how it's broken up in our data set. So for the next step or step four as we're calling it uh we want to display the images using mattplot library. There's many ways to display the images. You could even uh well there's other ways to drill into it but mattplot library is really good for this. And we'll also look at our first reshape uh setup or shaping the data so you can have a little glimpse into what that means. Uh so we're going to start 8:45:27 by importing our map plot. And of course since I am doing Jupyter notebook I need to do the map plot inline command so it shows up on my page. So here we go. We're going to import mapplot library.pipplot is plt. And if you remember mapplot library the pipplot is like a canvas that we paint stuff onto. And there's my percentage sign mapplot library in line. So it's going to show up in my notebook. And then of course we're going to import numpy as np for our numbers python array setup. And let's go ahead and set x equals to data batch one. So this will pull in all the data going into the x value. And then because this is just a long stream of binary data, uh we need to go to a little bit of reshaping. So in here we have to go ahead and reshape the data. We have 10,000 images. Okay, that looks correct. And this is kind of an interesting thing. It took me a little bit to I had to go research this myself to figure out what's going on with this data. And what it is is it's a 32x 32 8:46:29 picture. And let me do this. Let me go ahead and do a drawing pad on here. Uh, so we have 32 bits by 32 bits and it's in color. So there's three bits of color. Now, I don't know why the data is particularly like this. It probably has to do with how they originally encoded it. But most pictures put the three afterward. So what we're doing here is we're going to take uh the shape. We're going to take the data, which is just a long stream of information, and we're going to break it up into 10,000 pieces. And those 10,000 pieces then are broken into three pieces each. And those three pieces then are 32x 32. You can look at this like an oldfashioned projector where they have the red screen or the red projector, the blue projector and the green projector and they add them all together and each one of those is a 32x 32bit. So that's probably how this was originally formatted was in that kind of ideal. Things have changed. So we're going to transpose it and we're going to take the three which was here and we're going to put it at the end. So the first part is reshaping the data 8:47:29 from a single line of bit data or whatever format it is into 10,000x3x 32x32. And then we're going to transpose the color factor to the last place. So it's the image then the 32x 32 in the middle. That's this part right here. And then finally we're going to take this uh which is three bits of data and put it at the end. So it's more like we do we process images now. And then as type, this is really important that we're going to use an integer 8. You can come in here and you'll see a lot of these they'll try to do this with a float or a float 64. What you got to remember though is a float uses a lot of memory. So once you switch this into uh something that's not integer 8, which is goes up to 128, you are just going to the the amount of RAM, let me just put that in here, is going to go way up. the amount of RAM that it loads. Uh so you want to go ahead and use this. You can try the other ones and see what happens if you have a lot of RAM on your computer, but for this exercise, this 8:48:31 will work just fine. And let's go ahead and take that and run this. So now our X variable is all loaded and it has all the images in it from the batch one data batch one. And just to show we were talking about with the as type on there, if we go ahead and take X0 and just look for its max value, let me go ahead and run that. Uh you'll see it doesn't oops I said 128. It's 255. Uh you'll see it doesn't go over 255 because it's an basically an asky character is what we're keeping that down to. We're keeping those values down. So they're only 255 0 to 255 versus a float value which would bring this up um exponentially in size. And since we're using the map plot library, we can do um oops that's not what I wanted. Since we're using the map plot library, we can take our canvas and just do a plt. I im for image show. And let's just take a look at what x0 looks like. And it comes in I'm not sure what that is, but you can see it's a very low grade image uh 8:49:31 broken down to the minimal pixels on there. And if we did the same thing, oh, let's do uh let's see what one looks like. Hopefully, it's a little easier to see. Run on there. Not enter. Let's hit the run on that. Uh and we can see this is probably a semitr. That's a good guess on there. And I can just go back up here instead of typing the same line in over and over. And we'll look at three. Uh that looks like a dump truck unloading. Uh and so on. You can do any of the 10,000 images. We can just jump to 55. Uh looks like some kind of animal looking at us there. Probably a dog. And just for fun, let's do just one more uh uh run on there. And we can see a nice car for our image number four. Uh so you can see we pace through all the different images. It's very easy to look at them. and they've been reshaped to fit our view and what the uh mapplot library uses for its format. So the next step is we're going to start creating some helper functions. We'll start by a one hot encoder to help us. We're processing the data. Remember that your labels, they can't just be words. They have to switch it and we use the one hot 8:50:32 encoder to do that. And then we'll also create a uh class uh car helper. So it's going to have an init and a setup for the images. And then finally, we'll go ahead and run that code so you can see what that looks like. And then we get into the fun part where we're actually going to start creating our model, our actual neural network model. So let's start by creating our one hot encoder. We're going to create our own here. Uh and it's going to return an out and we'll have our vector coming in and our values equal 10. What this means is that we have the 10 values, the 10 possible labels. And remember, we don't look at the labels as a number because a car isn't one more than a horse. That'd be just kind of bizarre to have horse equals 0, car equals 1, plane equals 2, cat equals three. So a cat plus a car equals what? Uh so instead we create a numpy array of zeros and there's going to be 10 values. So we have a 10 different values in there. So you have uh zero or one. One means it's a cat. Zero means it's not a cat. Um in the 8:51:34 next line it might be that uh one means it's a car, zero means it's not a car. So instead of having one output with a value of 0 to 10, you have 10 outputs with the values of 0 to one. That's what the one hot encoder is doing here. And we're going to utilize this in code in just a minute. So let's go ahead and take a look at the next helpers. We have a few of these helper functions we're going to build. And when you're working with a very complicated Python project, dividing it up into separate definitions and classes is very important. Otherwise, it just becomes really ungainainely to work with. So, let's go ahead and put in our next helper uh which is a class. And this there's a lot in this class. So, we we'll break it down here. Let's just start uh oops we can put a space right in there. There we go. That looks a little bit more readable. Add a second space. So, we're going to create our class the cipher helper. And we'll start by initializing it. Now there's a lot going on in here. So let's start with the uh innit part. Uh self doi equals zero. That'll come in in a little bit. We'll come back to that in the lower part. We want to initialize 8:52:36 our training batches. So when we went through this, there was like a meta batch. We don't need the meta batch, but we do need the data batch 1 2 3 4 5. And we do not want the testing batch in here. This is just the selfall train batches. So we're going to come make an array of of all those different images. And then of course we left the test batch out. So we have our self.est batch. Uh we're going to initialize the training images and the training labels and also the test images and the test labels. So these are just this is just to initialize these variables in here. Then we create another definition down here and this is going to set up the images. Let's just take a look and see what's going on in there. Now, we could have all just put this as part of the uh innit part uh since this is all just helper stuff. But breaking it up again makes it easier to read. It also makes it easier when we start executing the different pieces to see what's going on. So that way we have a nice print statement to say, hey, we're now running this and this is what's going on in here. We're going to set up these 8:53:36 self-training images at this point and that's going to go to a numpy array vstack. And in there, we're going to load up uh in this case, the data for D and self, all trained batches. Again, that points right up to here. So, we're going to go through each one of these uh files or each one of these data sets because they're not a file anymore. We've brought them in. Data batch one points to the actual data. And so, our self-training images is going to stack them all into our into a numpy array. And then, it's always nice to get the training length. And that's just the total number of uh self-training images in there. And then we're going to take the self-training images. And let me switch marker colors because I am getting a little too much on the markers up here. Oops, there we go. Bring down our marker change so we can see it a little better. And at this point, this should look familiar. Where did we see this? Well, when we wanted to uh uh look at this above and we went to look at the images in the mattplot library, we had to reshape it. So, we're doing the same thing here. We're taking our 8:54:37 self-training images and uh based on the training length, total number of images because we stacked them all together. So now it's just one large file of images. We're going to take and look at it as our our three video cameras that are each displaying a 32x32. We're going to switch that around so that now we have um each of our images that stays the same place. And then we have our 32x 32 and then by our three our last uh our three different values for the color. And of course we want to go ahead and uh they run this where we say divide by 255. That was from earlier. It just brings all the data into 0ero to one. That's what this is doing. So we're turning this into a 0 to one array which is uh all the pictures 32x 32x3. And then we're going to take the self-training labels and we're going to pump those through our one hot encoder we just made and we're going to stack them together. And uh again, we're converting this into an array that goes 8:55:37 from uh instead of having horse equals 1, dog equals 2, and then horse plus dog would equal three, which would be cat. Now, it's going to be uh you know an array of 10 where each one is 0ero to one. Then we want to go ahead and set up our test images and labels. And uh when we're doing this, you're going to see it's the same thing we just did with the rest of them. Let me just change colors right here. This is no different than what we were doing up here with our training set. Uh we're going to stack the different uh images. Uh we're going to get the length of them so we know how many images are in there. Uh you certainly could add them by hand, but it's nice to let the computer do it, especially if it ever changes on the other end and you're using other data. And again, we reshape them and transpose them. And we also do the one hot encoder. same thing we just did on our training images. So now our test images are in the same format. So now we have a uh definition which sets up all our images in there. And then the next step is to go ahead and batch them or next batch. And let's do another breakout here for batches because this is really 8:56:38 important to understand tends to throw me for a little loop when I'm working with TensorFlow or KAS or a lot of these. We have our data coming in. If you remember, we had like 10,000 photos. Let me just put 10,000 down here. We don't want to run all 10,000 at once. So, we want to break this up into batch sizes. And you also remember that we had the number of photos in this case, uh, length of test or whatever number is in there. Uh, we also have 32x 32x3. So when we're looking at the batch size, we want to change this from 10,000 to um a batch of in this case I think we're going to do batches of 100. So we want to look at just 100, the first hundred of the photos. And if you remember, we set selfi equal to zero. Uh so what we're looking at here is we're going to create x. We're going to get the next batch from the very initialize. We've already initialized it for zero. So we're going to look at x from zero to batch size, which we've set to 100. So just the first 100 images and then we're 8:57:40 going to reshape that into uh and this is important to let the data know that we're looking at 100x 32x 32x3. Now we've already formatted it to the 32x 32x3. This just sets everything up correctly so that x has the data in there in the correct order in the correct shape. And then the y just like the x uh is our labels. So our training labels again they go from zero to batch size. In this case, they do self eye plus batch size because the self eye is going to keep changing. And then finally, we increment the self i because we have zero. So we so the next time we call it, we're going to get the next batch size. And so basically we have x and y. x being the photograph data coming in and y being the label. And that of course is labeled through one hot encoder. So if you remember correctly, if it was say horse is equal to zero, it would be one for the zero position since this is the horse. And then everything else would be zero in here. Just put lines through there. There we go. There's our array. Hard to 8:58:41 see that array. So, let's go ahead and take that and uh we're going to finish loading it since this is our class. And now we're armed with all this um uh our setup over here. Let's go ahead and load that up. And so we're going to create a variable ch with the car helper in it. And then we're going to do ch setup images. Uh now we could have just put all of the setup images under the init but by breaking this up into two parts it makes it much more readable and um also if you're doing other work there's reasons to do that as far as the setup. Let's go ahead and run that and you can see where it says uh setting up training images and labels setting up test images. And that's one of the reasons we broke it up is so that if you're testing this out you can actually have print statements in there telling you what's going on which is really nice. Uh they did a good job with this setup. I like the way that it was broken up in the back. And then one quick note, you want to remember that batch to set up the next batch is we have to run uh batch equals ch next batch of 100 because we're going to use the 100 size. Uh but we'll come back to that. We're going to 8:59:42 use that. Just remember that that's part of our code we're going to be using in a minute from the definition we just made. So now we're ready to create our model. First thing we want to do is we want to import our TensorFlow as TF. I'll just go ahead and run that. So it's loaded up. And you can see we got a a warning here. Uh that's because they're making some changes. It's always growing and they're going to be depreciating one of the uh values from float 64 to float type or it's treated as an nplat 64. Uh nothing to really worry about cuz this doesn't even affect what we're working on because we've set all of our stuff to a 255 value or 0 to one. And do keep in mind that 0ero to one value that we converted to 255 is still a float value. uh but it'll easily work with either the uh numpy float 64 or the numpy dtype float. It doesn't matter which one it goes through. So the depreciation would not affect our code as we have it. And in our tensorflow uh we'll go ahead let me just increase the size in there just a moment so you can get better view of the um what we're typing in. Uh we're going to set a couple placeholders here. 9:00:43 And so we have we're going to set x equals tf placeholder tf float 32. We just talked about the float 64 versus the numpy float. We're actually just going to keep this at float 32 more than uh significant number of decimals for what we're working with. And since it's a placeholder, we're going to set the shape equal to and we've set it equal to none because at this point we're just holding the place on there. We'll be setting up as we run the batches. That's what that first value is. And then 32x 32x3. That's what we've reshaped our data to fit in. And then we have our y true equals placeholder tf float 32 and the shape equals none, 10. 10 is the 10 different labels we have. So it's an array of 10. And then let's create one more placeholder. We'll call this hold prob or hold probability. And we're going to use this. We don't have to have a shape or anything for this. This placeholder is for what we call dropout. If you remember from our theory before, we drop out so many nodes is looking at or the different values going through 9:01:44 which helps decrease bias. So we need to go ahead and put a a placeholder for that also. And we'll run this. So it's all loaded up in there. So we have our three different placeholders. And since we're in TensorFlow, when you use KASS, it does some of this automatically, but we're in TensorFlow direct. KAS sits on TensorFlow. We're going to go ahead and create some more helper functions. So, we're going to create something to help us initialize the weights, initialize our bias. If you remember that each uh layer has to have a bias going in. We're going to go ahead and work on our our conversional 2D, our max pool. So, we have our pooling layer, our convolutional layer, and then our normal full layer. So, we're going to go ahead and put those all into definitions. And let's see what that looks like in code. And you can also grab some of these helper functions from the MNIS, the uh NIST setup. Let me just put that in there if you're under the TensorFlow. So, a lot of these are already in there, but we're going to go ahead and do our own. And we're going to create our uh init weights. And one of the reasons we're doing this is so that you can actually start thinking about what's 9:02:42 going on in the back end. So, even though there's ways to do this with an automation, sometimes these have to be tweaked and you have to put in your own setup in here. Uh now, we're not going to be doing that. We're just going to recreate them for our code. And let's take a look at this. We have our weights. And so, what comes in is going to be the shape, and what comes out is going to be uh random numbers. So, we're going to go ahead and just init some random numbers based on the shape with a standard deviation of 0.1. Kind of a fun way to do that. And then the TF variable, uh, init random distribution. So, we're just creating a random distribution on there. That's all that is for the weights. Now, you might change that. You might have a a higher standard deviation. In some cases, you actually load preset weights. That's pretty rare. Usually, you're testing that against another model or something like that, and you want to see how those weights configure with each other. Uh now remember we have our bias. So we need to go ahead initialize the bias with a constant. Uh in this case we're using 0.1. A lot of times the bias is just put in as one and then you have 9:03:40 your weights add on to that. Uh but we're going to set this as 0.1. Uh so we want to return a convolutional 2D in this case a neural network. This is uh would be a layer on here. What's going on with the con 2D is we're taking our data coming in. uh we're going to filter it. Strides, if you remember correctly, strides came from here's our image and then we only look at this picture here and then maybe we have a stride of one. So we look at this picture here and we continue to look at the different filters going on there. The other thing this does is that we have our data coming in as 32x 32x 3. And we want to change this so that it's just this is three dimensions and it's going to reformat this as just two dimensions. So it's going to take this number here and combine it with the 32x 32. So this is a very important layer here because it's reducing our data down using different means and it connects down. I'm just going to jump down one here. uh it goes with the convolutional 9:04:43 layer. So you have your your kind of your pre-formatting and the setup and then you have your actual convolution layer that goes through on there. And you can see here we have a net weights by the shape a net bias shape of three because we have the three different uh here's our three again. And then we return the TFN relu. So this convolutional uh has this feeding into it right there. It's using that as part of it. And of course the input is the xy plus b the bias. So that's quite a mouthful, but these two are the are the keys here to creating the convolutional layers there. The convolutional 2D coming in and then the convolutional layer which then steps through and creates all those filters we saw. Then of course we have our pooling. Uh so after each time we run it through the convectional layer, we want to pull the data uh if you remember correctly on the on the pool side. And let me just get rid of all my marks. It's getting a little crazy there. And in fact, let's go ahead and jump back to that slide. Let's just take a look at that slide over here. Uh so we have our image coming in. We create our convolutional 9:05:43 layer with all the filters. Remember the filters go um you know the filter is coming in here and it looks at these four boxes and then if it's a step let's say step two it then goes to these four boxes and then the next step and so on. Uh so we have our convolutional layer that we generate or convolutional layers. They use the uh relu function. Um there's other functions out there for this though. The relu is the uh most the one that works the best at least so far. I'm sure that will change. Then we have our pooling. Now, if you remember correctly, the pooling was max. Uh, so if we had the filter coming in and they did the multiplication on there and we have a one and maybe a two here and another one here and a three here, three is the max. And so out of all of these, you then create an array that would be three. And if the max is over here, two or whatever it is, that's what goes into the pooling. And what's going on in our pooling? Uh, so again, we're reducing that data down. We're reducing it down as small as we can. And then finally, we're going to flatten it out into a 9:06:44 single array. And that goes into our fully connected layer. And you can see that here in the code right here, we're going to create our normal full layer. Um, so at some point we're going to take from our pooling layer. This will go into some kind of flattening process and then that will be fed into the full the different layers going in down here. Um, and so we have our input size. You'll see our input layer get shape which is just going to get the shape for whatever is coming in. Uh and then input size initial weights is also based on uh the input layer coming in. And the input size down here is based on the input layer shape. So we're just going to already use the shape and already have our size coming in. And of course uh you have to make sure you init the bias. Always put your bias on there. And we'll do that based on the size. So this will return TF.mmatmo input layer W plusB. This is just a normal full layer. That's what this means right down here. That's what we're going to return. So that was a lot of steps we went through. Let's go ahead and run that. So those are all loaded in there. And let's go ahead and uh create 9:07:46 the layers. Let's see what that looks like. Now that we've done all the heavy lifting and everything, uh we get to do all the easy part. Let's go ahead and create our layers. We'll create a convolution layer one and two. two different convolutional layers and then we'll take that and we'll flatten that out and create a a reshape pooling in there for our reshape and then we'll have our full uh layer at the end. So, let's start by creating our first uh convolutional layer. Then we come in here and let me just run that real quick. And I want you to notice on here the three and the 32. This is important because coming into this convolutional layer, we have three different channels and 32 pixels each. Uh, so that has to be in there. The four and four you can play with. This is your filter size. So if you remember, you have a filter and you have your image and the filter slowly steps over and filters out this image depending on what your step is. For this particular setup, 44 is just fine. That should work pretty good for 9:08:47 what we're doing and for the size of the image. And then of course at the end once you have your convolutional layer set up, you also need to pool it. And you'll see that the pooling is automatically set up so that it would see the different shape based on what's coming in. So here we have max tool by 2 by two and we put in the convolutional one that we just created. The convolutional layer we just created goes right back into it. And that right up here as you can see is the X is coming in from here. So it knows to look at the first model and set the the data accordingly. Set that up uh so it matches. And we went ahead and ran this already. I think I ran it. Let me go and run it again. And if we're going to do one layer, let's go ahead and do a second layer down here. And it's h we'll call it convo 2. It's also a convolutional layer on this. And you'll see that we're feeding convolutional one in the pooling. So it goes from convolutional one into convolutional one pooling. From convolutional one pooling into convolutional two, and then from convolutional two into convolutional two pooling. And we'll go ahead and take 9:09:48 this and run this. So these variables are all loaded into memory. And for our flatten layer, uh, let's go ahead and we'll do, uh, since we have 64 coming out of here and we have, uh, 4x4 going in, let's do 8x 8x 64. So, let's do 4,096. This is going to be the flat layer. So, that's how many bits are coming through on the flat layer. And we'll reshape this. So, we'll reshape our uh, Convo 2 pooling. And that will feed into here, the Convo 2 pooling. And then we're going to set it up as a single layer that's 4,096 in size. That's what that means there. We'll go ahead and run this. So we've now created this variable, the convo to flat. And then we have our first full layer. This is the final uh neural network where we have the flat layer going in. And we're going to again use the uh relu for our uh setup on there on a neural network for evaluation. And you'll notice that we're going to create our first full layer, our normal full layer. That's our definition. So, we created that. That's 9:10:49 creating the normal full layer. And our input for the data comes right here from the this goes right into it. Uh the convo 2 flat. So, this tells it how big the data is. And we're going to have it come out. It's going to have uh 1024. That's how big the layer is coming out. We'll go ahead and run this. So, now we have our full layer one. And with the full layer one, we want to also define the full one dropout to go with that. So our full layer one comes in uh keep probability equals hold probability. Remember we created that earlier. And the full layer one is what's coming into it. And this is going backwards and training the data. We're not training every weight. We're only training a percentage of them each time which helps get rid of the bias. So let me go ahead and run that. And uh finally we'll go ahead and create a y predict which is going to equal the normal full one dropout and 10 cuz we have 10 labels in there. Now in this neural network, we could have added additional layers. That would be another option to play with. You can also play with instead of 1024, 9:11:49 you can use other numbers for the way that sets up and what's coming out going into the next one. We're only going to do just the one layer and the one layer dropout. And you can see if we did another layer, it'd be really easy just to feed in the full one dropout into full layer two. And then full layer two dropout would have full layer two feed into it. And then you'd switch that here for the Y prediction. For right now, this is great. this particular data set is tried and true and we know that this will work on it. And if we just type in y predict and we run that uh we'll see that this is a tensor object uh shape question mark 10 dtype 32. A quick way to double check what we're working on. So now we've got all of our uh we've done a setup all the way to the y predict which we just did. Uh we want to go ahead and apply the loss function and make sure that's set up in there. uh create the optimizer and then uh train our optimizer and create a variable to initialize all the global TF variables. So before we dive in to the um loss 9:12:51 function, let me point out one quick thing or just kind of a recap over a couple things. And that is when we're playing with this these setups um we pointed out up here we can change the 44 and use different numbers there. They change your outcome. So depending on what numbers you use here will have a huge impact on how well your model fits. And that's the same here with the 1024. Also, this is also another number that if you continue to raise that number, you'll get um possibly a better fit. You might overfit. And if you lower that number, you'll use less resources. And generally, you want to use this in um the exponential growth. And exponential being 2 4 8 16. And in this case, the next one down would be 512. You can use any number there, but those would be the ideal numbers uh when you look at this data. So the next step in all this is we need to also create uh a way of tracking how good our model is. And we're going to call this a loss function. And so we're going to create a cross entropy loss function. And so before we discuss 9:13:54 exactly what that is, let's take a look and see what we're feeding it. Uh we're going to feed it our labels. And we have our true labels and our prediction labels. Uh so coming in here as we're the two different uh variables we're sending in or the two different probability distributions is one that we know is true and what we think it's going to be. Now this function right here when they talk about cross entropy uh in information theory the cross entropy between two probability distributions over the same underlying set of events measures the average number of bits needed to identify an event drawn from the set. That's a mouthful. Uh really we're just looking at the amount of error in here. How many of these are correct and how many of these um are incorrect. So how much of it matches? And we're going to look at that. We're just going to look at the average. That's what the mean the reduced to the means here. So we're looking at the average error on this. And so the next step is we're going to take the error. We want to know uh our cross entropy or our loss function. How much loss we have. That's going to be 9:14:54 part of how we train the model. So when you know what the loss is and we're training it, you feed that back into the back propagation setup. And so we want to go ahead and optimize that. Here's our optimizer. We're going to create the optimizer using an atom optimizer. Remember, there's a lot of different ways of optimizing the data. Atom's the most popular used. Uh so our optimizer is going to equal the TF train atom optimizer. If you don't remember what the learning rate is, let me just pop this back into here. Here's our learning rate. when you have your weights, you have all your weights and your different nodes that are coming out. Here's our node coming out. Um, and it has all its weights and then the error is being pro sent back through in reverse on our neural network. So, we take this error and we adjust these weights based on the different formulas. In this case, the atom formula is what we're using. We don't want to just adjust them completely. We don't want to change this weight so it exactly fits the data coming through because if we made that kind of adjustment, it's going to be biased to whatever the last data we sent through is. Instead, we're going to 9:15:53 multiply that by 0.001 and make a very small shift in this weight. So our delta W is only 0.001 of the actual delta W of the full change we're going to compute from the atom. And then we want to go ahead and train it. So our training or set up a training uh uh variable or function. And this is going to equal our optimizer minimize cross entropy. And we make sure we go ahead and run this. So it's loaded in there. And then we're almost ready to train our model. But before we do that, we need to create one more um variable in here. And we're going to create a variable to initialize all the global TF variables. And when we look at this um the TF global variable initializer, this is a TensorFlow um object. It goes through there and it looks at all our different setup that we have going under our TensorFlow and then initializes those variables. Uh so it's kind of like a magic wand because it's all hidden in the back end of TensorFlow. All you need to know about this is that you have to have the initialization on there which is an operation. Um and you have to run that 9:16:55 once you have your setup going. So we'll go ahead and run this piece of code and then we're going to go ahead and train our data. So let me run this. So it's loaded up there. And so now we're going to go ahead and run the model by creating a graph session. Graph session is a TensorFlow term. So you'll see that coming up. It's one of the things that throws me because I always think of graphics and spark and graph as just general graphing. Uh but they talk about a graph session. So we're going to go ahead and run the model and let's go ahead and walk through this uh what's going on here. And let's paste this data in here. And here we go. So, we're going to start off with a with a TF session as cess. So, that's our actual TF session we've created. Uh, so we're right here with the TF uh session. Our session we're creating, we're going to run TF global variable initializer. So, right off the bat, we're initializing our variables here. Uh, and then we have for I in range 500. So, what's going on here? Remember 500, we're going to break the data up and we're going to batch it 9:17:56 in at 500 points each. We've created our session run. So we're going to do with TF session as session right here. We've created our variable session. Uh and then we're going to run and we're going to go ahead and initialize it. So we have our TF global variables initializer that we created. U that initializes our our session in here. The next thing we're going to do is we're going to go for I in range of 500 batch equals ch.next batch. So if you remember correctly, this is loading up um 100 pictures at a time and uh this is going to loop through that 500 times. So we are literally doing uh what is that? Uh 500 * 100 is uh 50,000. So that's 50,000 pictures we're going to process right there. In the first process is we're going to do a session run. We're going to take our train. We created our train variable or optimizer in there. We're going to feed it the dictionary. Uh we had our feed dictionary that we created and we have x equals batch zero coming in y true batch one hold the probability 9:18:58 0.5 and then just so that we can keep track of what's going on. We're going to every 100 steps we're going to run a print. So currently on step format accuracy is um and we're going to look at matches equals tf equal tf argument y prediction one tf.org arg max y true comma one. So we're going to look at this is how many matches it has. And here our ACC uh all we're doing here is we're going to take the matches how many matches they have. It creates it generates a chart. We're going to convert that to float. That's what the TF cast does. And then we just want to know the average. We just want to know the average of the um accuracy. And then we'll go ahead and print that out. Uh print session run accuracy feed dictionary. So it takes all this and it prints out our accuracy on there. So, let's go ahead and take this. Oops, screens there. Let's go ahead and take this and let's run it. And this is going to take a little bit to run. Uh, so let's see what happens on my old laptop. And we'll see here that we have our current uh we're currently on step zero. 9:20:01 It takes a little bit to get through the accuracy. And this will take just a moment to run. We can see that on our step zero, it has an accuracy of 0.1 or 0 1028. Um, and as it's running, we'll go ahead. that you don't need to watch it run all the way, but uh this accuracy is going to change a little bit up and down. So, we've actually lost some accuracy during our step two, but we'll see how that comes out. Let's come back after we run it all the way through and see how the different steps come out. Was actually reading that backwards. Uh the way this works is the closer we get to one, the more accuracy we have. Uh so, you can see here we've gone from a 0.1 to a 39. Um, and we'll go ahead and pause this and come back and see what happens when we're done with the full run. All right, now that we've uh prepared the meal, got it in the oven, and pulled out my finished dish here. If you've ever watched uh any of the old cooking shows, let's discuss a little bit about this accuracy going on here. And how do you interpret that? We've done a couple things. First, we've defined accuracy. Um, the reason I got 9:21:01 it backwards before is you have uh loss or accuracy. And with loss, you'll get a graph that looks like this. It goes Oops, that's an S, by the way. There we go. You get a graph that curves down like this. And with accuracy, you get a graph that curves up. This is how good it's doing. Now, in this case, uh, one is supposed to be really good accuracy. That mean it gets close to one, but it never crosses one. So, if you have an accuracy of one, that is phenomenal. Um, in fact, that's pretty much unp, you know, unheard of. And the same thing with loss. If you have a loss of zero, that's also unheard of. The zero is actually on this this axis right here as we go in there. So how do we interpret that? Because you know if I was looking at this and I go oh 0.51 that's uh 51%. You're doing 5050. No this is not percentage. Let me just put that in there. It is not percentage. Uh this is logarithmic. What that means is that 2 is twice as good as 0.1. And uh when we see 04 that's twice as good as 2. real 9:22:04 way to convert this into a percentage. You really can't say this is is a direct percentage conversion. What you can do though is in your head, if we were to give this a percentage, uh we might look at this as uh 50% we're just guessing equals 0.1. And if 50% roughly equals 0.1, that's where we started up here at the top. Remember at the top here, here's our 1028. the accuracy of 50% then 75% is about 0.2 and so on and so on. Don't quote those numbers because that doesn't work that way. They say that if you have 95 that's pretty much saying 100%. And if you have uh anywhere between you'd have to go look this up. Let me go and remove all my drawings there. Uh so the magic number is 0.5. We really want to be over a.5 in this whole thing. and we have uh both 0504 remember this is accuracy. If we were looking at loss then we'd be looking the other way but 0.0 you know 9:23:05 instead of how high it is we want how low it is. Uh but with accuracy being over a.5 is pretty valid. That means this is pretty solid. And if you get to a 0.95 then it's a direct correlation. That's what we're looking for here in these numbers. And you can see we finished with this model at 0 5135. So still good. Um, and if we look at uh when they ran this in the other end, remember there's a lot of randomness that goes into it when we see the weights, uh, they got 0.5251. So, a little better than ours, but that's fine. You'll find your own uh comes up a little bit better or worse depending on uh just that randomness. And so, we've gone through the whole model. We've created, we train the model, and we've also gone through on every 100th run to test the model to see how accurate it is. Welcome to the RNN tutorial. That's the recurrent neural network. So we talk about a feed forward neural network. In a feed forward neural network, information flows only in the forward direction from the input nodes through the hidden layers if any and to the output nodes. There are no cycles or 9:24:06 loops in the network. And so you can see here we have our input layer. I was talking about how it just goes straight forward into the hidden layers. So each one of those connects and then connects to the next hidden layer, connects to the output layer. And of course we have a nice simplified version where it has a predicted output. And they refer to the input as X a lot of times and the output as Y. Decisions are based on current input, no memory about the past, no future scope. Why recurrent neural network? Issues in feed forward neural network. So one of the biggest issues is because it doesn't have a scope of memory or time. A feed forward neural network doesn't know how to handle sequential data. Uh it only considers only the current input. So if you have a series of things and because three points back affects what's happening now and what your output affects what's happening. That's very important. So whatever I put as an output is going to affect the next one. Um a feed forward doesn't look at any of that. It just looks at this is what's coming in and it cannot memorize previous inputs. So it doesn't have that list of inputs coming in. Solution to feed forward neural 9:25:04 network. You'll see here where it says recurrent neural network and we have our X on the bottom going to H going to Y. That's your feed forward. uh but right in the middle it has a value C. So there's a whole another process. So it's memorizing what's going on in the hidden layers and the hidden layers as they produce data feed into the next one. So your hidden layer might have an output that goes off to Y. Uh but that output goes back into the next prediction coming in. What this does is this allows it to handle sequential data. It considers the current input and also the previously received inputs. And if we're going to look at general drawings and um solutions, we should also look at applications of the RNN. Image captioning. RNN is used to caption an image by analyzing the activities present in it. A dog catching a ball in midair. Uh that's very tough. I mean, you know, we have a lot of stuff that analyzes images of a dog and they of a ball, but it's able to add one more feature in there that's actually catching the ball in midair. Time series prediction. anytime series problem like 9:26:06 predicting the prices of stocks in a particular month can be solved using RNN and we'll dive into that in our use case and actually take a look at some stock. One of the things you should know about analyzing stock today is that it is very difficult and if you're analyzing the whole stock, the stock market at the New York Stock Exchange in the US produces somewhere in the neighborhood if you count all the individual trades and fluctuations by the second um it's like 3 terabytes a day of data. So, we're only going to look at one stock. Just analyzing one stock is really tricky. In here will give you a little jump on that. So, that's exciting, but don't expect to get rich off of it immediately. Another application of the RNN is natural language processing. Text mining and sentiment analysis can be carried out using RNN for natural language processing. And you can see right here the term natural language processing when you stream those three words together is very different than I if I said processing language naturally. So the time series is very important when we're analyzing sentiments. It can change the whole value of a sentence 9:27:08 just by switching the words around. Or if you're just counting the words, you might get one sentiment where if you actually look at the order they're in, you get a completely different sentiment. When it rains, look for rainbows. When it's dark, look for stars. Both of these are positive sentiments and they're based upon the order of which the sentence is going in. Machine translation. Given an input in one language, RNN can be used to translate the input into a different languages as output. I myself am very linguistically challenged. But if you study languages and you're good with languages, you know right away that if you're speaking English, you would say big cat. And if you're speaking Spanish, you would say cat big. So that translation is really important to get the right order to get uh there's all kinds of parts of speech that are important to know by the order of the words here. This person is speaking in English and getting translated. And you can see here a person is speaking in English in this little diagram. I guess that's denoted by the flags. I have a flag. I own it. No. Um, but they're speaking in English and it's getting 9:28:08 translated into Chinese, Italian, French, German, and Spanish languages. Some of the tools coming out are just so cool. So, somebody like myself who's very linguistically challenged, I can now travel into worlds I would never think of because I can have something translate my English back and forth readily and I'm not stuck with a communication gap. So, let's dive into what is a recurrent neural network. Recurrent neural network works on the principle of saving the output of a layer and feeding this back to the input in order to predict the output of the layer. Sounds a little confusing. When we start breaking it down, it'll make more sense. And usually we have a propagation forward neural network with the input layers, the hidden layers, the output layer. With the recurrent neural network, we turn that on its side. So here it is. And now our X comes up from the bottom into the hidden layers into Y. And they usually draw it very simplified X to H with C as a loop. A to Y where A, B, and C are the perimeters. A lot of times you'll see this kind of drawing in here. Digging closer and 9:29:09 closer into the H and how it works. Going from left to right, you'll see that the C goes in and then the X goes in. So the X is going upward bound and C is going to the right. A is going out and C is also going out. That's where it gets a little confusing. So here we have X in uh C in and then we have Y out and C out. and C is based on ht minus one. So our value is based on the y and the h value are connected to each other. They're not necessarily the same value because h can be its own thing. And usually we draw this or we represent it as a function h of t equals a function of c where h of t minus one. That's the last h output and x of t going in. So it's the last output of h combined with the new input of x. Uh where ht is the new state. FC is a function with the parameter c. That's a common way of denoting it. Uh ht minus one is the old state coming out and then x of t is an input vector at time of step t. Well, we need to cover types of recurrent neural 9:30:11 networks. And so the first one is the most common one which is a one one single output. One neural network is usually known as a vanilla neural network used for regular machine learning problems. Why? Because vanilla is usually considered kind of a just a real basic flavor. But because it's a very basic a lot of times they'll call it the vanilla neural network uh which is not the common term but it is you know like kind of a slang term people will know what you're talking about usually if you say that. Then we run one to many. So you have a single input and you might have a uh multiple outputs in this case uh image captioning as we looked at earlier where we have not just looking at it as a dog but a dog catching a ball in the air. And then you have many to one network takes in a sequence of inputs. examples, sentiment analysis, where a given sentence can be classified as expressing positive or negative sentiments. And we looked at that as we were discussing if it rains, look for a rainbow. So positive sentiment where rain might be a negative sentiment if you were just adding up the words in there. And then of course, if 9:31:13 you're going to do a one, many to one, one to many, there's many to many networks takes in a sequence of inputs and generates a sequence of outputs. Example, machine translation. So we have a lengthy sentence coming in in English and then going out in all the different languages. Uh you know just a wonderful tool very complicated set of computations. You know if you're a translator you realize just how difficult it is to translate into different languages. One of the biggest things you need to understand when we're working with this neural network is what's called the vanishing gradient problem. While training an RNN, your slope can be either too small or very large. And this makes training difficult. when the slope is too small, the problem is known as vanishing gradient. And you'll see here they have a nice uh image loss of information through time. So if you're pushing not enough information forward, that information is lost and then when you go to train it, you start losing the third word in the sentence or something like that or it doesn't quite follow the full logic of what you're working on. Exploding gradient problem. Oh, this is 9:32:14 one that runs into everybody when you're working with this particular neural network. when the slope tends to grow exponentially instead of decaying. This problem is called exploding gradient issues in gradient problem. Long training time, poor performance, bad accuracy. And I'll add one more in there. Uh your computer, if you're on a a lower-end computer testing out a model, will lock up and give you the memory error. Explaining gradient problem. Consider the following two examples to understand what should be the next word in the sequence. The person who took my bike and blank a thief. the students who got into engineering with blank from Asia. And you can see in here we have our x value going in. We have the previous value going forward. And then you back propagate the error like you do with any neural network. And as we're looking for that missing word, maybe we'll have the person took my bike and blank was a thief. And the student who got into engineering with a blank were from Asia. Consider the following example. The person who took the bike. So we'll go 9:33:14 back to the person who took the bike was blank a thief. In order to understand what would be the next word in the sequence, the RNN must memorize the previous context, whether the subject was singular noun or a plural noun. So, was a thief is singular. The student who got into engineering, well, in order to understand what would be the next word in the sequence, the RNN must memorize the previous context whether the subject was singular noun or a plural noun. And so, you can see here the students who got into engineering with blank were from Asia. It might be sometimes difficult for the error to back propagate to the beginning of the sequence to predict what should be the output. So when you run into the gradient problem, we need a solution. The solution to the gradient problem. First, we're going to look at exploding gradient where we have three different solutions depending on what's going on. One is identity initialization. So the first thing we want to do is see if we can find a way to minimize the identities coming in instead of having it identify everything just the important information we're looking at. 9:34:16 Next is to truncate the back propagation. So instead of having uh whatever information it's sending to the next series, we can truncate what it's sending, we can lower that particular uh set of layers, make those smaller. And finally is a gradient clipping. So when we're training it, we can clip what that gradient looks like and narrow the training model that we're using. When you have a vanishing gradient, the option problem, uh we can take a look at weight initialization. Very similar to the identity, but we're going to add more weights in there so it can identify different aspects of what's coming in better. Choosing the right activation function, that's huge. So we might be activating based on one thing and we need to limit that. We haven't talked too much about activation functions, so we'll look at that just minimally. uh there's a lot of choices out there. And then finally, there's long short-term memory networks, the LSTMS, and we can make adjustments to that. So, just like we can clip the gradient as it comes out, we can also um expand on that. We can increase the memory network, the 9:35:17 size of it, so it handles more information. And one of the most common problems in today's uh setup is what they call long-term dependencies. Suppose we try to predict the last word in the text. The clouds are in the and you probably said sky. Here we do not need any further context. It's pretty clear that the last word is going to be sky. Suppose we try to predict the last word in the text. I have been staying in Spain for the last 10 years. I can speak fluent. Maybe you said Portuguese or French. No, you probably said Spanish. The word we predict will depend on the previous few words in context. Here we need the context of Spain to predict the last word in the text. It's possible that the gap between the relevant information and the point where it is needed to become very large. LSTMs help us solve this problem. So the LSTMs are a special kind of recurrent neural network capable of learning long-term dependencies. Remembering information for long periods of time is their default behavior. All recurrent neural 9:36:18 networks have the form of a chain of repeating modules of neural network connections. In standard RNNs, this repeating module will have a very simple structure such as a single tangent H layer. LSTMs's also have a chain-like structure, but the repeating module has a different structure. Instead of having a single neural network layer, there are four interacting layers communicating in a very special way. LSTMs are a special kind of recurrent neural network capable of learning long-term dependencies, remembering information for long periods of time as their default behavior. LSTMS's also have a chain-like structure, but the repeating module has a different structure. Instead of having a single neural network layer, there are four interacting layers communicating in a very special way. As you can see, the deeper we dig into this, the more complicated the graphs get in here. I want you to note that you have x of t minus one coming in, you have x of t coming in, and you have x at t + one, and you have h of t minus one, and h of 9:37:18 t coming in, and h of t + one going out. And of course uh on the other side is the output a. Um in the middle we have our tangent h but it occurs in two different places. So not only when we're computing the x of t + one are we getting the tangent h from x of t but we're also getting that value coming in from the x of t minus one. So the short of it is as you look at these layers, not only does it does the propagate through the first layer goes into the second layer back into itself, but it's also going into the third layer. So now we're kind of stacking those up and this can get very complicated as you grow that in size. It also grows in memory too and in the amount of resources it takes. Uh but it's a very powerful tool to help us address the problem of complicated long sequential information coming in like we were just looking at in the sentence. And when we're looking at our long shortterm memory network uh there's three steps of processing in the LSTMs that we look at. The first one is we want to forget irrelevant parts of 9:38:18 the previous state. You know, a lot of times like you know is, as in, a unless we're trying to look at whether it's a plural noun or not, they don't really play a huge part in the language. So, we want to get rid of them. Then, selectively update cell state values. So, we only want to update the cell state values that reflect what we're working on. And finally, we want to put only output certain parts of the cell state. So, whatever is coming out, we want to limit what's going out, too. And let's dig a little deeper into this. Let's just see what this really looks like. Uh so step one decides how much of the past it should remember. First step in the LSTM is to decide which information to be omitted in from the cell in that particular time step. It is decided by the sigmoid function. It looks at the previous state h of t minus one and the current input x of t and computes the function. So you can see over here we have a function of t equals the sigmoid function of the weight of f the h at t minus one and then x of t 9:39:18 plus of course you have a bias in there with any of our neural networks. So we have a bias function. So f of t equals forget gate decides which information to delete that is not important from the previous time step. Considering an STM is fed with the following inputs from the previous and present time step. Alice is good in physics. John on the other hand is good in chemistry. So previous output, John plays football well. He told me yesterday over the phone that he had served as a captain of his college football team. That's our current input. So as we look at this, the first step is the forget gate realizes there might be a change in context after encounting the first full stop. Compares with the current input sentence of x. So we're looking at that full stop and then compares it with the input of the new sentence. The next sentence talks about John. So the information on Alice is deleted. Okay, that's important to know. So we have this input coming in. And if we're going to continue on with John, then that's going to be the primary information we're looking at. The position of the subject is vacated and is assigned to 9:40:20 John. And so in this one, we've seen that we've weeded out a whole bunch of information and we're only passing information on John since that's now the new topic. So step two is then to decide how much should this unit add to the current state. In the second layer, there are two parts. One is a sigmoid function and the other is a tangent h. In the sigmoid function, it decides which values to let through zero or one. Tangent h function gives a weightage to the values which are passed deciding their level of importance minus1 to one. And you can see the two formulas that come up. Uh the i of t equals the sigmoid of the weight of i h of t minus one x of t plus the bias of i. And the C of T equals the tangent of H of the weight of C of H of T minus 1 X of T plus the bias of C. So our I of T equals the input gate determines which information to let through based on its significance in the current time step. If this seems a little complicated, don't worry cuz a lot of the programming is already done when we get to the case study. Understanding though that this is 9:41:21 part of the program is important when you're trying to figure out these what to set your settings at. You should also note when you're looking at this, it should have some semblance to your forward propagation neural networks where we have a value assigned to a weight plus a bias. Very important steps in any of the neural network layers, whether we're propagating into them the information from one to the next or we're just doing a straightforward neural network propagation. Let's take a quick look at this what it looks like from the human standpoint. Um, as I step out in my suit again, consider the current input at exit. John plays football well. He told me yesterday over the phone that he had served as a captain of his college football team. That's our input. Input gate analysis the important information. John plays football and he was a captain of his college team is important. He told me over the phone yesterday is less important. Hence, it is forgotten. This process of adding some new information can be done via the input gate. Now, this example is as a human form, and we'll look at training this stuff in 9:42:22 just a minute. Uh, but as a human being, if I wanted to get this information from a conversation, maybe it's a Google voice listening in on you or something like that. Um, how do we weed out the information that he was talking to me on the phone yesterday? Well, I don't want to memorize that he talked to me on the phone yesterday. Or maybe that is important, but in this case, it's not. I want to know that he was the captain of the football team. I want to know that he served. I want to know that John plays football and he was the captain of the college football team. Those are the two things that I want to take away as a human being. Again, we measure a lot of this from the human viewpoint and that's also how we try to train them so we can understand these neural networks. Finally, we get to step three. Decides what part of the current cell state makes it to the output. The third step is to decide what will be our output. First, we run a sigmoid layer which decides what parts of the cell state make it to the output. Then we put the cell state through the tangent h to push the values to be between minus1 and one and multiply it by the output of the 9:43:19 sigmoid gate. So when we talk about the output of t, we set that equal to the sigmoid of the weight of zero of the h of t minus one back one step in time by the x of t plus of course the bias. The h of t equals the out of t times the tangent of the tangent h of c of t. So our o equals the output gate allows the passedin information to impact the output in the current time step. Let's consider the example to predicting the next word in the sentence. John played tremendously well against the opponent and one for his team. For his contributions, brave blank was awarded player of the match. There could be a lot of choices for the empty space. Current input brave is an adjective. Adjectives describe a noun. John could be the best output after brave. Thumbs up for John. Awarded player of the match. And if you were to pull just the nouns out of the sentence, team doesn't look right because that's not really the subject. We're talking about contributions. Uh you know, brave contributions or brave team, brave 9:44:20 player, brave match. Um so you look at this and you can start to train this these this neural network. So it starts looking at and goes, "Oh no, John is what we're talking about. So brave is an adjective. Jon's going to be the best output." and we give John a big thumbs up. And then of course we jump into my favorite part, the case study. Use case implementation of LSTM. Let's predict the prices of stocks using the LSTM network based on the stock price data between 2012 2016. We're going to try to predict the stock prices of 2017. And this will be a narrow set of data. We're not going to do the whole stock market. It turns out that the New York Stock Exchange generates roughly three terabytes of data per day. That's all the different trades up and down of all the different stocks going on and each individual one uh second to second or nancond to nanocond. Uh but we're going to limit that to just some very basic fundamental information. So don't think you're going to get rich off this today. But you at least you can give an eye you 9:45:21 can give a step forward in how to start processing something like stock prices. a very valid use for machine learning in today's markets. Use case implementation of LSTM. Let's dive in. We're going to import our libraries. We're going to import the training set and uh get the scaling going. Um now, if you watch any of our other tutorials, a lot of these pieces should start to look very familiar because it's very similar setup. Uh but let's take a look at that. And um just a reminder, we're going to be using Anaconda, the Jupiter notebook. So here I have my Anaconda navigator. When we go under environments, I've actually set up a KAS Python 3.6. I'm in Python 3.6. And u nice thing about Anaconda, especially the newer version. I remember a year ago messing with Anaconda in different versions of Python and different environments. Um Anaconda now has a nice interface. Um and I have this installed both on a Ubuntu Linux machine and on Windows, so it works fine on there. You can go in here and open a terminal 9:46:22 window. And then in here, once you're in the terminal window, this is where you're going to start uh installing using pip to install your different modules and everything. Now, we've already pre-installed them, so we don't need to do that in here. Uh but if you don't have them installed in your particular environment, you'll need to do that. And of course, you don't need to use the Anaconda or the Jupiter. You can use whatever favorite Python IDE you like. I'm just a big fan of this because it keeps all my stuff separate. You can see on this machine I have specifically installed one for KAS since we're going to be working with KAS under TensorFlow. We go back to home. I've gone up here to application and that's the environment I've loaded on here and then we'll click on the launch Jupyter notebook. Now I've already in my Jupyter notebook um have set up a lot of stuff so that we're ready to go. Kind of like uh Martha Stewart's in the old cooking shows. We want to make sure we have all our tools for you so you're not waiting for them to load. And uh if we go up here to where it says new, you can see where you can um create a new Python 3. That's what we did here underneath the setup. 9:47:22 So it already has all the modules installed on it. And I'm actually renamed this. So if you go under file, you can rename it. We I'm calling it RNN stock. And let's just take a look at start diving into the code. Let's get into the exciting part. Now we've looked at the tool. And of course, you might be using a different tool, which is fine. Uh let's start putting that code in there and seeing what those imports and uploading everything looks like. Now, first half is kind of boring when we hit the run button because we're going to be importing numpy as np that's uh uh the number python which is your numpy array and the mattplot library. So, we're going to do some plotting at the end and our pandas for our data set. Our pandas is pd. And when I hit run, uh it really doesn't do anything except for load those modules. Just a quick note, let me just do a quick uh draw here. Whoops. Shift alt. There we go. You'll notice when we're doing this setup, if I was to divide this up, oops, I'm gonna actually um let's overlap these. Here we go. Uh this first part that we're going to do is 9:48:24 our data prep. A lot of prepping involved. Um in fact, depending on what your system is, since we're using Kass, I put an overlap here. Uh but you'll find that almost maybe even half of the code we do is all about the data prep. And the reason I overlap this with uh KAS, let me just put that down because that's what we're working in. Uh is because KAS has like their own preset stuff. So it's already pre-built in which is really nice. So there's a couple steps a lot of times that are in the KAS setup. Uh we'll take a look at that to see what comes up in our code as we go through and look at stock. And then the last part is to evaluate. And if you're working with um shareholders or uh you know classroom whatever it is you're working with uh the evaluate is the next biggest piece. Um so the actual code here cross is a little bit more but when you're working with uh some of the other packages you might have like three lines that might be it all your stuff is in your pre-processing in your data. Since cross 9:49:25 has is is cutting edge and you load the individual layers, you'll see that there's a few more lines here and cross is a little bit more robust. And then you spend a lot of times uh like I said with the evaluate. You want to have something you present to everybody else to say, hey, this is what I did. This is what it looks like. So let's go through those steps. This is like a kind of a just general overview and let's just take a look and see what the next set of code looks like. And in here we have a data set train and it's going to be read using the PD or pandas read CSV and it's a Google stockpric train.csv. And so under this we have training set equals data set train.loation and we've kind of sorted out part of that. So what's going on here? Let's just take a look at that. Let's let's look at the actual file and see what's going on there. Now, if we look at this, uh, ignore all the extra files on this. Um, I already have a train and a test set where it's sorted out. This is important to notice because a lot of times we do that as part of the pre-processing of the data. We take 20% 9:50:25 of the data out so we can test it and then we train the rest of it. That's what we use to create our neural network. That way, we can find out how good it is. Uh, but let's go ahead and just take a look and see what that looks like as far as the file itself. And I went ahead and just opened this up in a basic word pad text editor just so we can take a look at it. Certainly you can open up in Excel or any other kind of spreadsheet. Um and we note that this is a commaepparated variables. We have a date uh open, high, low, close, volume. This is the standard stuff that we import into our stock with the most basic set of information you can look at in stock. It's all free to download. Um in this case we downloaded it from uh Google. That's why we call it the Google stock price. Um and it specifically is Google. This is the Google stock values from uh as you can see here we started off at 1320. So when we look at this first setup up here uh we have a data set train equals pd_csv. And if you noticed on the original frame uh let me just go back there. They had 9:51:28 it set to home Ubuntu downloads Google stock price train. I went ahead and changed that because we're in the same file where I'm running the code. So, I've saved this particular Python code and I don't need to go through any special paths or have the full path on there. And then, of course, we want to take out um certain values in here. And you're going to notice that we're using um our data set and we're now in pandas. Uh so, pandas basically it looks like a spreadsheet. Um, and in this case, we're going to do I location, which is going to get specific locations. The first value is going to show us that we're pulling all the rows in the data. And the second one is we're only going to look at columns one and two. And if you remember here from our data, as we switch back on over columns, we always start with zero, which is the date. And we're going to be looking at open and high, which would be one and two. I'll just label that right there so you can see. Now, when you go back and do 9:52:30 this, you certainly can extrapolate and do this on all the columns. Um, but for the example, let's just limit a little bit here so that we can focus on just some key aspects of stock. And then we'll go up here and run the code. And uh, again, I said the first half is very boring. Whenever we hit the run button, it doesn't do anything because we're still just loading the data and setting it up. Now that we've loaded our data, we want to go ahead and scale it. We want to do what they call feature scaling. And in here, we're going to pull it up from the SKLearn or the SK kit pre-processing import minm max scaler. And when you look at this, you got to remember that um biases in our data, we want to get rid of that. So if you have something that's like a really high value, um let's just draw a quick graph. And I have something here like the maybe the stock has a value one stock has a value of a 100 and another stock has a value of five. Um you start to get a bias between different stocks. And so when we do this 9:53:32 we go ahead and say okay 100 is going to be the max and five is going to be the min and then everything else goes and then we change this. So we just squish it down. I like the word squish. So it's between one and zero. So 100 equals 1 or 1 equals 100 and 0 equals 5. And you can just multiply. It's usually just a simple multiplication. We're using uh multiplication. So it's going to be uh minus5 and then 100 divided or 95 divided by one. So or whatever value is is divided by 95. And uh once we've actually created our scale, we've telling it's going to be from 0 to one. We want to take our training set and we're going to create a training set scaled. And we're going to use our scaler SC and we're going to fit we're going to fit and transform the training set. Uh so we can now use the SC this this particular object. We'll use it later on our testing set because remember we have to also scale that when we go to test our uh model and see how it works. And we'll go ahead and click on the run again. Uh it's not going to 9:54:34 have any output yet because we're just setting up all the variables. Okay. Okay, so we pasted the data in here and we're going to create the data structure with the 60 time steps and output. First note, we're running 60 time steps and that is where this value here also comes in. So the first thing we do is we create our X train and Y train variables and we set them to an empty Python array. Very important to remember what kind of array we're in and what we're working with. And then we're going to come in here. We're going to go for I in range 60 to 1258. There's our 60 60 time steps. And the reason we want to do this is as we're adding the data in there, there's nothing below the 60. So if we're going to use 60 time steps, uh we have to start at 60 because it includes everything underneath of it. Otherwise, you'll get a pointer error. And then we're going to take our X train and we're going to append training set scaled. This is a scaled value between 0 and one. And then as I is equal to 60, this value is going to be um 60 - 60 is 9:55:37 zero. So this actually is 0 to I. So it's going to be 0 to 60, 1 to 61. Let me just circle this part right here. 1 to 61, uh 2 to 62, and so on and so on. And if you remember, I said 0 to 60. That's incorrect because it does not count. Remember, it starts at zero. So this is a count of 60. So it's actually 59. Important to remember that as we're looking at this. And then the second part of this that we're looking at. So if you remember correctly, here we go. we go from uh 0 to 59 of i and then we have a comma a zero right here. And so finally we're just going to look at the open value. Now I know we did put it in there for one to two. Um if you remember correctly it doesn't count the second one. So it's just the open value we're looking at just open. Um and then finally we have ytrain.append training set i to zero. And if you remember correctly I to or I comma zero. If you remember correctly, this is 0 to 59. So there's 60 values in it. Uh so 9:56:39 when we do I down here, this is number 60. So we're going to do this is we're creating an array and we have 0 to 59. And over here we have number 60 which is going into the Y train. It's being appended on there. And then this just goes all the way up. So this is down here is uh uh 0 to 59 and we'll call it 60 since that's the value over here and it goes all the way up to 12 58. That's where this value here comes in. That's the length of the data we're loading. So we've loaded two arrays. We loaded one array that has uh which is filled with arrays from 0 to 59. And we loaded one array which is just the value. And what we're looking at, you want to think about this as a time sequence. Uh here's my open open open. What's the next one in the series? So we're looking at the Google stock and each time it opens, we want to know what the next one uh 0 through 59, what's 60? 1 through 60, what's 61? 2 through 62, what's 62? And 9:57:42 so on and so on going up. And then once we've loaded those in our for loop, we go ahead and take xra and yrain equals np.array x-train. NP array yrain. We're just converting this back into a numpy array. That way, we can use all the cool tools that we get with numpy array, including reshaping. So, if we take a look and see what's going on here, we're going to take our x train. We're going to reshape it. Wow. What the heck does reshape mean? Uh, that means we have an array, if you remember correctly, um, so many numbers by 60. That's how wide it is. And so, we're when you when you do x-ra.shape, shape that gets one of the shapes and you get um x-train.shape of one gets the other shape. And we're just making sure the data is formatted correctly. And so you use this to pull the fact that it's 60 by um in this case, where's that value? 60 by 1199. 1258us 60 1199. And we're making sure 9:58:44 that that is shaped correctly. So the data is grouped into uh 1199 by 60 different arrays. And then the one on the end just means at the end because this when you're dealing with shapes and numpy they look at this as layers and so the end layer needs to be one value. That's like the leaf of a tree where this is the branch and then it branches out some more um and then you get the leaf. NP.res comes from and using the existing shapes to form it. We'll go ahead and run this piece of code. Again, there's no real output. And then we'll import our different cross modules that we need. So from cross models, we're going to import the sequential model. We're dealing with sequential data. We have our dense layers. We have actually three layers. We're going to bring in our dense, our LSTM, which is what we're focusing on, and our dropout. And we'll discuss these three layers more in just a moment. But you do need the with the LSTM, you do need the dropout, and then the final layer will be the dense. But let's go ahead and run this and that'll 9:59:44 bring our modules. And you'll see we get an error on here. And if you read it closer, it's not actually an error. It's a warning. What does this warning mean? These things come up all the time when you're working with such cutting edge modules are completely being updated all the time. We're not going to worry too much about the warning. All it's saying is that the H5PY module, which is part of KAS, is going to be updated at some point. And uh if you're running new stuff on KAS and you start updating your KASS system, you better make sure that your H5 PI is updated too. Otherwise, you're going to have an error later on. And you can actually just run an update on the H5 PI now if you wanted to. Not a big deal. We're not going to worry about that today. And I said we were going to jump in and start looking at what those layers mean. I meant that. And uh we're going to start off with initializing the RNN. And then we'll start adding those layers in. And you'll see that we have the LSTM and then the dropout. LSTM then dropout. LSTM then dropout. What the heck is that doing? So let let's explore that. We'll start by initializing the 10:00:45 RNN regressor equals sequential because we're using the sequential model. And we'll run that and load that up. And then we're going to start adding our LSTM layer and some dropout regularization. And right there should be the Q dropout regularization. And if we go back here and remember our exploding gradient, well, that's what we're talking about. The uh dropout drops out unnecessary data so we're not just shifting huge amounts of data through um the network. So, and so we go in here. Let's just go ahead and uh add this in. I'll go ahead and run this. And we had three of them. So, let me go ahead and put all three of them in. And then we can go back over them. There's the second one. And let's put one more in. So, let's put that in. And we'll go and put uh two more in. I meant to put I said one more in, but it's actually two more in. And then let's add one more after that. And as you can see, each time I run these, they don't actually have an output. So let's take a closer look and see what's going on here. So we're going to add our first LSTM layer in here. We're going to have units 50. The units is the positive integer and it's the dimensionality of the output 10:01:47 space. This is what's going out into the next layer. So we might have 60 coming in, but we have 50 going out. We have a return sequence because it is a sequence data. So we want to keep that true. And then you have to tell it what shape it's in. Well, we already know the shape by just going in here and looking at X train shape. So input shape equals the X train shape of one comma one. Makes it really easy. You don't have to remember all the numbers that put in 60 or whatever else is in there. You just let it tell the regressor what model to use. And so we follow our STM with a dropout layer. Now understanding the dropout layer is kind of exciting because one of the things that happens is we can overtrain our network. That means that our neural network will memorize such specific data that it has trouble predicting anything that's not in that specific realm. To fix for that, each time we run through the training mode, we're going to take 02 or 20% of our neurons, they just turn them off. So, we're only going to train on the other ones. And it's going to be random. That way, each time we pass through this, we 10:02:48 don't overtrain. These nodes come back in in the next training cycle. We randomly pick a different 20. And finally, I see a big difference as we go from the first to the second and third and fourth. The first thing is we don't have to input the shape because the shapes already the output units is 50 here. This auto the next step automatically knows this layer is putting out 50. And because it's the next layer, it automatically sets that and says, oh, 50 is coming out from our last layer. It's coming out, you know, goes into the regressor. And of course, we have our dropout and that's what's coming into this one. And so on and so on. And so the next three layers, we don't have to let it know what the shape is. It automatically understands that. And we're going to keep the units the same. We're still going to do 50 units. It's still a sequence coming through. 50 units and a sequence. Now, the next piece of code is what brings it all together. Let's go ahead and take a look at that. And we come in here, we put the output layer, the dense layer. And if you remember up here, we had the three layers. We had uh LSTM, dropout, and dense. uh dense just says we're going to 10:03:48 bring this all down into one output. Instead of putting out a sequence, we just know want to know the answer at this point. And let's go ahead and run that. And so in here, you notice all we're doing is setting things up one step at a time. So far, we've brought in our uh way up here, we brought in our data. We brought in our different modules. We formatted the data for training it. We set it up. You know, we have our yx train and our y train. We have our source of data and the answers we're we know so far that we're going to put in there. We've reshaped that. We've come in and built our cross. We've imported our different layers. And we have in here, if you look, we have what uh five total layers. Now, KAS is a little different than a lot of other systems because a lot of other systems put this all in one line and do it automatic, but they don't give you the options of how those layers interface and they don't give you the options of how the data comes in. KAS is cutting edge for this reason. So even though there's a lot of extra steps in building the model, this has a huge impact on the output and what we can do with this these new models from KAS. So we brought 10:04:50 in our dense, we have our full model put together, our regressor. So we need to go ahead and compile it and then we're going to go ahead and fit the data. We're going to compile the pieces so they all come together and then we're going to run our training data on there and actually recreate our regressor so it's ready to be used. So let's go ahead and compile that. And I can go ahead and run that. And uh if you've been looking at any of our other tutorials on neural networks, you'll see we're going to use the optimizer atom. Atom is optimized for big data. There's a couple other optimizers out there uh beyond the scope of this tutorial, but certainly Adam will work pretty good for this. And loss equals mean squared value. So when we're training it, this is what we want to base the loss on. How bad is our error? Well, we're going to use the mean squared value for our error and the atom optimizer for its differential equations. You don't have to know the math behind them, but certainly it helps to know what they're doing and where they fit into the bigger models. And then finally, we're going to do our fit. Fitting the RNN to the training set. We have the regressor.fit, X-rain, Yra, 10:05:50 epics, and batch size. So, we know where this is. This is our data coming in for the X-ray. Our Y train is the answer we're looking for of our data, our sequential input. Epics is how many times we're going to go over the whole data set. We created a whole data set of X-ray. So this is each each of those rows which includes a time sequence of 60 and batch size. Another one of those things where KASS really shines is if you were pulling this say from a large file instead of trying to load it all into RAM, it can now pick smaller batches up and load those indirectly. We're not worried about pulling them off a file today because this isn't big enough to uh cause the computer too much of a problem to run. Not too straining on the resources. But as we run this, you can imagine what would happen if I was doing a lot more than just one column in one set of stock. In this case, Google stock. Imagine if I was doing this across all the stocks and I had instead of just the open, I had open, close, a high, low, and you can actually find yourself with about 13 different variables times 60 because 10:06:52 there's a time sequence. suddenly you find yourself with a gig of memory you're loading into your RAM which will just completely, you know, if it's just if you're not on multiple computers or cluster, you're going to start running into resource problems. But for this, we don't have to worry about that. So, let's go ahead and run this. And this will actually take a little bit on my computer cuz it's an older laptop. And give it a second to kick in there. There we go. All right. So, we have Epic. So, this is going to tell me it's running the first run through all the data. And as it's going through, it's batching them in 32 pieces. So 32 lines each time and there's 1198. I think I said 1199 earlier, but it's 1198. I was off by one. And each one of these is 13 seconds. So you can imagine this is roughly 20 to 30 minutes run time on this computer. Like I said, it's an older laptop running at uh 0.9 GHz on a dual processor. And that's fine. What we'll do is I'll go ahead and stop, go get a drink of coffee, and come back and let's see what happens at the end and where this takes us. And like any good cooking show. I've gone and gotten my latte. I also had some other stuff 10:07:52 running in the background. So you'll see these numbers jumped up to like 19 seconds, 15 seconds. But you can scroll through and you can see we've run it through 100 steps or 100 epics. So the question is what does all this mean? One of the first things you'll notice is that our loss can is over here. It kind of stopped at 0.0014, but you can see it kind of goes down until we hit about 0.014 three times in a row. So we guessed our epic pretty close since our loss has remained the same on there. So to find out what we're looking at, we're going to go ahead and load up our test data, the test data that we didn't process yet, and real stock price data set test location. This is the same thing we did when we prepped the data in the first place. So let's go ahead and go through this code. And we can see we've labeled it part three, making the predictions and visualizing the results. So the first thing we need to do is go ahead and read the data in from our test CSV. You see I've changed the path on it for my computer. And uh then we'll call it the real stock price. And again, we're doing just the one column here and the values from IO location. So it's all 10:08:54 the rows and just the values from these that one location. That's the open stock open. And let's go ahead and run that. So that's loaded in there. And then let's go ahead and uh create. We have our inputs. We're going to create inputs here. And this should all look familiar. This is the same thing we did before. We're going to take our data set total. We're going to do a little pandas concat from the data set train. Now remember the end of the data set train is part of the data going in. And let's just visualize that just a little bit. Here's our train data. Let me just put tr for train. And it went up to this value here. But each one of these values generated a bunch of columns. It was 60 across. And this value here equals this one. And this value here equals this one. And this value here equals this one. And so we need these top 60 to go into our new data. So to find out what we're looking at, we're going to go ahead and load up our test data, the test data that we didn't process yet. And a real stock price data set test I location. This is the same thing we did 10:09:54 when we prepped the data in the first place. So let's go ahead and go through this code. And we can see we've labeled it part three, making the predictions and visualizing the results. So the first thing we need to do is go ahead and read the data in from our test CSV. You see I've changed the path on it for my computer. And uh then we'll call it the real stock price. And again we're doing just the one column here and the values from IO location. So it's all the rows and just the values from these that one location. That's the open stock open. And let's go ahead and run that. So that's loaded in there. And then let's go ahead and uh create we have our inputs. We're going to create inputs here. And this should all look familiar. This is the same thing we did before. We're going to take our data set total. We're going to do a little pandas concat from the data set train. Now remember the end of the data set train is part of the data going in. And let's just visualize that just a little bit. Here's our train data. Let me just put tr for train. And it went up to this value here. But each one of these values 10:10:55 generated a bunch of columns. It was 60 across. And this value here equals this one. And this value here equals this one. And this value here equals this one. And so we need these top 60 to go into our new data cuz that's part of the next data or it's actually the top 59. So that's what this first setup is over here is we're going in. We're doing the real stock price and we're going to just take the data set test and we're going to load that in. And then the real stock price is our data test location. So we're just looking at that first uh column, the open price. And then our data set total, we're going to take pandas and we're going to concat. And we're going to take our data set train for the open and our data set test open. And this is one way you can reference these columns. We've referenced them a couple different ways. We've referenced them up here with the one two, but we know it's labeled as a panda set as open. So pandas is great that way. Lots of versatility there. And we'll go ahead and go back up here and run this. There we go. And uh you'll notice this is the same as what we did before. We have our open data set. We pended our two different or concatenated our two data 10:11:57 sets together. We have our inputs equals data set total length. Data set total minus length of data set minus test minus 60 values. So we're going to run this over all of them. And you'll see why this works because normally when you're running your test set versus your training set, you run them completely separate. But when we graph this, you'll see that we're just going to be we'll be looking at the part that uh we didn't train it with to see how well it graphs. And we have our inputs equals inputs reshapes or reshaping like we did before. We're transforming our inputs. So if you remember from the transform between 0 and one and uh finally want to go ahead and take our X test and we're going to create that X test and for I in range 60 to 80. So here's our X test and we're appending our inputs I to 60 which remember is 0 to 59 and I comm, 0 on the other side. So it's just the first column which is our open column. And uh once again we take our X test, we convert it to a numpy array. We do the same reshape we did before. And uh then we get down to the final two lines. And here we have something new right here on these last two lines. Let me just 10:12:58 highlight those or or mark them. Predicted stock price equals regressor.predictsx test. So we're predicting all the stock including both the training and the testing model here. And then we want to take this prediction and we want to inverse the transform. So remember we put them between zero and one. Well, that's not going to mean very much to me to look at a at a float number between 0 and one. And I want the dollar amounts. I want to know what the cash value is. And we'll go ahead and run this. And you'll see it runs much quicker than the training. That's what's so wonderful about these neural networks. Once you put them together, takes just a second to run the same neural network that took us what, a half hour to train. Head and plot the data. We're going to plot what we think it's going to be and we're going to plot it against the real data. What what the Google stock actually did. So let's go ahead and take a look at that in code. And let's uh pull this code up. So we have our PLT. That's our uh oh, if you remember from the very beginning, let me just go back up to the top. We have our mattplot library.pipplot as plt. That's where that comes in. And we come down here. 10:13:57 We're going to plot. Let me get my drawing thing out again. We're going to go ahead and plt is basically kind of like an object. It's one of the things that always threw me when I'm doing graphs in Python because I always think you have to create an object and then it loads that class in there. Well, in this case, plt is like a canvas you're putting stuff on. So if you've done HTML 5, you'll have the canvas object. This is the canvas. So we're going to plot the real stock price. That's what it actually is. And we're going to give that color red. So it's going to be in bright red. We're going to label it real Google stock price. And then we're going to do our predicted stock. And we're going to do it in blue. And it's going to be labeled predicted. And we'll give it a title because it's always nice to give a title to your uh graph, especially if you're going to present this to somebody, you know, to your uh shareholders in the office. And uh the x label is going to be time because it's a time series. And we didn't actually put the actual date and times on here. But that's fine. We just know they're incremented by time. And then of course the y label is the actual stock price. 10:14:55 plt.leend tells us to build the legend on here so that the color red and and real Google stock price show up on there. And then the plot shows us that actual graph. So let's go ahead and run this and see what that looks like. And you can see here we have a nice graph. And let's talk just a little bit about this graph before we wrap it up. Here's our legend I was telling you about. That's why we have the legend showed the prices. We have our title and everything. And you'll notice on the bottom we have a time sequence. We didn't put the actual time in here. Now, we could have we could have gone ahead and um plotted the x since we know what the the dates are and plotted this to dates, but we also know this only the last piece of data that we're looking at. So last piece of data which ends somewhere probably around here on the graph. I think it's like about 20% of the data probably less than that. We have the Google price and the Google price has this little up jump and then down. And you'll see that the actual Google instead of uh a turndown here just didn't go up as high and didn't low go uh down. So our prediction has the 10:15:56 same pattern but the overall value is pretty far off as far as um stock. But then again we're only looking at one column. We're only looking at the open price. We're not looking at how many volumes were traded. Like I was pointing out earlier when we talk about stock. Just right off the bat, there's six columns. There's open, high, low, close, volume. Then there's whether uh I mean volume shares. Then there's the adjusted open, adjusted high, adjusted low, adjusted close. They have a special formula to predict exactly what it would really be worth based on the value of the stock. And then from there, there's all kinds of other stuff you can put in here. So, we're only looking at one small aspect, the opening price of the stock. And as you can see here, we did a pretty good job. This curve follows the curve pretty well. It has like uh, you know, little jumps on it, bends. They don't quite match up. So, this bend here does not quite match up with that bend there, but it's pretty darn close. We have the basic shape of it, and the prediction isn't too far off. And you can imagine that as we add more data in and look at different aspects in the 10:16:58 specific domain of stock, we should be able to get a better representation each time we drill in deeper. Of course, this took a half hour for my program, my computer to train. So you can imagine that if I was running it across all those different variables, might take a little bit longer to train the data. Not so good for doing a quick tutorial like this. So we're going to dive right into what is KAS. We'll also uh go all the way through this into a couple of tutorials because that's where you really learn a lot is when you roll up your sleeves. So we talk about what is KAS. Kass is a high-level deep learning API written in Python for easy implement implementation of neural networks. It uses deep learning frameworks such as TensorFlow, PyTorch, etc. as backend to make computation faster. And this is really nice because as a uh programmer there is so much stuff out there and it's evolving so fast it can get confusing and having some kind of highlevel order in there we can actually view it and easily program these different neural networks uh is really 10:18:00 powerful. It's really powerful to to um uh have something out really quick and also be able to start testing your models and seeing where you're going. So, Kass works by using complex deep learning frameworks such as TensorFlow, PyTorch, um, ML played, etc. as a backend for fast computation while providing a userfriendly and easy tolearn front end. And you can see here we have the KASS API uh, specifications and under that you'd have like TF Karass for TensorFlow, Thano Karass and so on and then you have your TensorFlow workflow that this is all sitting on top of. And this is, like I said, it organizes everything. The heavy lifting is still done by TensorFlow or whatever, you know, underlying package you put in there. And this is really nice because you don't have to um dig as deeply into the heavy stuff while still having a very robust package. You can get up and running rather quickly and it doesn't distract from the processing time 10:19:01 because all the heavy lifting is done by packages like TensorFlow. This is the organization on top of it. So the working principle of KASS uh the working principle of KASS is Kass uses computational graphs to express and evaluate mathematical expressions. You can see here we put them in blue. They have the expression um expressing complex problems as a combination of simple mathematical operators uh where we have like the percentage or in this case in Python that's usually your uh left your remainder or multiplication uh you might have the operator of x uh to the power of.3 and it uses useful for calculating derivatives by using uh back propagation. So if we're doing with neural networks, we send the error back up to figure out how to change it. Uh this makes it really easy to do that without really having not banging your head and having to hand write everything. It's easier to implement distributed computation and for solving complex problems uh specify input and 10:20:03 outputs and make sure all nodes are connected. And so this is really nice as you come in through is that um as your layers are going in there, you can get some very complicated uh different setups nowadays, which we'll look at in just a second. And this just makes it really easy to start spinning this stuff up and trying out the different models. So we look at cross models. Uh cross model, we have a sequential model. Sequential model is a linear stack of layers where the previous layer leads into the next layer. And this, if you've done anything else, even like the sklearn with their neural networks and propagation and any of these setups, this should look familiar. You should have your input layer. It goes into your layer 1, layer two, and then to the output layer. And it's useful for simple classifier decoder models. And you can see down here we have the model equals a crosssequential. And this is the actual code. You can see how easy it is. Uh we have a layer that's dense. your layer one as an activation. Uh they're using the RLU in 10:21:04 this particular example. And then you have your name layer one, layer dense RLU, name layer two, and so forth. Uh and they just feed right into each other. So it's really easy just to stack them as you can see here. And it automatically takes care of everything else for you. And then there's a functional model. And this is really where things are at. This is new. Make sure you update your KAS or you'll find yourself running this um doing the functional model. you'll run into an error code because this is a fairly new release and it uses multi-input and multi-output model. The complex model which forks into two or more branches and you can see here we have our image inputs equals your cross input shape equals 32x 32x3. You have your uh dense layers dense 64 activation RLU and this should look similar to what you already saw before. Uh but if you look at the graph on the right, it's going to be a lot easier to see what's going on. You have two different inputs. Uh and one way you could think of this is maybe one of 10:22:05 those is a small image and one of those is a full-sized image. And that feedback goes into you might feed both of them into one node because it's looking for one thing and then only into one node for the other one. And so you can start to get kind of an idea that there's a lot of use for this kind of split and this kind of setup uh where you have multiple information coming in but the information's very different even though it overlaps and you don't want it to send it through the same neural network. Um and they're finding that this trains faster and is also has a better result depending on how you split the data up and and how you fork the models coming down. And so in here we do have the two complex uh models coming in. Uh we have our image inputs which is a 32x 32x3 your three channels or four if you're having an alpha channel. Uh you have your dense your layers dense is 64 activation using the ru uh x equals dense inputs x layers dense x64 activation equals ru x outputs 10:23:08 equals layers dense 10 x model equals cross model inputs equals inputs outputs equals outputs name equals minced model. Uh so we add a little name on there and again this is this kind of split here. This is setting us up to um have the input go into different areas. So if you're already looking at Kuss, you probably already have this answer. What are neural networks? Uh but it's always good to get on the same page and for those people who don't fully understand neural networks to dive into them a little bit or do a quick overview. Neural networks are deep learning algorithms modeled after the human brain. They use multiple neurons which are mathematical operations to break down and solve complex math problems. And so just like the neuron, one neuron fires in and it fires out to all these other neurons or nodes as we call them. And eventually they all come down to your output layer. And you can see here we have the really standard graph input layer, a hidden layer, and an output layer. One of the biggest parts of any 10:24:11 data processing is your data prep-processing. Uh so we always have to touch base on that with a neural network like many of these models. They're kind of uh when you first start using them they're like a black box. You put your data in, you train it and you test it and see how good it was and you have to pre-process that data because bad data in is uh bad outputs. So in data prep-processing we will create our own data examples set with KAS. The data consists of a clinical trial conducted on 2100 patients ranging from ages 13 to 100 with a the patients under 65 and the other half over 65 years of age. We want to find the possibility of a patient experiencing side effects due to their age. And you can think of this in today's world with uh COVID uh what's going to happen on there. And we're going to go ahead and do an example of that in our uh live hands-on. Like I said, most of this you really need to 10:25:11 have hands-on to understand. So, let's go ahead and bring up our Anaconda and uh open that up and open up a Jupyter notebook for doing the Python code in. Now, if you're not familiar with those, you can use pretty much any of your uh setups. I just like those for doing demos and uh showing people, especially shareholders. It really helps because it's a nice visual. So, let me go and flip over to our Anaconda. And the Anaconda has a lot of cool tools. They just added data lore and IBM Watson Studio cloud into the Anaconda framework, but we'll be in the Jupyter Lab or Jupyter Notebook. Um, I'm going to do Jupyter Notebook for this because I use the lab for like large projects with multiple pieces because it has multiple tabs where the notebook will work fine for what we're doing. And this opens up in our browser window because that's how Jupyter notebook Jupyter notebook is set to run. and we'll go under new create a new Python 3 and uh it creates an untitled Python. We'll go ahead and give this a title and we'll 10:26:12 just call this uh KAS tutorial. And let's change that to a capital. There we go. We'll go and just rename that. And the first thing we want to go ahead and do is uh get some pre-processing tools involved. And so we need to go ahead and import some stuff for that like our numpy do some random number generation. Um I mentioned sklearn or your scikit if you're installing sklearn the sklearn stuff it's a scite kit you want to look up that should be a tool of anybody who is um doing data science. If you if you're not if you're not familiar with the sklearn toolkit, it's huge. Uh but there's so many things in there that we always go back to. And we want to go ahead and create some train labels and train samples uh for training our data. And then just a note of what we're we're 10:27:13 actually doing in here. Uh let me go ahead and change this. This is kind of a fun thing you can do. We can change the code to markdown. And then markdown code is nice for doing examples once you've already built this. Uh our example data we're going to do experimental there we go experimental drug was tested on 2100 individuals between 13 to 100 years of age. Half the participants under 65 and 95% of participants are under 65 experience no side effects. Well 95% of participants over 65 u experience side effects. So, that's kind of where we're starting at. Um, and this is just a real quick example because we're going to do another one with a little bit more uh complicated information. Uh, and so we want to go ahead and generate our setup. Uh, so we want to do for I and range and we want to go ahead and create, if you look here, we have random integers, 10:28:13 train the labels, append. So, we're just creating some random data. Uh, let me go ahead and just run that. And so once we've created our random data and if you if I mean you can certainly ask for a copy of the code from simply learn they'll send you a copy of this or you can zoom in on the video and see how we went ahead and did our train samples a pin um and we're just using this I do this kind of stuff all the time. I was running a thing on uh that had to do with errors following a bellshaped curve on uh a standard distribution error. And so what do I do? I generate the data on a standard distribution error to see what it looks like and how my code processes it since that was the baseline I was looking for. In this we're just doing uh uh generating random data for our setup on here. And uh we could actually go in uh print some of the data. Let's just do this. Print um we'll do train 10:29:13 samples and we'll just gen do the first um five pieces of data in there to see what that looks like. And you can see the first five pieces of data in our train samples is 49 85 41 681 19 just random numbers generated in there. That's all that is. Uh and we generated significantly more than that. Um let's see 50 up here. 1,000. Yeah. So, there's 1,00 here. 1,00 numbers we generated. And we could also, if we wanted to find that out, we could do a quick uh print the length of it. And so, or you could do a shape kind of thing. And if you're using numpy, although the length for this is just fine. And there we go. It's actually 2100 like we said in the demo setup in there. And then we want to go ahead and take our labels. Oh, that was our train labels. We also did samples, didn't we? Uh, so we could also print do the same thing. 10:30:15 Labels. Um, and let's change this to labels and labels. And run that just to double check. And sure enough, we have 2100. And they're labeled 1 0 1 0 1 0. I guess that's if they have symptoms or not. One symptoms uh 0 none. And so we want to go ahead and take our train labels and we'll convert it into a numpy array. And the same thing with our samples. And let's go ahead and run that. And we also shuffle. Uh this is just a neat feature you can do in uh numpy right here. Put my drawing thing on which I didn't have on earlier. Um, I can take the data and I can shuffle it. Uh, so we have our So it's it just randomizes it. That's all that's doing. Um, we've already randomize it so it's kind of an overkill. It's not really necessary. 10:31:16 But if you're doing uh a larger package where the data is coming in and a lot of times it's organized somehow and you want to randomize it just to make sure that that you know the input doesn't follow a certain pattern uh that might create a bias in your model. And we go ahead and create a scaler uh the scaler range uh minimum max scaler feature range 0 to one. Uh then we go ahead and scale the uh scaled train samples. So we're going to go ahead and fit and transform the data uh so it's nice and scaled and that is the age. Uh so you can see up here we have 49 85 41. We're just moving that so it's going to be uh between zero and one. And so this is true with any of your neural networks. You really want to convert the data uh to zero and one otherwise you create a bias. Uh so if you have like a 100 creates a bias versus the math behind it gets really complicated. Uh if you actually start multiplying stuff because there's a lot of multiplication addition going on in 10:32:17 there that higherend value will eventually multiply down and it will have a huge bias as to how the model fits it and then it will not fit as well. And then one of the fun things we can do in Jupyter Notebook is that if you have a variable and you're not doing anything with it, it's the last one on the line, it will automatically print. Um, and we're just going to look at the first five samples on here. And so it's going to print the first five samples. And you can see here we go uh 91 95 791. So everything's between zero and one. And that just shows us that we scaled it properly and it looks good. Uh it really helps a lot to do these kind of printups halfway through. Uh you never know what's going to go on there. I don't know how many tents I've gotten down and found out that the data sent to me that I thought was scaled was not and then I have to go back and track it down and figure it out on there. Uh so let's go ahead and create our 10:33:19 artificial neural network. And for doing that, this is where we start diving into TensorFlow and KAS. Uh TensorFlow, if you don't know the history of TensorFlow, it helps to uh jump into we'll just use Wikipedia. Careful, don't quote Wikipedia on these things because you get in trouble. Uh but it's a good place to start. Uh back in 2011, Google Brain built disbelief as a proprietary machine learning setup. TensorFlow became the open source for it. Uh so TensorFlow was a Google product and then it became uh open sourced and now it's just become probably one of the de facto when it comes for neural networks as far as where we're at. Uh so when you see the TensorFlow setup, it it's got like a huge following. There are some other setups like a um the sidekit under the skarn has their own little neural network. uh but the 10:34:20 TensorFlow is the most robust one out there right now and KAS sitting on top of it makes it a very powerful tool so we can leverage both the KAS uh easiness in which we can build a sequential setup on top of TensorFlow. And so in here we're going to go ahead and do our input of TensorFlow. Uh and then we have the rest of this is all KAS here from number two down. Uh we're going to import from TensorFlow the KAS uh connection and then you have your TensorFlow cross models import sequential. It's a specific kind of model. We'll look at that in just a second. If you remember from the files, that means it goes from one layer to the next layer to the next layer. There's no funky splits or anything like that. Uh and then we have from TensorFlow across layers. We're going to import our activation and our dense layer. And we have our optimizer, Adam. Um, this is a big thing to be aware of how 10:35:20 you optimize uh your data. When you first do it, Adam's as good as any. Atom is usually uh there's a number of optimizer out there. There's about uh there's a couple main ones, but atom is usually assigned to bigger data. Uh it works fine. Usually the lower data does it just fine, but atom is probably the mostly used, but there are some more out there. And depending on what you're doing with your layers, your different layers might have different activations on them. And then finally down here, you'll see um our setup where we want to go ahead and use the metrics. And we're going to use the TensorFlow cross metrics um for categorical cross entropy. Uh so we can see how everything performs when we're done. That's all that is. Um, a lot of times you'll see us go back and forth between TensorFlow and then Scikit has a lot of really good metrics also for measuring these things. Um, again it's the end of the, you know, at the end of the story. How good does your model do? And we'll go ahead and load all that. And then comes the fun 10:36:22 part. Um, I actually like to spend hours messing with these things. And uh, four lines of code. You're like, "Ah, you're going to spend hours on four lines of code." Um, no. We don't spend hours on four lines of code. That's not what we're talking about when I say spend hours on four lines of code. Uh what we have here, I'm going to explain that in just a second. We have a model and it's a sequential model. If you remember correctly, we mentioned the sequential up here where it goes from one layer to the next. And our first layer is going to be your input. It's going to be uh what they call dense, which is u usually it's just dense. And then you have your input and your activation. Um, how many units are coming in? We have 16. Uh, what's the shape? What's the activation? And this is where it gets interesting. Uh, because we have in here, uh, ReLU on two of these and softmax activation on one of these. There are so many different options for 10:37:25 what these mean um, and how they function. How does the Reu, how does the softmax function? and they do a lot of different things. Um, we're not going to go into the activations in here. That is what really you spend hours doing is looking at these different activations. Um, and just some of it is just um almost like you're playing with it like an artist. You start getting a feel for like a uh inverse tangent activation or the 10H activation takes up a huge processing amount. Uh so you don't see it a lot yet. It comes up with a better solution especially when you're doing uh when you're analyzing word documents and you're tokenizing the words. And so you'll see this shift from one to the other because you're both trying to build a better model and if you're working on a huge data set um you'll crash the system. It'll just take too long to process. Um, and then you 10:38:26 see things like softmax. Uh, softmax generates an interesting um, setup where a lot of these when you talk about RLU it Oops, let me do this. Uh, ROU. There we go. RLU has um a setup where if it's less than zero, it's zero and then it goes up. Um, and then you might have what they call lazy uh, setup where it has a slight negative to it so that the errors can translate better. Same thing with softmax. It has a slight laziness to it so that errors translate better. All these little details make a huge different on your model. Um so one of the really cool things about data science that I like is you build your uh what they call you build to fail. And it's an interesting uh design setup. Oops, I forgot the end of my code here. The concept of build a fail is you want the model as a whole to work. So you can test your model out 10:39:29 so that you can do uh you can get to the end and you can do your let's see where was it overshot down here. You can test your test out how the quality of your setup on there and see where did I do my tensorflow. Oh here we go. I did it was right above me. There we go. we start doing your cross entropy and stuff like that is you need a full functional set of code so that when you run it you can then test your model out and say hey it's either this model works better than this model and this is why um and then you can start swapping in these models and so when I say spend a huge amount of time on pre-processing data is probably 80% of your programming time um well between those two it's like 8020 you'll spend a lot of time on the models Once you get the model down, once you get the whole code and the flow down, uh, set, depending on your data, your models get more and more robust as you start experimenting with different inputs, different data streams, and all 10:40:30 kinds of things. And we can do a simple model summary here. Uh, here's our sequential, here's our layer, our output, a parameter. This is one of the nice things about KAS is you just, you can see right here, here's our sequential one model. Boom, boom, boom, boom. everything set and clear and easy to read. So once we have our model built, uh the next thing we're going to want to do is we're want to go ahead and uh train that model. And so the next step is of course model training. And when we come in here, this a lot of times it's just paired with the model because it's so straightforward. It's nice to print out the model setup so you can have a tracking. But here's our model. Uh the keyword in Kass is compile optimizer atom. Learning rate. Another term right there that we're just skipping right over that really becomes the meat of uh the setup is your 10:41:31 learning rate. Uh so whoops, I forgot that I had an arrow, but I'll just underline it. A lot of times the learning rate set to 0.0 uh set to 0.01 01. Uh depending on what you're doing, this learning rate um can overfit and underfit. Uh so you'd want to look up I know we have a number of tutorials out on overfitting and underfitting that are really worth reading once you get to that point and understanding. And we have our loss um sparse categorical cross entropy. So this is going to tell how far to go until it stops. And then we're looking for metrics of accuracy. So we'll go ahead and run that. And now that we've compiled our model, we want to go ahead and um run it, fit it. So here's our model fit. Um we have our scale to train samples, our train labels, our validation split. Um in this case, we're going to use 10% of the data for validation. 10:42:33 Uh batch size, another number you kind of play with. Not a huge difference as far as how it works, but it does affect how long it takes to run and it can also affect the bias a little bit. Uh most of the time though a batch size is between 10 to 100 um depending on just how much data you're processing in there. We want to go ahead and shuffle it. Uh we're going to go through 30 epics and uh put a verbose of two. Let me just go ahead and run this. And you can see right here, here's our epic. Here's our training. Um here's our loss. Now, if you remember correctly up here, we set the loss. See, where was it? Um, compiled our data. There we go. Loss. Uh, so it's looking at the sparse categorical cross entropy. This tells us that as it goes, how how how much um how how much does the um error go down? Uh is the best way to look at that. And you can see here, the lower the number, the better. And it just keeps going down. And vice versa. 10:43:33 Accuracy. We want let's see where's my accuracy value accuracy at the end. Uh and you can see 619 69.74 it's going up. We want the accuracy would be ideal if it made it all the way to one. But we also the loss is more important because it's a balance. Um you can have 100% accuracy and your model doesn't work because it's overfitted. Uh again, you want to look up overfitting and underfitting models. And we went ahead and went through uh 30 epics. It's always fun to kind of watch your code going. Um to be honest, I usually uh uh the first time I run it, I'm like, "Oh, that's cool. I get to see what it does." And after the second time of running it, I'm like, "I'd like to just not see that." And you can repress those, of course, in your code. Uh repress the warnings in the printing. And so the next step is going to be building a test set and predicting it. 10:44:35 Now, uh so here we go. We want to go ahead and build our test set. And we have uh just like we did our training set. A lot of times you just split your your initial setup. Uh but we'll go ahead and do a separate set on here. And this is just what we did above. Uh there's no difference as far as um the randomness that we're using to build this set on here. Uh the only difference is that we already uh did our scalar up here. Well, it doesn't matter because the the data is going to be across the same thing, but this should just be just transform down here instead of fit transform. Uh because you don't want to refit your data um on your testing data. There we go. So now we're just transforming it because you never want to transform the test data. Um easy mistake to make especially on an example like this where we're not doing um you know we're randomizing the data anyway. 10:45:36 So it doesn't matter too much because we're not expecting something weird. And then we want ahead and do our predictions. The whole reason we built the model is we take our model, we predict, and we're going to do here's our Xcale data batch size 10 verbose. And now we have our predictions in here. And we could go ahead and do a um we'll print predictions. And then I guess I could just put down predictions and five so we can look at the first five of the predictions. And what we have here is we have our age and uh the prediction on this age versus on what is what we think it's going to be what what we think is going to have uh symptoms or not. And the first thing we notice is that's hard to read because we really want a yes no answer. Uh so we'll go ahead and just uh round off the predictions using the argmax um the numpy arg max uh 10:46:38 for predictions. So it just goes to a zero one. And if you remember this is a Jupyter notebook. So I don't have to put the print. I can just put in uh rounded predictions. And we'll just do the first five. And you can see here 0 1 0 0. So that's what the predictions are that we have coming out of this um is no symptoms. No symptoms symptoms no symptoms. And just as uh we were talking about at the beginning, we want to go ahead and um take a look at this. There we go. confusion matrixes for accuracy check. Uh most important part when you get down to the end of the story, how accurate is your model before you go and play with the model and see if you can get a better accuracy out of it. And for this we'll go ahead and use the scikit um the sklearn metrics. Uh scikit being where that comes from. import confusion matrix, uh some iteration tools, and of course a nice map plot library that makes a big difference. So it's always 10:47:38 nice to um have a nice graph to look at. Um picture is worth a thousand words. Um and then we'll go ahead and do call it CM for confusion matrix Y true equals test labels Y predict rounded predictions. and we'll go ahead and load in our CM. And I'm not going to spend too much time on the plotting um going over the different plotting code. Um you can spend uh like whole we have whole tutorials on how to do your different plotting on there. Uh but we do have here is we're going to do a plot confusion matrix. There's our CM our classes normalized false title confusion matrix. C map is going to be in blues. And you can see here we have uh to the nearest C map titles, all the different pieces, whether you put tick marks or not, the marks, the classes, the color bar. Um so a lot of different 10:48:38 information on here as far as how we're doing the printing of the of the confusion matrix. You can also just dump the confusion matrix um into a seaborn and real quick get an output. It's worth knowing how to do all this uh when you're doing a presentation to the shareholders. You don't want to do this on the fly. You want to take the time to make it look really nice. Uh like our guys in the back did. And uh let's go ahead and do this. Forgot to put together our CM plot labels. We'll go ahead and run that. And then we'll go ahead and call the little the definition for our mapping. And you can see here, plot confusion matrix. That's our the the little script we just wrote. And we're going to dump our data into it. Um so our confusion matrix, our classes, um title confusion matrix. And let's just go ahead and run that. And you can see here we have our basic setup. Uh no side effects 195 had side effects uh 200. No side effects that had 10:49:41 side effects. So, we predicted that 10 of them who actually had side effects. And that's pretty good. I mean, I I don't know about you, but you know, that's 5% error on this. And this is because there's 200 here. That's where I get 5% is uh divide these both by by two and you get five out of 100. Uh you can do the same kind of math up here. Not as quick on the fly because it's 15 and 195. not an easily rounded number, but you can see here where they have 15 people who predicted to have no uh with the no side effects but had side effects kind of set up on there. And these confusion matrix are so important at the end of the day. This is really where where you show uh whatever you're working on comes up and you can actually show them, hey, this is how good we are or not, how messed up it is. So this was a uh I spent a lot of time on some of the parts. Uh but you can see here is really simple. Uh we did the 10:50:42 random generation of data but when we actually built the model coming up here uh here's our model summary and we just have the layers on here that we built with our model on this and then we went ahead and trained it and ran the prediction. Now we can get a lot more complicated. Uh let me flip back on over here because we're going to do another uh demo. So that was our basic introduction to it. We talked about the uh oops here we go. Okay. So implementing a neural network with KASS. After creating our samples and labels, we need to create our KASS neural network model. We will be working with a sequential model which has three layers. And this is what we did. We had our input layer, our hidden layers, and our output layers. And you can see the input layer uh coming in uh was the age factor. We had our hidden layer and then we had the output. Are you going to have symptoms or not? So, we're going to go ahead and go with something a little bit more complicated. Um, training our model is a two-step process. We first compile our model and then we train it in our training data set. Uh, so we have 10:51:42 compiling. Compiling converts the code into a form of understandable by machine. We used the atom in the last example, a gradient descent algorithm to optimize a model. And then we trained our model, which means it let it uh learn on training data. Uh, and I actually had a little backwards there, but this is what we just did is we, if you remember from our code we just had, Oops, let me go back here. Um, here's our model that we created summarized. Uh, we come down here and we compile it. So, it tells it, hey, we're ready to build this model and use it. Uh, and then we train it. This is the part where we go ahead and fit our model and and put that information in here. here and it goes through the training on there and of course we scaled the data which was really important to do and then you saw we did the creating a confusion matrix with KAS. Um as we are performing classifications on our data we need a confusion matrix to check the results. A confusion matrix breaks down 10:52:43 the various misclassifications as well as correct classifications to get the accuracy. Um, and so you can see here, this is what we did with the true positive, false positive, true negative, false negative. And that is what we went over. Let me just scroll down here on the end. We printed it out. And you can see we have a nice print out of our confusion matrix uh with the true positive, false positive, false negative, true negative. And so the blue ones uh we want those to be the biggest numbers because those are the better side. And then uh we have our false predictions on here uh as far as this one. So had no side effects but we predicted let's see no side effects predicting side effects and vice versa. If getting your learning started is half the battle. What if you could do that for free? Visit scaleup by simply learn. Click on the link in the description to know more. Now uh saving and loading models with KAS. We're going to dive into a more complicated demo. Um, and 10:53:46 you're gonna say, "Oh, that was a lot of complication before." Well, if you broke it down, we randomized some data. We created the um KAS setup. We compiled it. We trained it. We predicted, and we ran our matrix. Uh, so we're going to dive into something a lot more fun is we're going to do a face mask detection with KAS. Uh, so we're going to build a Kass model to check if a person is wearing a mask or not in real time. And this might be important if you're at the front of a store. This is something today which is um might be very useful as far as some of our you know making sure people are safe. Uh and so we're going to look at mask and no mask. And let's start with a little bit on the data. And so in my data I have with a mask and you can see they just have a number of images showing the people in masks. And again, if you want some of this information, uh, contact SimplyLLearn and they can send you some of the information as far as people with and without masks so you can try it on your own. And this is just such a wonderful 10:54:46 example of this setup on here. So, before I dive into the mask detection, uh, talking about being in the current with COVID and seeing if people are wearing masks, this particular example I had to go ahead and update to a Python 3.8 8 version. Uh it might run in a 37. I'm not sure. I haven't I kind of skipped 37 and installed 38. Uh so I'll be running in a 3 Python 38. Um and then you also want to make sure your TensorFlow is up to date because the um they call functional uh layers. That's where they split. If you remember correctly from back uh oh let's take a look at this. Remember from here the functional model and a functional layer allows us to feed in the different layers into different you know different nodes into different layers and split them. Uh very powerful tool very popular right now in the edge of where things are with neural networks and creating a better model. So I've 10:55:48 upgraded to Python 3.8 8. And let's go ahead and open that up and go through uh our next example, which includes uh multiple layers, um programming it to recognize whether someone wears a mask or not, and then uh saving that model so we can use it in real time. So, we're actually almost a full um end toend development of a product here. Uh, of course, this is a very simplified version and there'd be a lot more to it. You'd also have to do like uh recognizing whether it's someone's face or not. All kinds of other things go into this. So, let's go ahead and jump into that code and we'll open up a new Python 3. Oops. Python 3. It's working on it. There we go. Um, and then we want to go ahead and train our mask. We'll just call this train mask. And we want to go ahead and train mask and save it. Uh, so it's it's uh it's save mask train mask detection, not to 10:56:50 be confused with masking data. A little bit different. We're actually talking about a physical mask on your face. And then from the cross standpoint, we got a lot of imports to do here. And I'm not going to dig too deep on the imports. Uh we're just going to go ahead and notice a few of them. Uh so we have in here oops let me go alt d there we go have something to draw with a little bit here we have our uh image processing and the image processing right here me underline that uh deals with how do we bring images in because most images are like a a square grid and then each value in there has three values for the three different colors. uh KAS and TensorFlow do a really good job of uh working with that so you don't have to do all the heavy listening and figuring out what's going to go on. Uh and we have the mobile net average pooling 2D. Um this 10:57:50 again is how do we deal with the images and pulling them? Uh dropout's a cool thing worth looking up if you haven't when as you get more and more into Kass and TensorFlow uh it'll auto drop out certain nodes. That way you'll get a better um the notes just kind of die. Uh they find that they actually create more of a bias than a help and they also add processing time so they remove them. Um and then we have our flatten. That's where you take that huge array with the three different colors and you find a way to flatten it so it's just a one-dimensional array instead of a 2x two by3. Uh dense input. We did that in the other one. So that should look a little familiar. Oops. There we go. our input um our model. Again, these are things we had on the last one. Here's our optimizer with our atom. Um we have some pre-processing on the input that goes along with bringing in the data in uh more pre-processing with 10:58:50 image to array, loading the image. Um this stuff is so nice. It looks like a lot of work. You have to import all these different modules in here, but the truth is is it does everything for you. you're not doing a lot of pre-processing. You're letting the software do the pre-processing. Um, and we're going to be working with the setting something to categorical. Again, that's just a conversion from a number to a category. Uh, 01 doesn't really mean anything. It's like true false. Um, label binarizer. The same thing. Uh, we're changing our labels around. And then there's our train test split classification report. um our IM utilities. Let me just go ahead and scroll down here a notch for these. This is something a little different going on down here. This is not part of the uh TensorFlow or the sklearn. This is the scite kit setup in TensorFlow above. Uh the path this is part of um Open CV and we'll actually have another tutorial 10:59:51 going out with the Open CV. So, if you want to know more about OpenCV, you'll get a glance on it in uh this software, especially the ne the second piece when we reload up the data and hook it up to a video camera. We're going to do that on this round. Um, but this is part of the open CV thing. And you'll see CV2 is usually how that's referenced. Um, but the IM utilities has to do with how do you rotate pictures around and stuff like that, uh, and resize them. And then the map plot library for plotting because it's nice to have a graph tells us how good we're doing. And then of course our numpy numbers array and just a straight OS access. Wow. So that was a lot of imports. Uh like I said, I'm not going to spend I spent a little time going through them. Uh but we didn't want to go too much into them. And then I'm going to create um some variables that we need to go ahead initialize. We have the learning rate, number of epics to train for, and the batch size. And if you remember correctly, we talked about the learning rate uh to the -4.001 01. 11:00:51 Um, a lot of times it's 0.001 or 0.001. Usually it's in that um variation depending on what you're doing and how many epics and they kind of play with the epics. The epics is how many times are we going to go through all the data. And now I have it as two. Um, the actual setup is for 20. And 20 works great. The reason I have it for two is it takes a long time to process. One of the downsides of Jupiter is that Jupiter isolates it to a single kernel. So even though I'm on an 8 core processor uh with 16 dedicated threads, only one thread is running on this no matter what. So it doesn't matter. Uh so it takes a lot longer to run even though um TensorFlow really scales up nicely. And the batch size is how many pictures do we load at once and process. Again, those are numbers you have to learn to play with depending on your data and what's coming in. And the last thing we want to go ahead and do is there's a directory with a data set we're going to 11:01:52 run. Uh, and this just has images of mass and not masks. And if we go in here, you'll see data set. Um, and then you have pictures with mass. They're just images of people with masks on their face. Uh, and then we have the opposite. Let me go back up here. Without masks. So, it's pretty straightforward. They look kind of a skew because they tried to format them into very similar uh setup on there. So, they're they're mostly squares. You'll see some that are slightly different on here. And that's kind of important thing to do on a lot of these data sets. Get them as close as you can to each other. And we'll we actually will run in the in this processing of images up here and the cross uh layers and importing and and dealing with images. It does such a wonderful job of converting these that a lot of it we don't have to do a whole lot with. Uh so you have a couple things going on there. And so uh we're now going to be this is now loading the um images and let me see and we'll go ahead 11:02:53 and uh create data and labels. Here's our um uh here's the features going in which is going to be our pictures and our labels going out. And then for categories in our list directory directory. And if you remember, I just flashed that at you. It had uh uh face mask or or no face mask. Those are the two options. And we're just going to load into that. We're going to appin the image itself and the labels. So, we're just create a huge array. Uh and you can see right now this could be an issue if you had more data at some point. Um, thankfully I have a a 32 gig hard drive or um RAM. Even that does you could do with a lot less of that. Probably under 16 or even 8 gigs would easily load all this stuff. Um, and there's a conversion going on in here. I told you about how we are going to convert the size of the image so it resizes all the images. That way our data is all identical the way it comes in. And you can see here with our labels we 11:03:55 have without mask, without mask, without mask. Uh the other one would be with mask. Those are the two that we have going in there. Uh and then we need to change it to the one hot encoding. And this is going to take our um um up here we had was it labels and data. Uh we want the labels uh to be categorical. So we're going to take labels and change it to categorical. And our labels then equal a categorical list. Uh we'll run that. And again, if we do, uh labels and we just do the last or the first 10. Let's do the last 10 just because um minus 10 to the end. There we go. Just so we can see what the other side looks like. We now have one. That means they have a mask. 1 0 1 0 so on. Uh one being they have a mask and zero no mask. And if we did this in reverse, I just realized that this might not make sense if you've never done this before. 11:04:57 Let me run this. 01. So zero is uh do they have a mask on? Zero. Do they not have a mask on? One. So this is the same as what we saw up here without mask. One equals uh the second value is without mask. So with mass without mask uh and that's just a with any of your data processing we can't really a zero if you have a 01 output uh it causes issues as far as training and setting it up. So we always want to use a one hot encoder if the values are not actual uh linear val or regression values. They're not actual numbers if they represent a thing. And so now we need to go ahead and do our train X, test X, train Y, test Y, um, train split test data. And we'll go ahead and make sure it's going to be uh, random. And we'll take 20% of it for testing and the rest for um, setting it 11:05:59 up as far as training their model. This is something that's become so cool. When they're training these set, uh, they realize we can augment the data. What does augment mean? Well, if I rotate the data around and I zoom in, I zoom out, I rotate it, um, share it a little bit, flip it horizontally, um, fill mode as I do all these different things to the data, it, um, is able to, it's kind of like increasing the number of samples I have. Uh, so if I have all these perfect samples, what happens when we only have part of the face or the face is tilted sideways or all those little shifts cause a problem if you're doing just a standard set of data. So, we're going to create an augment and our image data generator um, which is going to rotate, zoom, and do all kinds of cool thing. And this is worth looking up this image data generator and all the different features it has. Um, a lot of times I'll the first time through my models, I'll leave that out because I want to make sure 11:07:00 there's a thing we call build to fail, which is just cool to know. You build the whole process and then you start adding these different things in uh so that you can better train your model. And so we go and run this and then we're going to load um and then we need to go ahead and you probably would have gotten an error if you hadn't put this piece in right here. Um I haven't run it myself because the guys in the back did this. Uh but we take our base model and one of the things we want to do is we want to do a mobile net v2. Um and this what we this is a big thing right here include the top equals false. A lot of data comes in with a label on the top row. Uh so we want to make sure that that is not the case. Uh and then the construction of the head of the model that will be placed on the top of the base model. Uh we want to go ahead and set that up. And you'll see a warning here. I'm kind of ignoring the warning because it has to do with the uh size of the pictures and the weights for input shape. Um so 11:08:02 they'll it'll switch things to defaults. Just saying, "Hey, we're going to autoshape some of this stuff for you." You should be aware that with this kind of imagery, we're already augmenting it by moving it around and flipping it and doing all kinds of things to it. Uh so that's not a bad thing in this, but in other data, it might be if you're working in a different domain. And so we're going to go back here and we're going to have we have our base model. We're going to do our head model equals our base model output. Um and what we got here is we have an average pooling 2D pool size 77 head model. Um head model flatten. So we're flattening the data. Uh so this is all processing and flattening the images and the pooling has to do with some of the ways it can process some of the data. We'll look at that a little bit when we get down to the lower level and just processing it. Um and then we have our dense. We've already talked a little bit about a dense just what you think about. And then the head model has a dropout of 0.5. Uh what we can do with a dropout? 11:09:07 The dropout says that we're going to drop out a certain amount of nodes while training. Uh so when you actually use the model, it will use all the nodes, but this drops certain ones out and it helps stop biases from. Uh so it's really a cool feature on here. They discovered this a while back. Uh we have another dense mode and this time we're using soft max activation. Lots of different activation options here. Softmax is a real popular one for a lot of things and so is the Reu and you know there's we could do a whole talk on activation formulas uh and why what their different uses are and how they work. When you first start out you'll you'll use mostly the RLU and the softmax for a lot of them uh just because they're they're some of the basic setups. It's a good place to start. Uh and then we have our model equals model inputs equals base model.input input outputs equals head model. So again, we're still building our model here. We'll go ahead and run that. 11:10:08 And then we're going to loop over all the layers in the base model and freeze them so they will not be updated during the first training process. Uh so for layer and base model layers, layers.trainable equals false. A lot of times when you go through your data, um you want to kind of jump in partway through. Um I I'm not sure why in the back they did this for this particular example. Um but I do this a lot when I'm working with series and and specifically in stock data. I wanted to iterate through the first set of 30 data before it does anything. Um I would have to look deeper to see why they froze it on this particular one. And then we're going to compile our model. Uh so compiling the model atom init layer decay um initial learning rate over epics and we go ahead and compile. Our loss is going to be the binary cross entropy which we'll have that print out. Optimizer for opt metrics is accuracy. Same thing we had 11:11:10 before. Not a huge jump as far as um the previous code. And then we go ahead and we've gone through all this and now we need to go ahead and fit our model. Uh so train the head of the network print info training head run. Now I skipped a little time because it you'll see the run time here is um at 80 seconds per epic takes a couple minutes for it to get through on a single kernel. One of the things I want you to notice on here while we're while it's finishing the processing is that we have up here our augment going on. So anytime the train X and train Y go in, there's some randomness going on there and is jiggling it around what's going into our setup. Uh, of course we're batch sizing it. Uh, so it's going through whatever we set for the batch values, how many we process at a time. And then we have the steps per epic uh the train x the batch size 11:12:12 validation data. Here's our uh test x and test y where we're sending that in. Uh and this again it's validation. One of the important things to know about validation is our um when both our training data and our test data have about the same accuracy. That's when you want to stop. That means that our model isn't biased. If you have a higher accuracy on your uh testing, you know, you've trained it and your accuracy is higher on your actual test data, then something in there is probably uh has a bias and it's overfitted. Uh so that's what this is really about right here with the validation data and validation steps. So it looks like it's let me go ahead and see if it's done processing. Looks like we've gone ahead and gone through two epics. Again, you could run this through about uh 20 with this amount of data and it would give you a nice refined uh model at the end. We're only going to stop at two because I really don't want to sit around all afternoon 11:13:13 and I'm running this on a single thread. So, now that we've done this, we're going to need to evaluate our model and see how good it is. And to do that, we need to go ahead and make our predictions. Um these are predictions on our test X to see what it thinks are going to be. Uh so now it's going to be evaluating the network. And then we go ahead and go down here and we will need to uh turn the index in because remember it's it's either zero or one. It's uh 0 one 01. So you have two outputs uh not wearing uh wearing a mask, not wearing a mask. And so we need to go ahead and take that argument at the end and change those predictions to a zero or one coming out. Uh, and then to finish that off, we want to go ahead and let me just put this right in here and do it all in one shot. We want to show a nicely formatted classification report so we can see what that looks like on here. And there we have it. We have our precision. Uh, it's 97% with a mask. 11:14:15 There's our F1 score. Support without a mask, 97%. Um, so that's pretty high high uh setup on there. you know, three people are going to sneak into the store who are without a mask and that thinks they have a mask and there's going to be three people with a mask that's going to flag the person at the front to go, "Oh, hey, look at this person. He might not have a mask." Um, it's I guess it's just set up in front of a store. Um, so there there you have it. And of course, one of the other cool things about this is if someone's walking into the store and you take multiple pictures of them. Um, you know, this is just an it would be a way of flagging and then you can take that average of those pictures and make sure they match or don't match if you're on the back end. And this is an important step because we're going to this is just cool. I love doing this stuff. Uh, so we're going to go ahead and take our model and we're going to save it. Uh, so model save mass detector.mmodel. We're going to give it a name. Uh we're going to save the format. Um in this case we're going to use the H5 format. 11:15:16 And so this model we just programmed has just been saved. Uh so now I can load it up in model. Now they can use it for whatever. And then if I get more information uh and we start working with that at some point I might want to update this model um make a better model. And this is true of so many things where I take this model and maybe I'm uh running a prediction on uh making money for a company and as my model gets better I want to keep updating it and then it's really easy just to push that out to the actual end user. Uh and here we have a nice graph. You can see the training loss and accuracy as we go through the epics. uh we only did the you know only shows just the one epic coming in here but you can see right here as the uh uh value loss train accuracy and value accuracy starts switching and they start converging and you you'll hear converging this is the convergence they're talking about when they say you're you're um I know when I work in 11:16:18 the um scikit with sklearn neural networks this is what they're talking about a convergence is our loss and our accuracy see come together and also up here. And this is why I'd run it more than just two epics. As you can see, they still haven't converged all the way. Uh so that would be a cue for me to keep going. But what we want to do is we want to go ahead and create a new Python 3 program and we just did our train mask. So now we're going to go ahead and import that and use it and show you in a live action. uh get a view of uh both myself in the afternoon along with my background of an office which is in the middle still of reconstruction for another month. And we'll call this uh mask detector. And then we're going to grab a bunch of 11:17:19 um a few items coming in. Uh we have our um mobile net v2 import pre-processing input because we're still going to need that. Um we still have our TensorFlow image to array. We have our load model. That's where most of the stuff's going on. This is our CV2 or our open CV. Again, I'm not going to dig too deep into that. We're going to flash a little open CV code at you. Uh and we actually have a tutorial on that coming out. um our numpy array, our IM utilities which is part of the open CV or CV2 setup. Uh and then we have of course time and just our operating system. So those are the things we're going to go ahead and set up on here. And then we're going to create this takes just a moment our module here which is going to do all the heavy lifting. Uh so we're going to detect and predict a mask. We have frame 11:18:20 facet masknet. These are going to be generated by our open CV. We have a frame coming in and then we want to go ahead and and create a mask around the face. It's going to try to detect the face and then set that up so we know what we're going to be processing through our model. Um and then there's a frame shape here. This is just our um height versus width. That's all HW stands for. Um, they've called it blob, which is a CV2 DNN blob form image frame. So, this is reformatting this frame that's going to be coming in literally from my camera. And we'll show you that in a minute. That little piece of code that shoots that in here. Uh, and we're going to pass the blob through the network and obtain the face detections. Uh so facet set import blob detections facenet forward print detections shape. Uh so this is this is what's going on here. This is that model we just created. 11:19:20 We're going to send that in there and I'll show you in a second where that is. But it's going to be under facet. Uh and then we go ahead and initialize our list of faces, their corresponding locations and the list of predictions from our face mask network. We're going to loop over the detections. And this is a little bit more work than you think um as far as looking for different faces. What happens if you have a fa a crowd of faces? Um so we're looping through the detections and the shapes going through here and probability associated with the detection. Uh here's our confidence of detections. We're going to filter out weak detection by ensuring the confidence is greater than the minimum confidence. Uh so we've set it remember 0ero to one so 0.5 would be our minimal confidence probably is pretty good. Um and then we're going to put in compute bounding boxes for the object. If I'm zipping through this it's because we're going to do an open CV and I really want to stick to just the KAS part. 11:20:21 And so I'm I'm just kind of jumping through all this code. You can get a copy of this code from SimplyLearn and take it apart or look for the Open CV coming out. and we'll create a box. Uh the box sets it around the image. Ensure the bounding boxes fall within the dimensions of the frame. Uh so we create a box around what's going what we hope is going to be the face. Extract the face ROI. Convert it from BGR to RGB channel. Again, this is an open CV issue. Not really an issue, but it has to do with the order. Um, I don't know how many times I've forgotten to check the order colors when working with OpenCV causes all kinds of fun things when red becomes blue and blue becomes red. Uh, then we're going to go ahead and resize it, process it, frame it. Uh, face frame setup again. The face, the CVT color, we're going to convert it. Uh, we're going to resize it. Image to array. Pre-process the input. Uh, pin the face. 11:21:22 locate face, start X, start Y, and X. Boy, that was just a huge amount. And I skipped over a ton of it, but the bottom line is we're building a box around the face. And that box, because the Open CV does a decent job of finding the face, and that box is going to go in there and see, hey, does this person have a mask on it? Uh, and so that's what that's what all this is doing on here. And then finally, we get down to this where it says predictions equals masset.predict predict faces batch size 32. Uh so these different images and where we're guessing where the face is are then going to go through and generate an array of faces, if you will, and we're going to look through and say, does this face have a mask on it? And that's what's going right here is our prediction. That's the big thing that we're working for. And then we return the locations and the predictions. The location just tells where on the picture it is. And then the um prediction tells us what it is. Is it a mask or is it not a mask? All right. 11:22:23 So, we've loaded that all up. So, we're going to load our serialized face detector model from disk. Um and we have our the path that it was saved in. Obviously, you're going to put it in a different path depending on where you have it or however you want to do it and how you saved it on the last one where we trained it. Uh and then we have our weights path. Um, and so finally, our facet, here it is, equals cb2.dnn readet uh prototext path weights path. And we're going to load that up on here. So, let me go ahead and run that. And then we also need to I'll just put it right down here. I always hate separating these things in there. Um, and then we're going to load the actual mass detector model from disk. This is the the the model that we saved. So, let's go ahead and run that on there also. So, this is pulling in all the different pieces we need for our model. And then the next part is we're going to create open up our video. Uh, and this is just kind of fun because it's all part of the Open CV 11:23:26 video setup. And let me just put this all in as one. There we go. Uh, so we're going to go ahead and open up our video. We're going to start it and we're going to run it until we're done. And this is where we get some real like kind of liveaction stuff which is fun. This is what I like working about with images and videos is that when you start working with images and videos, it's all like right there in front of you. It's visual and you can see what's going on. Uh so we're going to start our video streaming. This is grabbing our video stream source zero start. Uh that means it's c grabbing my main camera I have hooked up. Um and then you know starting video you're going to print it out. Here's our video source equals zero start loop over the frames from the video stream. Oops, a little redundancy there. Um, let me close. I'll just leave it. That's how they had it in the code. So, uh, so while true, we're going to grab the frame from the 11:24:26 threaded video stream and resize it to have the maximum width of 400 pixels. So, here's our frame. We're going to read it, uh, from our visual, uh, stream. We're going to resize it. And then we have we're returning remember we returned from the our procedure the location and the prediction. So detect and predict mask. We're sending it the frame. We're sending it the face net and the mask net. So we're sending all the different pieces that say this is what's going through on here. And then it returns our location and predictions. And then for our box and predictions in the location and predictions um and the box is is again this is an open CV set that says hey this is a box coming in from the location um because you have the two different points on there and then we're going to unpack the box and predictions and we're going to go ahead and do mask without a mask equals prediction. We're going to create our label. No mask. We're going to create color. If 11:25:28 the label equals mask, L00225. And you know, this is going to make a lot more sense when I hit the run button here. Uh, but we have the probability of the label. We're going to display the label and bounding box rectangle in the output frame. Uh, and then we're going to go ahead and show the output from the frame. CV2 im show frame frame. And then the key equals CV2 weight key one. We're just going to wait till the next one comes through from our feed. And we're going to do this until we hit the stop button pretty much. So, are you ready for this? Let's see if it works. We've distributed our uh our model. We've loaded it up into our distributed uh code here. We've got it hooked into our camera and we're going to go ahead and run it. And there it goes. It's going to be running. And we can see the data coming down here. And we're waiting for the popup. And there I am in my office with my funky headset on. Uh, and you can see in the background my unfinished wall. And it says up here, no mask. Oh no, I don't 11:26:28 have a mask on. Uh, I wonder if I cover my mouth. What would happen? Uh, you can see my no mask goes down a little bit. I wish I brought a mask into my office. It's up at the house. But you can see here that this says, you know, there's a 95 98% chance that I don't have a mask on. And it's true. I don't have a mask on right now. And this could be distributed. This is actually an excellent little piece of script that you could start, you know, you install somewhere on a a video feed on a on a security camera or something and then you'd have this really neat uh setup saying, "Hey, do you have a mask on when you enter a store or a public transportation or whatever it is where they're required to wear a mask?" Uh, let me go ahead and stop that. Now, if you want a copy of this uh code, definitely give us a hauler. We will be going into Open CV and another one. So, I skipped a lot of the Open CV um code in here as far as going into detail. Really focusing on the KAS uh saving the 11:27:30 model, uploading the model, and then processing a streaming video through it. So, you can see that the model works. We actually have this working model that hooks into the video camera, which is just pretty cool and a lot of fun. So, I told you we're going to dive in and really roll up our sleeve and do a lot of coding today. Uh we did the basic uh demo up above for just pulling in a cross and then we went into a cross model uh where we pulled in data to see whether someone was wearing a mask or not. So very useful in today's world as far as a fully running application. In today's video, we are diving deep into the world of machine learning interview preparation. As we gear up for 2024, it's crucial to be well prepared for the questions that can come your way in any machine learning interview. We have compiled 30 essential interview questions and answers thoughtfully categorized into beginner, intermediate and advanced levels. So let's start with beginner level questions. And number one is what is machine learning? So machine 11:28:31 learning is a subset of artificial intelligence that involves the use of algorithms and statistical models to enable computers to perform task without explicit instructions that is by relying on patterns and interference. And now moving to number second question that is what are the different types of machine learning. So the three main types of machine learning are number one is supervised learning and then comes unsupervised learning and then there is reinforcement learning. Now moving to next question that is third that is what is supervised learning. So supervised learning involves training a model on a label data set which means each training example is paired with an output label. The model learns to predict the output from the input data. Now moving to the fourth question that is what is unsupervised learning. So unsupervised involve training a model on data that does not have labeled responses. The model tries to learn the patterns and the structure from the input data. So 11:29:31 guys these are the beginner level questions. And now we'll move to the fifth question that is what is reinforcement learning. So reinforcement learning is a type of machine learning where an agent learns to make decisions by performing actions and receiving rewards or penalties. The goal is to maximize the cumulative reward. So now moving to the sixth question that is what is a model in machine learning. So a model in machine learning is a mathematical representation of a real world process. It is trained on data to recognize patterns and make predictions or decisions based on new data. So now moving to seventh question that is what is overfitting? So overfitting occurs when a machine learning model performs well on the training data but poorly on new unseen data. It indicates that the model has learned the noise and details in the training data instead of the actual patterns. So now coming to question number eight that is what is underfitting? So underfitting occurs when a machine learning model is too simple to capture the underlying 11:30:31 patterns in the data. it performs poorly on both the training data and new data. Now move to the next question that is ninth question and the question is what is a confusion matrix? So confusion matrix is a table used to evaluate the performance of a classification model. It summarizes the number of correct and incorrect predictions made by the model and that is categorized by each class. Now moving to the 10th question that is what is cross validation? So cross validation is a technique for assessing how the results of a statistical analysis will generalize to an independent data set. It involves partitioning the data into subsets, training the model on some subsets and validating it on the remaining subsets. This was all about that is the 10th question or the overall 1 to 10 questions for beginner level. Now we'll move to intermediate level and here we'll cover 10 questions. So we'll start with 11th question that is what is a ROC curve. So ROC that is receiver operating 11:31:34 characteristic curve. It is a graphical representation of a classifier's performance across different thresholds. It plots the true positive rate that is TPR against a false positive rate that is FPR. Now moving to 12th question that is what is precision and recall. So precision is the ratio of correctly predicted positive observations to the total predicted positives and recall is the ratio of correctly predicted positive observations to all actual positives. So the formula is precision equal to TP/TP plus FP and the recall is TP/TP + FN. So now we'll move to the 13th question that is what is the F1 score? So the F1 score is the harmonic mean of precision and recall. It provides a balance between the two metrics and is useful when you need to balance precision and recall. F1 score is equal to twice into precision into recall and 11:32:35 that is divided by precision plus recall. Now we'll move to 14th question and here we will cover regularization. So the question is what is regularization? So it is a technique used to prevent overfitting by adding a penalty to the model's complexity. And the common types of regularization include L1 that is lasso and L2 ridge regularization. Now we'll move to the 15th question that is what is the bias variance tradeoff. So the bias variance trade-off is a fundamental issue in machine learning that involves balancing the error introduced by the model's assumptions and the error due to model complexity. So a good model should have low bias and low variance. Now we'll move to the question number 16 that is what is feature engineering. So feature engineering is the process of creating new features or modifying existing ones to improve the performance of a machine learning model. It involves techniques like normalization and coding categorical variables and creating 11:33:37 interaction terms. So now we'll move to question number 17 and that is about gradient descent. So the question is what is gradient descent and your answer is gradient descent is an optimization algorithm used to minimize the cost function in machine learning models and it iteratively adjusts the model parameters in the direction of the steepest descent of the coast function. So with this we'll move to the 18th question and that we'll cover with the difference between bagging and boosting. So the question is what is difference between bagging and boosting and you could answer this with starting with bagging that is bootstrap aggregating that involves training multiple models on different subsets of the data and averaging their predictions. Then comes boosting that involves training models sequentially with each new model focusing on correcting the errors of the previous ones. And then we have the question number 19 that is what is a decision tree? So a decision tree is a nonparametric supervised learning 11:34:39 algorithm used for classification and regression. It splits the data into subsets based on the value of input features resulting in a treel like structure of decisions. Now we'll move to question number 20 that is what is a random forest? So random forest is an ansemble learning method that combines multiple decision trees to improve the accuracy and robustness of the model. It builds each tree using a random subset of features and data points and then averages their predictions. So these were the questions that are for the intermediate level and these are just the basic questions or I will just say the theoretical questions that can be asked in an interview. So be prepared for that. Now we'll move to the advanced level interview questions and we'll start with question number 21. And here also we'll cover the 10 questions. So number one question or that is 21 question and the question is what is a support vector machine? So support vector machine is a supervised learning algorithm used for classification and 11:35:39 regression. It finds the optimal hyper plane that maximizes the margin between different classes in the feature space. And then comes question number 22 that is what is principal component analysis. So principal component analysis is a dimensionality reduction technique that transforms highdimensional data into a lower dimensional space by finding the directions that is principal components that maximize the variance in the data. And then comes the question number 23 that is what is a neural network? So a neural network is a series of algorithms that attempt to recognize underlying relationships in a set of data through a process that mimics the way the human brain operates. It consists of layer of interconnected nodes or neurons. And then comes the question number 24 that is what is deep learning? So deep learning is a subset of machine learning that involves neural networks with many layers that is deep neural networks and it is particularly effective for task like image and speech recognition. Now I 11:36:39 move to question number 25 that is what is convolutional neural network that is CNN. So we will start the answer by answering the interviewer that a convolutional neural network is a type of deep learning model specifically designed for processing structured grid data like images. It uses convolutional layers to extract special features or the special features and patterns from the input data. Now we'll move to the question number 26 that is what is a recurrent neural network or RNN. So a recurrent neural network is a type of neural network designed for sequential data and it has connections that form directed cycles allowing it to maintain a memory of previous inputs and process sequences of data. So this was all about question number 26 and now we will cover the question number 27 that is what is the difference between batch gradient descent and stoopastic gradient descent. So batch gradient descent computes the gradient of the coast function using the 11:37:40 entire training data set while stoastic gradient descent that is SGD computes the gradient using only one training example at a time. So SGD is faster but noisier. Now we move to question number 28 that is what is dropout in neural networks. So dropout is a regularization technique used in neural networks to prevent overfitting and it involves randomly setting a fraction of the neurons to zero during training forcing the network to learn more robust features. And now we'll move to question number 29 and that will be about transfer learning. And your question is what is transfer learning? So we'll answer this to the interviewer by starting that transfer learning is a technique in machine learning where a model developed for one task is reused as the starting point for a model on a second related task. It is particularly useful when there is limited data available for the second task. Now we'll move to the last question and the 30th question. So that is what is a 11:38:42 generative adversial network that is GN. So you can start answering this. So generative adversial network is a type of deep learning model consisting of two neural networks a generator and a discriminator that are trained simultaneously. The generator creates fake data while the discriminator tries to distinguish between real and fake data leading to the generator producing increasingly realistic data. And these questions and answers are over. And these covers a wide range of topics in machine learning and should help prepare for interviews at various levels. So that's a wrap on our full course. If you have any doubts or questions, you can ask them in the comment section below. Our team of experts will reply you as soon as possible. Thank you and keep learning with Simply Learn. Staying ahead in your career requires continuous learning and upskilling. Whether you're a student aiming to learn today's top skills or a working professional looking to advance your career, we've got you covered. Explore our impressive catalog 11:39:44 of certification programs in cuttingedge domains, including data science, cloud computing, cyber security, AI, machine learning, or digital marketing. Designed in collaboration with leading universities and top corporations and delivered by industry experts. Choose any of our programs and set yourself on the path to career success. Click the link in the description to know more. Hi there. If you like this video, subscribe to the SimplyLearn YouTube channel and click here to watch similar videos. To nerd up and get certified, click here.