1-
21# Linear Regression
32
43<a target =" _blank " href =" https://colab.research.google.com/github/intro-stat-learning/ISLP_labs/blob/v2.2/Ch03-linreg-lab.ipynb " >
@@ -19,7 +18,7 @@ import pandas as pd
1918from matplotlib.pyplot import subplots
2019
2120```
22-
21+
2322
2423### New imports
2524Throughout this lab we will introduce new functions and libraries. However,
@@ -95,7 +94,7 @@ A.sum()
9594
9695```
9796
98-
97+
9998
10099## Simple Linear Regression
101100In this section we will construct model
@@ -117,7 +116,7 @@ Boston = load_data("Boston")
117116Boston.columns
118117
119118```
120-
119+
121120Type ` Boston? ` to find out more about these data.
122121
123122We start by using the ` sm.OLS() ` function to fit a
@@ -132,7 +131,7 @@ X = pd.DataFrame({'intercept': np.ones(Boston.shape[0]),
132131X[:4]
133132
134133```
135-
134+
136135We extract the response, and fit the model.
137136
138137``` {python}
@@ -154,7 +153,7 @@ method, and returns such a summary.
154153summarize(results)
155154
156155```
157-
156+
158157
159158Before we describe other methods for working with fitted models, we outline a more useful and general framework for constructing a model matrix~ ` X ` .
160159### Using Transformations: Fit and Transform
@@ -225,8 +224,8 @@ The fitted coefficients can also be retrieved as the
225224results.params
226225
227226```
228-
229-
227+
228+
230229The ` get_prediction() ` method can be used to obtain predictions, and produce confidence intervals and
231230prediction intervals for the prediction of ` medv ` for given values of ` lstat ` .
232231
@@ -396,7 +395,7 @@ terms = Boston.columns.drop('medv')
396395terms
397396
398397```
399-
398+
400399We can now fit the model with all the variables in ` terms ` using
401400the same model matrix builder.
402401
@@ -407,7 +406,7 @@ results = model.fit()
407406summarize(results)
408407
409408```
410-
409+
411410What if we would like to perform a regression using all of the variables but one? For
412411example, in the above regression output, ` age ` has a high $p$-value.
413412So we may wish to run a regression excluding this predictor.
@@ -482,7 +481,7 @@ model2 = sm.OLS(y, X)
482481summarize(model2.fit())
483482
484483```
485-
484+
486485
487486## Non-linear Transformations of the Predictors
488487The model matrix builder can include terms beyond
@@ -557,7 +556,7 @@ there is little discernible pattern in the residuals.
557556In order to create a cubic or higher-degree polynomial fit, we can simply change the degree argument
558557to ` poly() ` .
559558
560-
559+
561560
562561## Qualitative Predictors
563562Here we use the ` Carseats ` data, which is included in the
0 commit comments