Skip to content

Commit 08c2a94

Browse files
Update Part_15_Regression.md
1 parent 4d34ebb commit 08c2a94

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

Part_15_Regression.md

+15-31
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11

22
### Fitting a line through data***
33

4-
Linear regression is the first, and therefore, probably the most fundamental
5-
model—a straight line through data.
4+
Linear regression is the first, and therefore, probably the most fundamental model—a straight line through data.
65

76
#### Description
8-
The ***boston*** dataset is useful for learning about linear regression. The \textit{boston*** dataset has the
9-
median home price of several areas in Boston. It also has other factors that might impact
10-
housing prices, for example, crime rate.
7+
The ***boston*** dataset is useful for learning about linear regression. The ***boston*** dataset has the median home price of several areas in Boston. It also has other factors that might impact housing prices, for example, crime rate.
118

129
#### Getting the data
1310

@@ -16,16 +13,15 @@ Firstly, we import the datasets model, then we can load the dataset:
1613
<pre><code>
1714
from sklearn import datasets
1815
boston = datasets.load_boston()
19-
2016
</code></pre>
2117

2218
### Implementation
2319

2420
Using linear regression in scikit-learn is very simple.
2521

2622
First, import the ***LinearRegression*** object and create an object (lets call it ***lr***):
27-
<pre><code>
2823

24+
<pre><code>
2925
from sklearn.linear_model import LinearRegression
3026
lr = LinearRegression()
3127

@@ -35,16 +31,13 @@ To fit the model, supply the independent and dependent variables to the ***fit**
3531
<pre><code>
3632

3733
lr.fit(boston.data, boston.target)
38-
39-
LinearRegression(copy_X=True, fit_intercept=True, normalize=False)
40-
34+
LinearRegression(copy_X=True, fit_intercept=True, normalize=False)
4135
</code></pre>
4236

4337
Let's take a look at the regression coefficients:
4438
<pre><code>
45-
46-
lr.coef_
47-
array([ -1.07170557e-01, 4.63952195e-02, 2.08602395e-02,
39+
lr.coef_
40+
array([ -1.07170557e-01, 4.63952195e-02, 2.08602395e-02,
4841
2.68856140e+00, -1.77957587e+01, 3.80475246e+00,
4942
7.51061703e-04, -1.47575880e+00, 3.05655038e-01,
5043
-1.23293463e-02, -9.53463555e-01, 9.39251272e-03,
@@ -53,43 +46,34 @@ Let's take a look at the regression coefficients:
5346
</code></pre>
5447

5548
A common pattern to express the coefficients of the features and
56-
their names is ***zip(boston.feature\_names, lr.coef\_)***.
49+
their names is ***zip(boston.feature_names, lr.coef_)***.
5750

5851

59-
\item We can see which factors have a negative relationship with the
60-
outcome, and also the factors that have a positive relationship.
61-
\item The per capita crime rate is the first coefficient in the regression. An increase in the per capita crime rate by town has a negative relationship with the price of a
62-
home in Boston.
63-
\end{itemize***
52+
* We can see which factors have a negative relationship with the outcome, and also the factors that have a positive relationship.
53+
* The per capita crime rate is the first coefficient in the regression. An increase in the per capita crime rate by town has a negative relationship with the price of a home in Boston.
6454

55+
### Making Predictions
6556

66-
67-
### Making Predictions***
68-
Now, to get the predictions, use the ***predict*** method of
69-
***LinearRegression***:
57+
Now, to get the predictions, use the ***predict*** method of ***LinearRegression***:
7058

7159
<pre><code>
72-
7360
predictions = lr.predict(boston.data)
74-
7561
</code></pre>
7662

7763

7864
### Residuals***
79-
The next step is to look at how close the predicted values are to the actual data. These differences are known as \textbf{residuals***.
65+
The next step is to look at how close the predicted values are to the actual data. These differences are known as ***residuals***.
8066
We can use a histogram to look at these residuals.
8167
% % GRAPHIC
8268

8369

84-
### Other Remarks***
70+
### Other Remarks
8571
The ***LinearRegression*** object can automatically normalize (or scale) the inputs:
86-
<pre><code>
8772

73+
<pre><code>
8874
lr2 = LinearRegression(normalize=True)
8975
lr2.fit(boston.data, boston.target)
90-
91-
LinearRegression(copy_X=True, fit_intercept=True, normalize=True)
76+
LinearRegression(copy_X=True, fit_intercept=True, normalize=True)
9277
predictions2 = lr2.predict(boston.data)
9378

9479
</code></pre>
95-
\end{document***

0 commit comments

Comments
 (0)