def nmae(data, predictions, clusters, value_range=20.0): error = 0 num_ratings = 0 for user in range(data.shape[0]): cluster = clusters[users] # cluster that user belongs to prediction = predictions[cluster] # predicted ratings actual = data[user, :] # actual ratings abs_diff = np.abs(prediction - actual) # absouloute difference total = np.nansum(abs_diff) # total of all errors error += total num_ratings += np.count_nonzero(~np.is_nan(actual)) # number of ratings print error return error/(value_range * num_ratings)
def nmae(data, predictions, clusters, value_range=20.0): error = 0 num_ratings = 0 for user in range(data.shape[0]): cluster = clusters[users] # cluster that user belongs to prediction = predictions[cluster] # predicted ratings actual = data[user, :] # actual ratings abs_diff = np.abs(prediction - actual) # absouloute difference total = np.nansum(abs_diff) # total of all errors error += total num_ratings += np.count_nonzero( ~np.is_nan(actual)) # number of ratings print error return error / (value_range * num_ratings)
def target(X, target): mat = 2 * (X - target) X[np.is_nan(X)] = 0 return X, np.nansum((X - target) ** 2), 'Target rotation'