July 2017
Intermediate to advanced
382 pages
9h 13m
English
In order to test the generalization performance of the model, we calculate the mean squared error on the test data:
In [11]: y_pred = linreg.predict(X_test)In [12]: metrics.mean_squared_error(y_test, y_pred)Out[12]: 15.010997321630166
We note that the mean squared error is a little lower on the test set than the training set. This is good news, as we care mostly about the test error. However, from these numbers, it is really hard to understand how good the model really is. Perhaps it's better to plot the data:
In [13]: plt.figure(figsize=(10, 6))... plt.plot(y_test, linewidth=3, label='ground truth')... plt.plot(y_pred, linewidth=3, label='predicted')... plt.legend(loc='best')... plt.xlabel('test data points')... plt.ylabel('target ...Read now
Unlock full access