@@ -60,7 +60,8 @@ We can use a scatter plot of the data to see the relationship between $y_i$ (ice
60
60
---
61
61
mystnb:
62
62
figure:
63
- name: wpdisc
63
+ caption: "Scatter plot"
64
+ name: sales-v-temp
64
65
---
65
66
ax = df.plot(
66
67
x='X',
@@ -88,8 +89,14 @@ df['Y_hat'] = α + β * df['X']
88
89
```
89
90
90
91
``` {code-cell} ipython3
92
+ ---
93
+ mystnb:
94
+ figure:
95
+ caption: "Scatter plot with a line of fit"
96
+ name: sales-v-temp2
97
+ ---
91
98
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)
93
100
df.plot(x='X',y='Y_hat', kind='line', ax=ax)
94
101
```
95
102
@@ -103,8 +110,14 @@ df['Y_hat'] = α + β * df['X']
103
110
```
104
111
105
112
``` {code-cell} ipython3
113
+ ---
114
+ mystnb:
115
+ figure:
116
+ caption: "Scatter plot with a line of fit"
117
+ name: sales-v-temp3
118
+ ---
106
119
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)
108
121
df.plot(x='X',y='Y_hat', kind='line', ax=ax)
109
122
```
110
123
@@ -114,8 +127,14 @@ df['Y_hat'] = α + β * df['X']
114
127
```
115
128
116
129
``` {code-cell} ipython3
130
+ ---
131
+ mystnb:
132
+ figure:
133
+ caption: "Scatter plot with a line of fit"
134
+ name: sales-v-temp4
135
+ ---
117
136
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)
119
138
df.plot(x='X',y='Y_hat', kind='line', ax=ax, color='g')
120
139
```
121
140
139
158
```
140
159
141
160
``` {code-cell} ipython3
161
+ ---
162
+ mystnb:
163
+ figure:
164
+ caption: "Plot of the residuals"
165
+ name: plt-residuals
166
+ ---
142
167
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')
145
170
plt.vlines(df['X'], df['Y_hat'], df['Y'], color='r');
146
171
```
147
172
@@ -181,6 +206,12 @@ for β in np.arange(20,100,0.5):
181
206
Plotting the error
182
207
183
208
``` {code-cell} ipython3
209
+ ---
210
+ mystnb:
211
+ figure:
212
+ caption: "Plotting the error"
213
+ name: plt-errors
214
+ ---
184
215
ax = pd.Series(errors).plot(xlabel='β', ylabel='error')
185
216
plt.axvline(β_optimal, color='r');
186
217
```
@@ -196,6 +227,12 @@ for α in np.arange(-500,500,5):
196
227
Plotting the error
197
228
198
229
``` {code-cell} ipython3
230
+ ---
231
+ mystnb:
232
+ figure:
233
+ caption: "Plotting the error (2)"
234
+ name: plt-errors2
235
+ ---
199
236
ax = pd.Series(errors).plot(xlabel='α', ylabel='error')
200
237
plt.axvline(α_optimal, color='r');
201
238
```
@@ -327,12 +364,18 @@ print(α)
327
364
Now we can plot the OLS solution
328
365
329
366
```{code-cell} ipython3
367
+ ---
368
+ mystnb:
369
+ figure:
370
+ caption: "OLS line of best fit"
371
+ name: plt-ols
372
+ ---
330
373
df['Y_hat'] = α + β * df['X']
331
374
df['error'] = df['Y_hat'] - df['Y']
332
375
333
376
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')
336
379
plt.vlines(df['X'], df['Y_hat'], df['Y'], color='r');
337
380
```
338
381
0 commit comments