Locked lesson.
About this lesson
We'll take a look at the coeffecients and intercepts we discovered at the end of the last video and explain what they mean.
Exercise files
Download this lesson’s related exercise files.
Explore the Coefficents and Intercepts.docx57.1 KB Explore the Coefficents and Intercepts - Solution.docx
55.6 KB
Quick reference
Explore the Coefficents and Intercepts
Next we want to find our Intercept, and the Coefficients.
When to use
Do this whenever you run a Linear Regression.
Instructions
Find the Intercept:
lin.intercept_
Find the Coefficients:
lin.coef_
Create a DataFrame of the Coefficients:
cdf = pd.DataFrame(lin.coef_[0], X_train.columns, columns=['Coeff'])
Hints & tips
- lin.intercept_
- lin.coef_
- cdf = pd.DataFrame(lin.coef_[0], X_train.columns, columns=['Coeff'])
- 00:05 So in the last video when we fed our data to our linear regression model,
- 00:09 we generated some coefficients and some intercepts.
- 00:12 So in this video I want to look at those and talk about them a little bit.
- 00:16 So to find out what these are, first we could call
- 00:20 lin.intercept_ and we can see it's at 31.47.
- 00:25 We'll talk about what that means in a second.
- 00:27 To find the coefficients, we can call it lincoef_ and
- 00:32 then we get an array of coefficients.
- 00:35 And you'll notice there's 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 of these.
- 00:40 That's because there are 13 columns in our data, right?
- 00:44 So if we remember X_train, which was just up here,
- 00:49 x, our columns, if we look at that, we could see 1,
- 00:54 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13.
- 01:01 So it's those 13 things, that's what these coefficients are, one for each one.
- 01:06 So we can actually create a coefficient data frame just to make it easier to read.
- 01:11 Let's call it cdf, coefficient data frame.
- 01:14 And let's just set this equal to, it's going to be a pd.DataFrame.
- 01:19 And we want to go lin.coef_ and then it's going to
- 01:25 be X_train, or X because they're the same,
- 01:30 .columns.
- 01:34 And then let's just create a column header called, I don't know, Coeff.
- 01:39 Needs to be in quotation marks.
- 01:46 And you notice we're getting an error.
- 01:47 That's because this is an array inside of an array, so
- 01:51 we need to designate this to be the zeroth item.
- 01:54 When we do that, it works out fine.
- 01:56 Then we can go cdf and we can call this.
- 01:57 So we have a list of our coefficients for each of our items.
- 02:03 So that's very cool.
- 02:05 So what does these two things mean, the coefficients and the intercept?
- 02:08 Well, the intercept is just simply not that important but
- 02:14 it's the expected mean value of y when all x is 0.
- 02:17 So if we go to our linear regression model, we can see here,
- 02:21 this is just from Wikipedia we looked at earlier.
- 02:24 When x is 0, y, here, is 5.
- 02:28 So the y intercept here is 5, right?
- 02:31 Ours is 31.
- 02:33 So ours would be way up here, not even on this chart.
- 02:36 So it's just something to keep in mind but it's not all that important.
- 02:39 When we look at a scatterplot later on, we'll remark on this but
- 02:44 that's really all.
- 02:45 The thing that's more interesting are the coefficients, right?
- 02:49 Each of these coefficients, as I said, relates to one of these columns.
- 02:52 And basically it means, if we hold all other things fixed,
- 02:57 a one unit increase in x correlates to an increase of
- 03:02 whatever that coefficient is in, for instance, price.
- 03:05 So, it looks like, for instance here,
- 03:09 as taxes go down, price goes down this much.
- 03:15 So for instance age,
- 03:18 as the house gets older the price of the house will go up just a very little bit,
- 03:23 so apparently age doesn't have a whole lot to do with things.
- 03:25 So here as the crime rate goes up, the price goes down.
- 03:29 Think about that.
- 03:31 As there's more crime in the area, the houses get cheaper.
- 03:34 That kind of makes sense, right?
- 03:35 There's always cheaper houses where there's more crime.
- 03:39 Houses cost more in safer neighborhoods.
- 03:41 So it kind of makes sense.
- 03:42 So these are our coefficients and we'll talk about these more as we make
- 03:45 predictions and analyze our results, which we'll start to do in the next video.
Lesson notes are only available for subscribers.