 Hello, welcome to this video session. In this video session, we're going to see a live hands-on demonstration on visualizing a linear regression using scikit-learn library. So what exactly is planned as an outcome for this video session? Let us move over to that slide. So at the end of this session, the audience will be able to demonstrate linear regression using scikit-learn library. So before going to the hands-on session, let us quickly see what all the hands-on session would be focusing on. The first would be to generate a proper data set so that your linear regression can be modeled on. And then we will add some small noise to the data set so that we can actually see linear regression being learned. And what we will be doing next is we will use the scikit-learn library's linear regression method under the linear models package category. And in the end, once we train the model and when we fit the model, we will also visualize the results by using matplot library to plot and visualize the results as well. So let us move to the hands-on session here. So I have a Google collab space, which I'm going to switch to. And I'll be typing all in the collab editor. So this is Google collab workspace. So let me type the code snippet type-by-type here. So the first thing here is we'll import the required libraries. The most important library, which we always require is numpy, which we'll import as np. And then we'll also import, so a linear model from scikit and instead of importing entire library, we'll implement linear, since we are going to implement linear regression, what we'll do is we'll only implement from linear model, so we'll import linear regression. Most often Google collab gives you suggestions and they are very quite helpful during typing this hands-on session. And we'll also be importing matplotlib. And under matplotlib we'll prefer this, where I will be using plot and access method to plot the visualization of linear regression. So once we have a proper import system, let me execute this segment, yes. So then I'll move to next code segment wherein we will initialize a data set. So in short, when we're talking about linear regression, here we rely on, let's say, so we rely on linear regression and specifically we will implement linear regression for equation of y is equal to 5 times x, where phi is my coefficient, plus the intercept I will be using is 2. So for this linear equation, so we are targeting a point which observes this pattern. And through that pattern, we will train our linear regression model so that it can understand or it can learn and guess the right coefficient values and intercept values based on the data set we generate. So let us generate a data set. So we will use numpy to generate a random set and let x be a, we will stick to a sample of 100. So we will define some variable size is equal to 100. And let me initialize some random variables, np. we'll use np.random. And under that, we will initialize few random values of size 100 rows and column 1. And once we have done with this, it is better I call reshape. Let me check what exact values we get it. I don't think there is a need for reshaping it. So if I see an output of this, so okay, I can see that I have a vector, two dimensional vector 100 rows in one column. So I have a x data set. Now when I have a x data set, we will be generating y. So we also need y points and y points would be adhering to this equation. Remember I want my model to guess this 5 and this intercept 2. So instead of directly generating the points and then asking the linear regression to learn on a perfect data would not be a recommended strategy, rather we will introduce a small error margin, say plus 2% to minus 2%. So to introduce that error margin, let me generate an array of some random values in a uniform distribution. So I'll use np.random.uniform. So for that I need it takes a range. So low, high and size. So what I'll do is since I want from negative 2% to positive 2%, I'll use the following values, 2% in the sense 0.02 and the positive boundary would be 0.02 and I want size is equal to the size which we have defined. So this will generate the error, random error. And once we have this, what we'll be doing is we will now generate, let us do one thing. We will modify this e is equal to e plus 1 so that I want that the random values to be converted into percentage, percentage margin. So I use on that principle that if I want a 2% increase, I multiply by the value by 1.02. So I will be doing plus and let me print e and see what exactly I get here. Let me execute this code segment. So I can see here, I have these are the percentages. So this indicates percentage increment by 1.5% and this denotes a decrement. This is 1.1 and it's almost 0.001 decrement. So these values I'll be using to generate my y values, y is equal to, so I have a 5. So now instead of directly taking 5, I'll multiply 5 by e. So I get a few increment or decrement on coefficient. So I'm introducing a slight noise in the data. I'm not taking a perfect multiplication. So multiplied by x and plus 2, that should give me the value for this one. Let me see what values we get. Now we do too much of, we generated is equal to but we forgot to reshape it into the dimensions which we require. Let me reshape it to 100 comma 1. So what wrong we did was, I won't call it as wrong. It's like we have generated a 20 rows each of 100 columns and your actual linear regression tray was trained on 20 times, 20 iterations have happened here. So let us reshape it so that I will end up with only one data set. So I have reshaped it. I think now we won't be having any issue with this. Let me check the shape of y here for once. It is a 100 and 100. We shouldn't get it a 100 and 100. So maybe we also reshape x. We have to initialize it's not this one. So e.reshape 100. So now we have a proper y. So now when you do all this, so now you can even check what values I'm getting here. So earlier I used to get 20 intercepts for 20 iterations. Since when I, okay, so now, okay, now we will only get that because now the shape of y dash per each is 20 rows in one column. So now I think it would be easy to plot. So these are the coefficient is learned around 2 and this is around 5. You will see that they are not exactly same to this because we have introduced a small noise here because now everyone is, okay, now you can see this. So if you look at this, this is a train sample. So almost 80 points, okay, almost we have a y train in this and to be far more precise if you want to guess what exactly we learned by the coefficient. So with noise, so instead of it is not, it is, it is actually model.coefficient plus based on learned intercept and the model values. And here if I pass one more plot with x, but now I'll use the noise sample, change the color to green. So if I execute it now, okay, you can see almost my line which learned is fine. You can see that there's a slight deviation here. So now you can experiment with this more the sample, more the error. It is up to the person who is working on to experiment with this model and see what all parameters which are being learned right now in this case. These are the parameters which we are learning. What the data size has an effect, what the test split has the effect and what the error introduced in that. For example, we call it as noise, how it would be affecting entire linear model. So you can experiment with this. So that's it for this video. So this was there for hands-on. As a quick reflection for this video, I would like to put a question is after training the linear regression model in scikit, what do you think? Like, are we able to retrieve the coefficient and intercept which my model has learned? So you can pause the video, you can visit back the video from the start and you can find the answer. The answer is yes, I can always retrieve it. How exactly you can see here, these are the values, how I retrieve that model.intercept and model.coefficient. So this is a reference, curious readers can visit this reference and find out more about the linear regression model which we use from scikit library. So that's it for this video. Thank you.