当前位置: 首页>>代码示例>>Python>>正文


Python NearestNeighbors.kneighborgs方法代码示例

本文整理汇总了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
开发者ID:spalaciob,项目名称:py-dbclasd,代码行数:21,代码来源:dbclasd.py


注:本文中的sklearn.neighbors.NearestNeighbors.kneighborgs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。