'convert cosine similarity distance to confidence percent
I am working to features of images based on deep learning techniques, and for labeling images, I specify the desired label with a threshold using cosine distance. The algorithm is as follows:
import math
from itertools import izip
def dot_product(v1, v2):
return sum(map(lambda x: x[0] * x[1], izip(v1, v2)))
def cosine_measure(v1, v2):
prod = dot_product(v1, v2)
len1 = math.sqrt(dot_product(v1, v1))
len2 = math.sqrt(dot_product(v2, v2))
return prod / (len1 * len2)
Suppose I get the number 0.34. How do I convert this number to a percentage?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
