fuzzyclust.graph.neighbors_graph#
- fuzzyclust.graph.neighbors_graph(X, n_neighbors=10, radius=None)[source]#
Symmetric \(k\)-nearest-neighbor (or \(\varepsilon\)-radius) graph with Euclidean weights.
Two samples are linked when either one is among the \(k\) nearest neighbors of the other (\(k\)-Isomap) or when they are closer than
radius(\(\varepsilon\)-Isomap). A sample is never its own neighbor; coincident samples are linked by an edge of lengthEPSso that a zero weight never means “no edge”.- Parameters:
- Xarray_like
ofshape(n_samples,n_features) - n_neighbors
intorNone, default=10 Number of neighbors \(k\). Ignored when
radiusis given.- radius
floatorNone, default=None Connect all pairs closer than
radius.
- Xarray_like
- Returns:
- G
scipy.sparse.csr_matrixofshape(n_samples,n_samples) Symmetric adjacency with the Euclidean distances as weights (a structurally missing entry means “no edge”).
- G
Examples
>>> import numpy as np >>> from fuzzyclust.graph import neighbors_graph >>> X = np.c_[np.arange(5.0), np.zeros(5)] >>> G = neighbors_graph(X, n_neighbors=1) >>> G.nnz, float(G.max()) (8, 1.0)