Skip to content

Commit 339cf2a

Browse files
committed
FIG Simplify figure
Only one regression line in each plot
1 parent e0d4022 commit 339cf2a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ch07/figure1_2.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@
4242

4343
lr.fit(x, y)
4444

45-
plt.plot([0, boston.data[:, 5].max() + 1],
46-
[0, lr.predict(boston.data[:, 5].max() + 1)], '-', lw=4)
45+
plt.clf()
46+
plt.xlabel("Number of rooms (RM)")
47+
plt.ylabel("House Price")
48+
plt.scatter(boston.data[:, 5], boston.target)
49+
xmin = x.min()
50+
xmax = x.max()
51+
plt.plot([xmin, xmax], lr.predict([[xmin], [xmax]]) , '-', lw=4)
4752
plt.savefig('Figure2.png', dpi=150)
4853

4954
mse = mean_squared_error(y, lr.predict(x))

0 commit comments

Comments
 (0)