博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
机器学习中的常用距离
阅读量:7224 次
发布时间:2019-06-29

本文共 1851 字,大约阅读时间需要 6 分钟。

If x1,x2Rn, then:

闵可夫斯基距离 Minkowski Distance

d12=k=1n(x1kx2k)pp,p>0

欧氏距离 Enclidean Distance

L2 norm

d12=k=1n(x1kx2k)2 or d12=(x1x2)T(x1x2)

标准化欧式距离/加权欧式距离 Weighted Euclidean Distance

d12=k=1n(x1kx2kSk)2
where
Sk is the standard deviation.
from numpy import *vectormat=mat([[1,2,3],[4,5,6]])v12=vectormat[0]-vectormat[1]varmat=std(vectormat.T, axis=0)normmat=(vectormat-mean(vectormat))/varmat.Tnormv12=normmat[0]-normmat[1]print(sqrt(normv12*normv12.T))

曼哈顿距离 Manhattan Distance

L1 norm

d12=k=1n|x1kx2k|

切比雪夫距离 Chebyshev Distance

L norm

d12=maxi(|x1ix2i|)
from numpy import *vector1=mat([1,2,3])vector2=mat([4,5,7])print(abs(vector1-vector2).max())

夹角余弦 Cosine

cosθ=nk=1x1kx2knk=1x21knk=1x22k

汉明距离 Hamming Distance

In information theory, the Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. In other words, it measures the minimum number of substitutions required to change one string into the other. (referred from Wikipedia)

from numpy import *matV=mat([[1,1,0,1,0,1,0,0,1],[0,1,1,0,0,0,1,1,1]])smstr=nonzero(matV [0]-matV[1])print(shape(smstr[0])[0])

杰卡德相似系数 Jaccard Similarity Coefficient

Given two sets, A and B, the Jaccard similarity coefficient is defined as

J(A,B)=|AB||AB|

杰卡德距离 Jaccard Distance

Jδ(A,B)=1J(A,B)=|AB||AB||AB|
from numpy import *import scipy.spatial.distance as distmatV=mat([[1,1,0,1,0,1,0,0,1],[0,1,1,0,0,0,1,1,1]])print(dist.pdist(matV,'jaccard'))

马氏距离 Mahalanobis Distance

Given m sample vectors X1,,Xm whose mean value is μ and covariance matrix is S, then the Mahalanobis distance of sample vector X and μ is defined as

D(X)=(Xμ)TS1(Xμ)
that of sample vector
Xi and
Xj is
D(X)=(XiXj)TS1(XiXj)

转载地址:http://bdufm.baihongyu.com/

你可能感兴趣的文章
使用parted解决大于2T的磁盘分区
查看>>
oschina
查看>>
Octave 入门
查看>>
深度学习入门:10门免费线上课程推荐
查看>>
JavaScript 如何正确处理 Unicode 编码问题!
查看>>
iOS帅气加载动画、通知视图、红包助手、引导页、导航栏、朋友圈、小游戏等效果源码...
查看>>
微服务核心架构梳理
查看>>
浅谈JavaScript的面向对象和它的封装、继承、多态
查看>>
laravel with 查询列表限制条数
查看>>
Python爬虫--- 1.3 BS4库的解析器
查看>>
CentOS从零开始部署Nodejs项目
查看>>
React组件设计模式(一)
查看>>
express.js的介绍及使用
查看>>
闭包--闭包之tab栏切换(四)
查看>>
Elasticsearch 参考指南(升级前重新索引)
查看>>
Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比...
查看>>
浅析微信支付:申请退款、退款回调接口、查询退款
查看>>
基于axios的vue插件,让http请求更简单
查看>>
问:在指定的JSON数据中(最外层是数组)根据指定条件拿到匹配到的结果
查看>>
Kibana配置logstash,报表一体化
查看>>