sowe can see that the data lies between - and - now that we have an estimate datawe can check what happens when we use ols to predict note that we can use exactly the same classes and methods as beforefrom sklearn linear_model import linearregression lr linearregression(fit_intercept=truelr fit(data,targetp np array(map(lr predictdata) ravel( is ( , arraywe want to flatten it -target is 'error'difference of prediction and reality total_sq_error np sum( *ermse_train np sqrt(total_sq_error/len( )print(rmse_trainthe error is not exactly zero because of the rounding errorbut it is very close (much smaller than the standard deviation of the targetwhich is the natural comparison valuewhen we use cross-validation (the code is very similar to what we used before in the boston example)we get something very different remember that the standard deviation of the data is only this means that if we always "predictthe mean value of - we have root mean square error of sowith olsin trainingthe error is insignificant when generalizingit is very large and the prediction is actually harmfulwe would have done better (in terms of root mean square errorby simply predicting the mean value every timetraining and generalization error when the number of features is greater than the number of examplesyou always get zero training error with olsbut this is rarely sign that your model will do well in terms of generalization in factyou may get zero training error and have completely useless model one solutionnaturallyis to use regularization to counteract the overfitting we can try the same cross-validation loop with an elastic net learnerhaving set the penalty parameter to nowwe get rmsewhich is better than just "predicting the meanin real-life problemit is hard to know when we have done all we can as perfect prediction is almost always impossible