Skip to content

Commit 8fa667b

Browse files
committed
update numbered and captioned figures
1 parent 380bedc commit 8fa667b

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

lectures/simple_linear_regression.md

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ We can use a scatter plot of the data to see the relationship between $y_i$ (ice
6060
---
6161
mystnb:
6262
figure:
63-
name: wpdisc
63+
caption: "Scatter plot"
64+
name: sales-v-temp
6465
---
6566
ax = df.plot(
6667
x='X',
@@ -88,8 +89,14 @@ df['Y_hat'] = α + β * df['X']
8889
```
8990

9091
```{code-cell} ipython3
92+
---
93+
mystnb:
94+
figure:
95+
caption: "Scatter plot with a line of fit"
96+
name: sales-v-temp2
97+
---
9198
fig, ax = plt.subplots()
92-
df.plot(x='X',y='Y', kind='scatter', ax=ax)
99+
ax = df.plot(x='X',y='Y', kind='scatter', ax=ax)
93100
df.plot(x='X',y='Y_hat', kind='line', ax=ax)
94101
```
95102

@@ -103,8 +110,14 @@ df['Y_hat'] = α + β * df['X']
103110
```
104111

105112
```{code-cell} ipython3
113+
---
114+
mystnb:
115+
figure:
116+
caption: "Scatter plot with a line of fit"
117+
name: sales-v-temp3
118+
---
106119
fig, ax = plt.subplots()
107-
df.plot(x='X',y='Y', kind='scatter', ax=ax)
120+
ax = df.plot(x='X',y='Y', kind='scatter', ax=ax)
108121
df.plot(x='X',y='Y_hat', kind='line', ax=ax)
109122
```
110123

@@ -114,8 +127,14 @@ df['Y_hat'] = α + β * df['X']
114127
```
115128

116129
```{code-cell} ipython3
130+
---
131+
mystnb:
132+
figure:
133+
caption: "Scatter plot with a line of fit"
134+
name: sales-v-temp4
135+
---
117136
fig, ax = plt.subplots()
118-
df.plot(x='X',y='Y', kind='scatter', ax=ax)
137+
ax = df.plot(x='X',y='Y', kind='scatter', ax=ax)
119138
df.plot(x='X',y='Y_hat', kind='line', ax=ax, color='g')
120139
```
121140

@@ -139,9 +158,15 @@ df
139158
```
140159

141160
```{code-cell} ipython3
161+
---
162+
mystnb:
163+
figure:
164+
caption: "Plot of the residuals"
165+
name: plt-residuals
166+
---
142167
fig, ax = plt.subplots()
143-
df.plot(x='X',y='Y', kind='scatter', ax=ax)
144-
df.plot(x='X',y='Y_hat', kind='line', ax=ax, color='g')
168+
ax = df.plot(x='X',y='Y', kind='scatter', ax=ax)
169+
ax = df.plot(x='X',y='Y_hat', kind='line', ax=ax, color='g')
145170
plt.vlines(df['X'], df['Y_hat'], df['Y'], color='r');
146171
```
147172

@@ -181,6 +206,12 @@ for β in np.arange(20,100,0.5):
181206
Plotting the error
182207

183208
```{code-cell} ipython3
209+
---
210+
mystnb:
211+
figure:
212+
caption: "Plotting the error"
213+
name: plt-errors
214+
---
184215
ax = pd.Series(errors).plot(xlabel='β', ylabel='error')
185216
plt.axvline(β_optimal, color='r');
186217
```
@@ -196,6 +227,12 @@ for α in np.arange(-500,500,5):
196227
Plotting the error
197228

198229
```{code-cell} ipython3
230+
---
231+
mystnb:
232+
figure:
233+
caption: "Plotting the error (2)"
234+
name: plt-errors2
235+
---
199236
ax = pd.Series(errors).plot(xlabel='α', ylabel='error')
200237
plt.axvline(α_optimal, color='r');
201238
```
@@ -327,12 +364,18 @@ print(α)
327364
Now we can plot the OLS solution
328365
329366
```{code-cell} ipython3
367+
---
368+
mystnb:
369+
figure:
370+
caption: "OLS line of best fit"
371+
name: plt-ols
372+
---
330373
df['Y_hat'] = α + β * df['X']
331374
df['error'] = df['Y_hat'] - df['Y']
332375
333376
fig, ax = plt.subplots()
334-
df.plot(x='X',y='Y', kind='scatter', ax=ax)
335-
df.plot(x='X',y='Y_hat', kind='line', ax=ax, color='g')
377+
ax = df.plot(x='X',y='Y', kind='scatter', ax=ax)
378+
ax = df.plot(x='X',y='Y_hat', kind='line', ax=ax, color='g')
336379
plt.vlines(df['X'], df['Y_hat'], df['Y'], color='r');
337380
```
338381

0 commit comments

Comments
 (0)