简体   繁体   English

如何计算R中两个向量之间不同的众所周知的相似性或距离度量?

[英]How to calculate different well-known similarity or distance measures between two vectors in R?

I want to compute the similarity (distance) between two vectors: 我想计算两个向量之间的相似性(距离):

v1 <- c(1, 0.5, 0, 0.1)
v2 <- c(0.7, 1, 0.2, 0.1)

I just want to know if a package is available for calculating different well-known similarity (distance) measures in R? 我只是想知道一个包是否可用于计算R中不同的众所周知的相似性(距离)度量? For example, "Resnik", "Lin", "Rel", "Jiang",... 例如,“Resnik”,“Lin”,“Rel”,“Jiang”,......

The implementation of these method is not hard, but I really think it must be defined in some packages in R. 这些方法的实现并不难,但我认为它必须在R中的一些包中定义。

After some googling I found a package "GOSemSim" , which contains most measures, but it's specific to the biomedical application and I can't use them for computing the similarity between two vectors. 经过一些谷歌搜索后,我发现了一个包含“GOSemSim”的软件包,其中包含大多数测量,但它特定于生物医学应用程序,我不能用它们来计算两个向量之间的相似性。

" proxy " is a general library for distance and similarity measures. 代理 ”是用于距离和相似性度量的通用库。 The following methods are supported: 支持以下方法:

"Jaccard" "Kulczynski1" "Kulczynski2" "Mountford" "Fager" "Russel" "simple matching" "Hamman" "Faith" “Jaccard”“Kulczynski1”“Kulczynski2”“Mountford”“Fager”“Russel”“简单匹配”“Hamman”“Faith”
"Tanimoto" "Dice" "Phi" "Stiles" "Michael" "Mozley" "Yule" "Yule2" "Ochiai" “Tanimoto”“Dice”“Phi”“Stiles”“Michael”“Mozley”“Yule”“Yule2”“Ochiai”
"Simpson" "Braun-Blanquet" "cosine" "eJaccard" "fJaccard" "correlation" "Chi-squared" "Phi-squared" "Tschuprow" “Simpson”“Braun-Blanquet”“余弦”“eJaccard”“fJaccard”“相关”“卡方”“Phi-squared”“Tschuprow”
"Cramer" "Pearson" "Gower" "Euclidean" "Mahalanobis" "Bhjattacharyya" "Manhattan" "supremum" "Minkowski" “Cramer”“Pearson”“Gower”“Euclidean”“Mahalanobis”“Bhjattacharyya”“Manhattan”“supremum”“Minkowski”
"Canberra" "Wave" "divergence" "Kullback" "Bray" "Soergel" "Levenshtein" "Podani" "Chord" “Canberra”“Wave”“divergence”“Kullback”“Bray”“Soergel”“Levenshtein”“Podani”“Chord”
"Geodesic" "Whittaker" "Hellinger" “Geodesic”“Whittaker”“Hellinger”

Check the following example: 请检查以下示例:

x <- c(1,2,3,4,5)
y <- c(4,5,6,7,8)
l <- list(x, y)
simil(l, method="cosine")

The output is a similarity matrix between the elements of "l": 输出是“l”元素之间的相似性矩阵:

      1
2     0.978232

The only problem I have is that for some methods (such as: "Jaccard"), the following error is occurred: 我遇到的唯一问题是对于某些方法(例如:“Jaccard”),发生以下错误:

simil(l, method="Jaccard")
Error in n - d : 'n' is missing

The dist function supports via its method argument: "euclidean", "maximum", "manhattan", "canberra", "binary" or "minkowski". dist函数通过其method参数支持:“euclidean”,“maximum”,“manhattan”,“canberra”,“binary”或“minkowski”。 See ?dist ?dist

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM