the loading of the dataset is just basic pythonso let us jump ahead to the learning we have sparse matrixwhere there are entries from to whenever we have rating (most of the entries are zero to denote that this user has not rated these moviesthis timeas regression methodfor varietywe are going to be using the lassocv classfrom sklearn linear_model import lassocv reg lassocv(fit_intercept=truealphas= , , , ]by passing the constructor an explicit set of alphaswe can constrain the values that the inner cross-validation will use you may note that the values are multiples of twostarting with / up to we will now write function which learns model for the user iisolate this user reviews[iwe are only interested in the movies that the user ratedso we must build up the index of those there are few numpy tricks in hereu toarray(to convert from sparse matrix to regular array thenwe ravel(that array to convert from row array (that isa two-dimensional array with first dimension of to simple onedimensional array we compare it with zero and ask where this comparison is true the resultpsis an array of indicesthose indices correspond to movies that the user has ratedu array(ravel(psnp where( build an array with indices [ nexcept us np delete(np arange(reviews shape[ ])ix reviews[us][:,pst finallywe select only the movies that the user has ratedy [pscross-validation is set up as before because we have many userswe are going to only use four folds (more would take long time and we have enough training data with just percent of the data)err kf kfold(len( )n_folds= for train,test in kfnow we perform per-movie normalization this is explained below xc, movie_norm( [train]