Skip to content

Instantly share code, notes, and snippets.

@Wann-Jiun
Last active November 20, 2017 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wann-Jiun/b8a9ae273557b8b0a6434704e3b9223e to your computer and use it in GitHub Desktop.
Save Wann-Jiun/b8a9ae273557b8b0a6434704e3b9223e to your computer and use it in GitHub Desktop.
from sklearn.metrics import mean_squared_error
prediction = similarity_user.dot(train_matrix) / np.array([np.abs(similarity_user).sum(axis=1)]).T
prediction = prediction[test_matrix.nonzero()].flatten()
test_vector = test_matrix[test_matrix.nonzero()].flatten()
mse = mean_squared_error(prediction, test_vector)
print 'MSE = ' + str(mse)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment