knn ā kNN Graph Construction
kNN graph construction via PyNNDescent.
build_knn_graph(X, n_neighbors=15, metric='euclidean', random_state=None, perplexity=None)
Build sparse kNN graph from a point cloud.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Input data. |
required |
n_neighbors
|
int
|
Number of nearest neighbors (excluding self). |
15
|
metric
|
str
|
Distance metric for PyNNDescent. |
'euclidean'
|
random_state
|
int or None
|
Random seed for reproducibility. |
None
|
perplexity
|
float or None
|
If set, apply perplexity equalization (Gaussian kernel with
adaptive bandwidth) and return a column-stochastic probability
matrix. If |
None
|
Returns:
| Type | Description |
|---|---|
csc_matrix
|
Sparse (n_samples, n_samples) matrix. Column-stochastic probabilities if perplexity is set, raw squared distances otherwise. Self-loops removed. |