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
-
+import numpy as np
12
from sklearn.linear_model import LinearRegression
13
from sklearn.datasets import load_boston
14
+from sklearn.metrics import mean_squared_error
15
import pylab as plt
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