 Hi, in this video, I'm going to show you three different ways to calculate our square, the coefficient of determination using Python. So let's get down to it. So the data set that we're going to use is what we've been using previous videos the nuclear power versus drowning data set. And the first option uses the correlation coefficient or core here. And so we'll calculate it. As you've done previously, we'll put in one variable and the order doesn't matter here. So let's go with drowning and we'll say dot core, the function that we have here. And the other variable, in this case, nuclear. And we'll print this out. We'll say, okay, here's our coefficient, our correlation coefficient, which is going to be equal to this reported value we'll round it off just so it's not a whole bunch of decimal places. So we'll say that point nine ones are pretty high correlation. And we can find our squared as just the square of that so we'll say our two is equal to our squared here, and then we will print that out. So be our coefficient of determination, or I guess put our our squared. And this is our two, we'll go ahead and run that. So the square of point nine but point eight one so you're moderately good, our squared value. Okay, the second option uses the linear grass function which we've seen previously as well. And in this case, we have to import our sci fi stats package. So this is stats, and we'll say output equals stats that land regress as you've done before. And we'll have our X variable and our why, or our explanatory variable and our response variable here. So we'll see what our output looks like. You've seen this before. We've got all these values. The one we want to focus on is our R value will note that this is equal to our correlation coefficient that we have above. And so we can pull that out and square it again. And we'll say print R squared is equal to output dot R value and we will square this in place. And let's also round this just so we don't get this huge string of numbers. So around that also to three decimal places. And go ahead and run that. And there we go we get the same thing point eight one two. All right and then the third and final way is using a new method which you haven't seen before this from the stats models package and so we'll import that here. We'll have to say import stats models dot API. And we'll import this as SM for shorthand so we're going to have to write stats models API every time. And the way this works is it works is a bit more complicated than what we have in a little regress. So in our X variable, we can call this anything we want but it's handy to just call it X. And that is drowning. As we've seen before. And our Y variable. And in this case it's nuclear. So we have our X and our Y. And then we will define a model using this function OLS transfer ordinary least squares this is our simple linear model. This is our simple linear function or what we're going to do here is define the simple linear model will see we have to give it the Y first and then the X so different than what we had before. And we should get in the habit of saying has const equals true. There are for some professionals, especially economists, there might be some reason for define saying this is false but throughout this course, we should always put in has const equals true. Okay. So our model will fit it will say mod as you define above our model dot fit will do our fit function. And we'll say print. Res, I'm saying res for short hand being the results. So the results of the fit. Summary so we're going to print a summary of this model. So go ahead and run that. And there we go. And you'll note, wait a minute, we've got a negative r squared that's not possible. What's going on here. We scroll down a little bit more we'll see, we just have one line here. This line is the slope for drowning. And what we should see what we want to see is a second line giving us the intercept. So we need to go back and we need to define an intercept and the way we do that is overriding X so so we say X. SM add constant constant is another name for the intercept here so add constant to X. Okay. So all we're doing with this function here is adding an intercept term. And the linear algebra solutions is essentially adding a column of ones in our, in our matrix. And there we go. We see that our squared point eight one two. It's exactly as what we had before. Furthermore, if we scroll scroll down for a constant we get the intercept value that we saw before with the linear grass 613 and some change we can go up and check that intercept 613 some change. And similarly this the slope for our explanatory variable in this case drowning. Additionally, we get the P value associated with that slope right here and the confidence interval, I should say the 95% confidence interval. So the limits being 0.025 and 975. So we get a lot of stuff in this output here. So we get the F statistic associated with or related to the R squared as defined in the lesson here. And our degrees of freedom. So a lot of a lot of nice diagnostic output to look at here. And then we also get the P value associated with the F statistic as well. So basically the area under that F distribution above this F statistic value. Okay. And similarly input and subsequent videos, similar output I should say in subsequent videos, but we'll end here for now with our three methods for getting our R squared. Okay.