11/15/23, 1:21 AM
17.6. Multiple Regression — Computational and Inferential Thinking
https://inferentialthinking.com/chapters/17/6/Multiple_Regression.html
4/12
In fact, none of the individual attributes have a correlation with sale price that is above 0.7
(except for the sale price itself).
However, combining attributes can provide higher correlation. In particular, if we sum the first
floor and second floor areas, the result has a higher correlation than any single attribute alone.
This high correlation indicates that we should try to use more than one attribute to predict the
sale price. In a dataset with multiple observed attributes and a single numerical value to be
predicted (the sale price in this case), multiple linear regression can be an effective technique.
17.6.2. Multiple Linear Regression
In multiple linear regression, a numerical output is predicted from numerical input attributes by
multiplying each attribute value by a different slope, then summing the results. In this example,
the slope for the
1st Flr SF
would represent the dollars per square foot of area on the first
floor of the house that should be used in our prediction.
0.6424662541030225
for
label
in
sales
.
labels:
print
(
'Correlation of'
, label,
'and SalePrice:\t'
, correlation(sales, label,
'Sale
Correlation of SalePrice and SalePrice:
1.0
Correlation of 1st Flr SF and SalePrice:
0.6424662541030225
Correlation of 2nd Flr SF and SalePrice:
0.3575218942800824
Correlation of Total Bsmt SF and SalePrice:
0.652978626757169
Correlation of Garage Area and SalePrice:
0.6385944852520443
Correlation of Wood Deck SF and SalePrice:
0.3526986661950492
Correlation of Open Porch SF and SalePrice:
0.3369094170263733
Correlation of Lot Area and SalePrice:
0.2908234551157694
Correlation of Year Built and SalePrice:
0.5651647537135916
Correlation of Yr Sold and SalePrice:
0.02594857908072111
both_floors
=
sales
.
column(
1
)
+
sales
.
column(
2
)
correlation(sales
.
with_column(
'Both Floors'
, both_floors),
'SalePrice'
,
'Both Floors'
)
0.7821920556134877
Skip to main content