Skip to content

Commit 198bc22

Browse files
committed
ENH Plot predicted-vs-actual
1 parent c7f5e25 commit 198bc22

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

ch07/figure4.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This code is supporting material for the book
2+
# Building Machine Learning Systems with Python
3+
# by Willi Richert and Luis Pedro Coelho
4+
# published by PACKT Publishing
5+
#
6+
# It is made available under the MIT License
7+
8+
9+
# This script plots prediction-vs-actual on training set for the Boston dataset
10+
# using OLS regression
11+
12+
from sklearn.linear_model import LinearRegression
13+
from sklearn.datasets import load_boston
14+
import pylab as plt
15+
16+
boston = load_boston()
17+
18+
x = boston.data
19+
y = boston.target
20+
21+
lr = LinearRegression()
22+
lr.fit(x, y)
23+
p = lr.predict(x)
24+
plt.scatter(p, y)
25+
plt.xlabel('Predicted price')
26+
plt.ylabel('Actual price')
27+
plt.plot([y.min(), y.max()], [y.min(), y.max()])
28+
29+
plt.savefig('Figure4.png', dpi=150)

0 commit comments

Comments
 (0)