now we can use this in several ways simple one is to select the nearest neighbors of each user these are the users that most resemble it we will use the measured correlation discussed earlierdef estimate(userrest)''estimate movie ratings for 'userbased on the 'restof the universe ''binary version of user ratings bu user binary version of rest ratings br rest ws all_correlations(bu,brselect highest values selected ws argsort()[- :estimate based on the meanestimates rest[selectedmean( we need to correct estimates based on the fact that some movies have more ratings than othersestimates / +br[selectedmean( )when compared to the estimate obtained over all the users in the datasetthis reduces the rmse by percent as usualwhen we look only at those users that have more predictionswe do betterthere is percent error reduction if the user is in the top half of the rating activity looking at the movie neighbors in the previous sectionwe looked at the users that were most similar we can also look at which movies are most similar we will now build recommendations based on nearest neighbor rule for movieswhen predicting the rating of movie for user uthe system will predict that will rate with the same points it gave to the movie most similar to thereforewe proceed with two stepsfirstwe compute similarity matrix ( matrix that tells us which movies are most similar)secondwe compute an estimate for each (user-moviepair we use the numpy zeros and ones functions to allocate arrays (initialized to zeros and ones respectively)movie_likeness np zeros((nmovies,nmovies)allms np ones(nmoviesboolcs np zeros(nmovies