8.20.8. sklearn.neighbors.radius_neighbors_graph¶
- sklearn.neighbors.radius_neighbors_graph(X, radius, mode='connectivity')¶
Computes the (weighted) graph of Neighbors for points in X
Neighborhoods are restricted the points at a distance lower than radius.
Parameters : X : array-like or BallTree, shape = [n_samples, n_features]
Sample data, in the form of a numpy array or a precomputed BallTree.
radius : float
Radius of neighborhoods.
mode : {‘connectivity’, ‘distance’}, optional
Type of returned matrix: ‘connectivity’ will return the connectivity matrix with ones and zeros, in ‘distance’ the edges are Euclidean distance between points.
Returns : A : sparse matrix in CSR format, shape = [n_samples, n_samples]
A[i, j] is assigned the weight of edge that connects i to j.
See also
Examples
>>> X = [[0], [3], [1]] >>> from sklearn.neighbors import radius_neighbors_graph >>> A = radius_neighbors_graph(X, 1.5) >>> A.todense() matrix([[ 1., 0., 1.], [ 0., 1., 0.], [ 1., 0., 1.]])