September 2019
Intermediate to advanced
420 pages
10h 29m
English
To test the generalization performance of the model, we calculate the mean squared error on the test data:
In [24]: y_pred = linreg.predict(X_test)In [25]: metrics.mean_squared_error(y_test, y_pred)Out[25]: 14.995852876582541
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 [26]: 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