本文整理汇总了Python中sklearn.neighbors.NearestNeighbors.kneighborgs方法的典型用法代码示例。如果您正苦于以下问题:Python NearestNeighbors.kneighborgs方法的具体用法?Python NearestNeighbors.kneighborgs怎么用?Python NearestNeighbors.kneighborgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.neighbors.NearestNeighbors
的用法示例。
在下文中一共展示了NearestNeighbors.kneighborgs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: retrieve_neighborhood_simple
# 需要导入模块: from sklearn.neighbors import NearestNeighbors [as 别名]
# 或者: from sklearn.neighbors.NearestNeighbors import kneighborgs [as 别名]
def retrieve_neighborhood_simple(allpts, cluster_idxs, nnfinder, pt_idx=None):
"""
DEPRECATED
Retrieve candidates to expand a given cluster. The radius is set to the largest 1-NN distance within all cluster
points. This method omits the lower bound check and follows directly the definition for the radius.
:param allpts: NxM 2d-array with N points of M dimensions. These are all points in the dataset.
:param cluster_idxs: the indices whthin allpts of the (partial) cluster to be evaluated/expanded.
:param nnfinder: instance of scipy's NearestNeighbor fit with all points in the dataset.
:param pt_idx: index within allpts of the reference point to be checked for neighboring candidates to expand
the cluster. If None, the first index of cluster_idxs is going to be used instead.
:return: list of point indices that are within a radius r from the query point, including the query point.
"""
cluster = allpts[cluster_idxs]
two_nnfinder = NearestNeighbors(2, algorithm='ball_tree', p=2).fit(cluster)
r = two_nnfinder.kneighborgs(cluster)[0][:, 1].max() # Max NN distance of pts
if pt_idx is None:
pt_idx = cluster_idxs[0]
query_nn_dists, query_nn_idxs = nnfinder.kneighbors([allpts[pt_idx]])
return query_nn_idxs[query_nn_dists <= r] # Discard the input point itself