机器学习中的常用距离

简介: If x1,x2∈Rnx_{1}, x_{2}\in\mathbb{R}^{n}, then: 闵可夫斯基距离 Minkowski Distance d12=∑k=1n(x1k−x2k)p−−−−−−−−−−−−√p,p>0d_{12}=\sqrt[\uproot{16}p]{\sum_{k=1}^{n}(x_{1k}-x_{2k})^{p}},\quad p>0欧

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.T
normv12=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 dist
matV=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)
相关文章
|
4月前
|
机器学习/深度学习
【机器学习】误差分析
【1月更文挑战第23天】【机器学习】误差分析
|
3月前
|
机器学习/深度学习 人工智能 物联网
深度学习在时间序列预测的总结和未来方向分析
2023年是大语言模型和稳定扩散的一年,时间序列领域虽然没有那么大的成就,但是却有缓慢而稳定的进展。Neurips、ICML和AAAI等会议都有transformer 结构(BasisFormer、Crossformer、Inverted transformer和Patch transformer)的改进,还出现了将数值时间序列数据与文本和图像合成的新体系结构(CrossVIVIT), 也出现了直接应用于时间序列的可能性的LLM,以及新形式的时间序列正则化/规范化技术(san)。
82 1
|
14天前
|
机器学习/深度学习 自然语言处理 算法
机器学习--K-近邻算法常见的几种距离算法详解
机器学习--K-近邻算法常见的几种距离算法详解
|
2月前
|
机器学习/深度学习 算法
机器学习的魔法(二)超越预测的界限-揭秘机器学习的黑科技-探索监督学习中的回归和分类问题
机器学习的魔法(二)超越预测的界限-揭秘机器学习的黑科技-探索监督学习中的回归和分类问题
138 0
|
3月前
|
机器学习/深度学习 搜索推荐 数据可视化
机器学习中7种常用的线性降维技术总结
上篇文章中我们主要总结了非线性的降维技术,本文我们来总结一下常见的线性降维技术。
88 6
|
8月前
|
机器学习/深度学习 数据采集 算法
【机器学习7】特征缩放
【机器学习7】特征缩放
74 0
|
4月前
|
机器学习/深度学习 人工智能 算法
【人工智能】<吴恩达-机器学习>批量梯度下降&矩阵和向量运算概述
【1月更文挑战第26天】【人工智能】<吴恩达-机器学习>批量梯度下降&矩阵和向量运算概述
|
机器学习/深度学习 分布式计算 并行计算
推荐一些机器学习系统MLSys中的值得研究的方向
MLsys不能算是一种方向,而是一种思路。比如对于system研究者来说,可以把ML作为我们开发的系统要适配的一种benchmark,就像transaction对于数据库、某种文件场景对于File System的意义一样。这样一想可做的空间就宽广多了
467 0
|
11月前
|
机器学习/深度学习 算法
学习笔记: 机器学习经典算法-空间内一点到超平面的距离推广公式
机器学习经典算法-个人笔记和学习心得分享
94 0
|
机器学习/深度学习 数据采集 Dart
使用阿里云机器学习PAI做回归预测
XGBoost是一种集成机器学习算法,能够处理分类和回归问题。它具有高准确性、鲁棒性、可解释性和可扩展性等优点。XGBoost的算法原理是集成多个决策树模型,每个模型都是在前一个模型的残差上进行训练。在训练过程中,XGBoost使用了一些技术来避免过拟合,例如正则化、剪枝和子采样。如果想要处理分类和回归问题,XGBoost是一个值得尝试的机器学习算法。
359 0
使用阿里云机器学习PAI做回归预测