the linearregression class implements ols regression as followslr linearregression(fit_intercept=truewe set the fit_intercept parameter to true in order to add bias term this is exactly what we had done beforebut in more convenient interfacelr fit( ,yp map(lr predictxlearning and prediction are performed for classification as followse - total_error np sum( *esum of squares rmse_train np sqrt(total_error/len( )print('rmse on training{}format(rmse_train)we have used different procedure to compute the root mean square error on the training data of coursethe result is the same as we had before (it is always good to have these sanity checks to make sure we are doing things correctlynowwe will use the kfold class to build -fold cross-validation loop and test the generalization ability of linear regressionfrom sklearn cross_validation import kfold kf kfold(len( )n_folds= err for train,test in kflr fit( [train], [train] map(lr predictx[test] - [testerr +np sum( *ermse_ cv np sqrt(err/len( )print('rmse on -fold cv{}format(rmse_ cv)with cross-validationwe obtain more conservative estimate (that isthe error is greater) as in the case of classificationthis is better estimate of how well we could generalize to predict prices ordinary least squares is fast at learning time and returns simple modelwhich is fast at prediction time for these reasonsit should often be the first model that you use in regression problem howeverwe are now going to see more advanced methods