We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f293c75 commit 045d3a1Copy full SHA for 045d3a1
ch07/figure4.py
@@ -8,9 +8,10 @@
8
9
# This script plots prediction-vs-actual on training set for the Boston dataset
10
# using OLS regression
11
-
+importnumpyasnp
12
fromsklearn.linear_modelimportLinearRegression
13
fromsklearn.datasetsimportload_boston
14
+fromsklearn.metricsimportmean_squared_error
15
importpylabasplt
16
17
boston=load_boston()
@@ -21,6 +22,8 @@
21
22
lr=LinearRegression()
23
lr.fit(x, y)
24
p=lr.predict(x)
25
+print("RMSE:{:.2}.".format(np.sqrt(mean_squared_error(y, p))))
26
+print("R2:{:.2}.".format(lr.score(x, y)))
27
plt.scatter(p, y)
28
plt.xlabel('Predicted price')
29
plt.ylabel('Actual price')
0 commit comments