简体   繁体   English

在MATLAB中计算给定实例向量的KNN时,如何加权尺寸?

[英]How can I weight the dimensions as I am computing KNN of given instance vector in MATLAB?

Suppose I have a bunch of instances and I want to find the closest K instances to a particular instance. 假设我有一堆实例,并且我想找到最接近特定实例的K个实例。 Moreover, I have some weights showing the strengths of each dimension as we computing the distances. 此外,在计算距离时,我有一些权重显示每个维度的优势。 How can I incorporate these weights with the KNN finding process in MATLAB? 如何将这些权重与MATLAB中的KNN查找过程合并?

There are two methods that can allow you to do this. 有两种方法可以使您执行此操作。 Looking at the knnsearch documentation, you can either use the seuclidean flag where this performs the standardized Euclidean distance. 查看knnsearch文档,您可以在执行标准欧几里德距离的地方使用seuclidean标志。 Each co-ordinate difference between two points is scaled by dividing by a corresponding scale value in S . 通过除以S的相应比例值,可以缩放两个点之间的每个坐标差。 S by default is the standard deviation for each co-ordinate. 默认情况下, S是每个坐标的标准偏差。 You can manually specify each of these scales by specifying the Scale parameter, then specifying a vector where each component will scale each dimension for you instead of the standard deviation in each dimension. 您可以通过指定Scale参数,然后指定一个矢量,在其中每个组件将为您缩放每个尺寸而不是每个尺寸中的标准偏差,来手动指定每个Scale

As such, the more contribution a co-ordinate has, the larger the scale should be, as you want to aggregate co-ordinates and will allow distances that are larger to have a smaller Euclidean distance. 因此,坐标的贡献越大 ,比例就应该越大,这是因为您要汇总坐标,并将允许较大的距离具有较小的欧几里得距离。 This is essentially the same thing as weighting the strengths in each dimension. 这与加权每个维度的强度本质上是相同的。

Alternatively, you can provide your own function that computes the distance between two vectors. 另外,您可以提供自己的函数来计算两个向量之间的距离。 You can define what these weights are in your workspace before hand, then create an anonymous function wrapper that accesses these weights when computing whatever distance measure you want yourself. 您可以事先定义工作空间中这些权重的含义,然后创建一个匿名函数包装器,以便在计算所需的任何距离度量时访问这些权重。 The anonymous function can only take in two vectors, corresponding to two different co-ordinate vectors in KNN. 匿名函数只能接受两个向量,分别对应于KNN中的两个不同的坐标向量。 As such, use this anonymous function to access the weights that should be already defined in the workspace then go from there. 因此,使用此匿名函数访问应在工作空间中已经定义的权重,然后从那里去。

Check out: http://www.mathworks.com/help/stats/knnsearch.html 检出: http : //www.mathworks.com/help/stats/knnsearch.html

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

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