Created
March 13, 2021 14:11
-
-
Save vncsna/4c90d0ef04422e7db097e2e67fa100bb to your computer and use it in GitHub Desktop.
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
# Distancia Euclidiana | |
for i in range(1, 5): | |
dist = norm((x[0, :] - x[i, :]).A) | |
print(f"Distância(Consulta, Documento {i}) = {dist:.2f}") | |
# Função Auxiliar | |
def cosine_similarity(x, y): | |
x = x.A.ravel() | |
y = y.A.ravel() | |
return np.dot(x, y) / (norm(x) * norm(y)) | |
# Similaridade de Cossenos | |
for i in range(1, 5): | |
sim = cosine_similarity(x[0, :], x[i, :]) | |
print(f"Similaridade(Consulta, Documento {i}) = {sim:.2f}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment