Skip to content

Commit 045d3a1

Browse files
committed
ENH Print metrics
1 parent f293c75 commit 045d3a1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

‎ch07/figure4.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
# This script plots prediction-vs-actual on training set for the Boston dataset
1010
# using OLS regression
11-
11+
importnumpyasnp
1212
fromsklearn.linear_modelimportLinearRegression
1313
fromsklearn.datasetsimportload_boston
14+
fromsklearn.metricsimportmean_squared_error
1415
importpylabasplt
1516

1617
boston=load_boston()
@@ -21,6 +22,8 @@
2122
lr=LinearRegression()
2223
lr.fit(x, y)
2324
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)))
2427
plt.scatter(p, y)
2528
plt.xlabel('Predicted price')
2629
plt.ylabel('Actual price')

0 commit comments

Comments
(0)