def estimate_user(user, rest): bu = user > 0 br = rest > 0 ws = all_correlations(bu,br) selected = ws.argsort()[-100:] estimates = rest[selected].mean(0) estimates /= (.1+br[selected].mean(0)) return estimates
def estimate_user(user, rest, num_neighbors=100): '''Estimate ratings for user based on the binary rating matrix Returns ------- estimates: ndarray Returns a rating estimate for each movie ''' # Compute binary matrix correlations: bu = user > 0 br = rest > 0 ws = all_correlations(bu, br) # Select top `num_neighbors`: selected = ws.argsort()[-num_neighbors:] # Use these to compute estimates: estimates = rest[selected].mean(0) estimates /= (.1 + br[selected].mean(0)) return estimates