Last active
December 1, 2016 08:32
-
-
Save otknoy/1927a29f642593861afc to your computer and use it in GitHub Desktop.
Python + scipy で cos 類似度の計算
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import numpy as np | |
import scipy.spatial.distance | |
if __name__ == '__main__': | |
x = np.array([1, 1, 1, 1, 1]) | |
y = np.array([1, 0, 1, 0, 1]) | |
z = np.array([0, 1, 0, 0, 0]) | |
print 1 - scipy.spatial.distance.cosine(x, y) | |
print 1 - scipy.spatial.distance.cosine(y, z) | |
print 1 - scipy.spatial.distance.cosine(z, x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
距離だから、1 から引いてやれば類似度として使える。