

def cosineDistance(x, y):
    ' This function computes the cosine distance between feature vectors \n         x and y. This distance is frequently used for text classification. \n        It varies between 0 and 1. The distance is 0 if x==y. \n    '
    denom = math.sqrt((sum((x ** 2)) * sum((y ** 2))))
    dist = (1.0 - (np.dot(x, y.conj().transpose()) / denom))
    return round(dist, 6)

dataset/ETHPy150Open bt3gl/Advanced-Machine-Learning/k-NN/calculate_cosine_distance.py cosineDistance/original