dislib.neighbors.NearestNeighbors¶
-
class
dislib.neighbors.base.
NearestNeighbors
(n_neighbors=5)[source]¶ Bases:
object
Unsupervised learner for implementing neighbor searches.
Parameters: n_neighbors (int, optional (default=5)) – Number of neighbors to use by default for kneighbors queries. Examples
>>> from dislib.neighbors import NearestNeighbors >>> from dislib.data import load_data >>> x = np.random.random((100, 5)) >>> data = load_data(x, subset_size=25) >>> knn = NearestNeighbors(n_neighbors=10) >>> knn.fit(data) >>> distances, indices = knn.kneighbors(data)
-
fit
(dataset)[source]¶ Fit the model using dataset as training data.
Parameters: dataset (Dataset) – Training data.
-
kneighbors
(dataset, n_neighbors=None, return_distance=True)[source]¶ Finds the K nearest neighbors of the samples in dataset. Returns indices and distances to the neighbors of each sample.
Parameters: - dataset (Dataset) – The query samples.
- n_neighbors (int, optional (default=None)) – Number of neighbors to get. If None, the value passed in the constructor is employed.
Returns: - dist (array) – Array representing the lengths to points, only present if return_distance=True.
- ind (array) – Indices of the nearest samples in the fitted data.
-