def nn_movie(ureviews, reviews, uid, mid, k=1):
 X = ureviews
 y = ureviews[mid].copy()
 y -= y.mean()
 y /= (y.std() + 1e-05)
 corrs = np.dot(X, y)
 likes = corrs.argsort()
 likes = likes[::(-1)]
 c = 0
 pred = 3.0
 for ell in likes:
  if (ell == mid):
   continue
  if (reviews[(uid, ell)] > 0):
   pred = reviews[(uid, ell)]
   if (c == k):
    return pred
   c += 1
 return pred

def nn_movie ( ureviews , reviews , uid , mid , k = 1 ) : X = ureviews y = ureviews [ mid ] . copy ( ) y -= y . mean ( ) y /= ( y . std ( ) + 1e-05 ) corrs = np . dot ( X , y ) likes = corrs . argsort ( ) likes = likes [ : : ( - 1 ) ] c = 0 pred = 3.0 for ell in likes : if ( ell == mid ) : continue if ( reviews [ ( uid , ell ) ] > 0 ) : pred = reviews [ ( uid , ell ) ] if ( c == k ) : return pred c += 1 return pred
movie neighbor based classifier parameters ureviews : ndarray reviews : ndarray uid : int index of user mid : int index of movie k : int index of neighbor to return returns pred : float .