1

库和相应的文档如下——是的,我阅读了所有内容并能够在我自己的代码上“运行”。

http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.LSHForest.html

但结果对我来说真的没有意义,所以我浏览了这个例子(也包含在上一个网页中)

    >>> from sklearn.neighbors import LSHForest
    >>> X_train = [[5, 5, 2], [21, 5, 5], [1, 1, 1], [8, 9, 1], [6, 10, 2]]
    >>> X_test = [[9, 1, 6], [3, 1, 10], [7, 10, 3]]
    >>> lshf = LSHForest()
    >>> lshf.fit(X_train)  
    LSHForest(min_hash_match=4, n_candidates=50, n_estimators=10,
              n_neighbors=5, radius=1.0, radius_cutoff_ratio=0.9,
              random_state=None)
    >>> distances, indices = lshf.kneighbors(X_test, n_neighbors=2)
    >>> distances                                        
        array([[ 0.069...,  0.149...],
               [ 0.229...,  0.481...],
               [ 0.004...,  0.014...]])
    >>> indices
        array([[1, 2],
               [2, 0],
               [4, 0]])

所以我只是尝试通过找到三个测试集 [9, 1, 6], [3, 1, 10], [7, 10, 3] 的最近邻居来验证示例

假设搜索 [9,1,6] 的最近邻居(通过使用欧几里德距离),最近的训练点是 [5, 5, 2] 和 [6, 10, 2] (我认为索引将 [0.4]) ——这与结果显着不同 [1,2]

通过简单的数学计算,距离也完全脱离了主题,附上我的 excel 表

再次感谢您的时间和帮助

4

1 回答 1

1

没错,因为 LSHForest 实现了 ANN(近似近邻),也许这就是我们需要考虑的差异。ANN 结果不是最近邻,而是最近邻应该是的近似值。

例如,2 最近邻结果如下所示:

from sklearn.neighbors import NearestNeighbors

X_train = [[5, 5, 2], [21, 5, 5], [1, 1, 1], [8, 9, 1], [6, 10, 2]]
X_test = [[9, 1, 6], [3, 1, 10], [7, 10, 3]]

nbrs = NearestNeighbors(n_neighbors=2, algorithm='ball_tree').fit(X_train)
distances, indices = nbrs.kneighbors(X_test)

并返回

indices
Out[2]: 
array([[0, 2],
       [0, 2],
       [4, 3]], dtype=int64)

distances
Out[3]: 
array([[ 6.92820323,  9.43398113],
       [ 9.16515139,  9.21954446],
       [ 1.41421356,  2.44948974]])

如果有帮助,请查看内容并注意其中提到:

给定一个查询点 q,如果在距 q 的距离 r 内存在一个点,则它报告距 q 的距离为 cr 的一个点。这里c是算法的近似因子。

距离 'r' 的点和返回的点不必相同。

希望这可以帮助。

于 2015-06-24T09:01:19.247 回答