Transcript:
Hey, guys, and welcome to this video tutorial on the R programming language. So in this video, we want to do a little bit of data analytics And what I want to do Is I want to make a prediction so given some X value, I want to produce some Y value and the perfect model for this is the linear regression model. Alright, so linear regression is an approach for modeling the relationship between scalar dependent variables or variable. I’m sorry, which would be our Y variable and one or more independent variables, which would be our X or XS variables, so in this case. I I me the first line of data. Set, you know what I want to predict and our programming language has a lots of data sets already available and we can see it just by typing in data left front seats, right parenthesis, press. Enter and then this right here will retrieve a list of the our data sets so in here. If we scroll it down to the bottom, we can see. A data set called women and women contains the average height and weights for American women. So that’s perfect. It looks like that. I have a X value, which may be our height and a y value, which would be our weight or maybe we want to predict the height. Then weight would be our X value and height would be our Y values. Those, however, you want to look at it, but in this case. I want to predict a woman’s height. I’m sorry a woman’s weight based on her height. All right, so now let’s take a look At this data set. We could do that by using the View function, That’s what the capital B. And then we type in women, which will be our data set press enter, and now we can see the data that is contained in the data set and it has 15 rows and 2 columns, height and weight. I’m not sure about the unit of measurement, but that doesn’t matter. This is what we get for now and let’s see if we can do some predictions using the linear model. Alright, so next up now, we need to use this model to make our predictions and our already has a function for it called. Lm so I’m going to create a variable called linear model. I’m going to set it equal to our LM function now. The LM function takes in a y value and the X value, and then we have to tell that the data set as well so again, our our Y value in this case is what we’re trying to predict, which is a woman’s weight so weight will be our. Y value. And then our X value will be the height now in our this is tilde that we have to use for the syntax, and then we have to put in the X value, which again is our height, so that’s just one parameter that we need for our LM function. We put a comment here. We need to tell it. The data set that were going to use. We can do that by saying data equals women because we’re going to use the women data set. And that’s basically it that sets up our model for us so again, Weight is our predicted value or our. Y value and then height is our predict or value or our X value. Okay, so I’m go ahead and press. Enter here now. Let’s take a look to see what our linear model looks like. What it what it gives us back? So I need to know the coefficients for us to use, and so here we see that our coefficient’s is or coefficients are negative. Eighty seven point, five, two and three point four five now. If you remember from maybe high school during your high or college, a function like this y equals. MX Plus B. Then that’s exactly what we’re going to be using here to do our prediction to make our prediction, so Y in this case would be the woman predicted weight and our M here will be 3.45 and our X will be our height value, so we’re going to come back to that. And then B will be negative. Eighty seven point five -, all right, so let’s make a prediction given this data set that we already have to see you know about how well is it doing? Is it making a pretty good prediction? Is it kind of accurate? So I’m going to put in 59 here for our X value. So times 59 and let’s see if we get our predicted weight value of 117 or at least somewhere close to it. Okay, so what I’m going to do is I’m going to copy this here and we can actually see. The value of top is 116 point O 3 But I pasted it here as well and then when you see if we get 116 point 0 3 so that’s pretty close to 117 That’s pretty good now. What I want to do is maybe plot our data so I could do that using the plot function and for plot II. We just do the same thing. We need a Y a y-value. We need a X value and just press. Enter, oh, I have to tell it what data set to use, so I go back. Copy this paste it. There comma data equals 1 min. Now, let’s plot it perfect. So now you see that we plotted the data set on this chart here and next. What we’re going to do is put the linear regression line on that chart, that’s. What that’s the model that we’re never using basically so to do that, we just use the app line from and then we put in the linear model that we created and it’s going to put a line through the data for us. Just like that there, so thank you guys. I hope you enjoyed this video. Please leave any questions that you have. Of course. This was a really small data set, so probably, you know, not that great to do predictions on. We usually want to do predictions on a much larger data set than just 15 rows. So you know if you have a certain height, and you’re not getting your right wait here. I would say this is actually very accurate for everyone, especially since the data sessions for American women and it’s only 15 rows. But you guys kind of get the gist of it pretty fun stuff. Anyways, Thank you guys, and I see you on the next video.