fortunatelyscikit-learn makes it very easy to do the right thingit has classes named lassocvridgecvand elasticnetcvall of which encapsulate cross-validation check for the inner parameter the code is percent like the previous oneexcept that we do not need to specify any value for alpha from sklearn linear_model import elasticnetcv met elasticnetcv(fit_intercept=truekf kfold(len(target)n_folds= for train,test in kfmet fit(data[train],target[train] map(met predictdata[test] np array(pravel( -target[testerr +np dot( ,ermse_ cv np sqrt(err/len(target)this results in lot of computationso you may want to get some coffee while you are waiting (depending on how fast your computer israting prediction and recommendations if you have used any commercial online system in the last yearsyou have probably seen these recommendations some are like amazon' "costumers who bought also bought these will be dealt with in the next under the topic of basket analysis others are based on predicting the rating of productsuch as movie this last problem was made famous with the netflix challengea million-dollar machine learning public challenge by netflix netflix (well-known in the and but not available elsewhereis movie rental company traditionallyyou would receive dvds in the mailmore recentlythe business has focused on online streaming of videos from the startone of the distinguishing features of the service was that it gave every user the option of rating films they had seenusing these ratings to then recommend other films in this modeyou not only have the information about which films the user sawbut also their impression of them (including negative impressionsin netflix made available large number of customer ratings of films in its database and the goal was to improve on their in-house algorithm for ratings prediction whoever was able to beat it by percent or more would win million dollars in an international team named bellkor' pragmatic chaos was able to beat that mark and take the prize they did so just minutes before another teamthe ensemblepassed the percent mark as wellan exciting photo-finish for competition that lasted several years