## （原）欧氏距离与余弦距离

https://www.cnblogs.com/darkknightzh/p/12013741.html

$Euc\_dist={{\left\| \mathbf{A}-\mathbf{B} \right\|}_{2}}=\sqrt{\sum\limits_{i=1}^{n}{{{({{a}_{i}}-{{b}_{i}})}^{2}}}}=\sqrt{\sum\limits_{i=1}^{n}{(a_{i}^{2}-2\centerdot {{a}_{i}}\centerdot {{b}_{i}}+b_{i}^{2})}}=\sqrt{\sum\limits_{i=1}^{n}{a_{i}^{2}}+\sum\limits_{i=1}^{n}{b_{i}^{2}}-2\centerdot \sum\limits_{i=1}^{n}{{{a}_{i}}\centerdot {{b}_{i}}}}$

$Cos\_sim\text{=}\frac{\mathbf{A}\centerdot {{\mathbf{B}}^{T}}}{{{\left\| \mathbf{A} \right\|}_{2}}\centerdot {{\left\| \mathbf{B} \right\|}_{2}}}=\frac{\sum\limits_{i=1}^{n}{{{a}_{i}}\centerdot {{b}_{i}}}}{\sqrt{\sum\limits_{i=1}^{n}{a_{i}^{2}}}\centerdot \sqrt{\sum\limits_{i=1}^{n}{b_{i}^{2}}}}$

$Cos\_dis\text{=}1-Cos\_sim\text{=}1\text{-}\frac{\sum\limits_{i=1}^{n}{{{a}_{i}}\centerdot {{b}_{i}}}}{\sqrt{\sum\limits_{i=1}^{n}{a_{i}^{2}}}\centerdot \sqrt{\sum\limits_{i=1}^{n}{b_{i}^{2}}}}$

$Euc\_dist\text{=}\sqrt{1+1-2\centerdot \sum\limits_{i=1}^{n}{{{a}_{i}}\centerdot {{b}_{i}}}}\text{=}\sqrt{2\centerdot 1-\sum\limits_{i=1}^{n}{{{a}_{i}}\centerdot {{b}_{i}}}}$

$Cos\_dis\text{=}1\text{-}\sum\limits_{i=1}^{n}{{{a}_{i}}\centerdot {{b}_{i}}}$

$Euc\_dis{{t}^{2}}\text{=}2\centerdot Cos\_dis\text{=}2\centerdot (1-Cos\_sim)$

$Cos\_sim=1-\frac{1}{2}Euc\_dis{{t}^{2}}$

posted on 2019-12-09 22:05  darkknightzh  阅读(606)  评论(0编辑  收藏  举报