Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precomputed_knn error #1012

Open
blabarthe1 opened this issue May 24, 2023 · 2 comments
Open

precomputed_knn error #1012

blabarthe1 opened this issue May 24, 2023 · 2 comments

Comments

@blabarthe1
Copy link

api documentation here https://umap-learn.readthedocs.io/en/latest/api.html tells :

" If you wish to use k-nearest neighbors data calculated by another package then provide a tuple of the form (knn_indices, knn_dists). The contents of the tuple should be two numpy arrays of shape (N, n_neighbors) where N is the number of items in the input data. The first array should be the integer indices of the nearest neighbors, and the second array should be the corresponding distances. The nearest neighbor of each item should be itself, e.g. the nearest neighbor of item 0 should be 0, the nearest neighbor of item 1 is 1 and so on. Please note that you will not be able to transform new data in this case. "

If you provide such an input to umap api it raises this error during fit :

File /opt/conda/lib/python3.10/site-packages/umap/umap_.py:2288, in UMAP.fit(self, X, y)
2286 self.knn_indices = self.precomputed_knn[0]
2287 self.knn_dists = self.precomputed_knn[1]
-> 2288 self.knn_search_index = self.precomputed_knn[2]
2290 self._validate_parameters()
2292 if self.verbose:

IndexError: tuple index out of range

if this input is provided (knn_indices, knn_dists,None) it raises :

File /opt/conda/lib/python3.10/site-packages/umap/umap_.py:2290, in UMAP.fit(self, X, y)
2287 self.knn_dists = self.precomputed_knn[1]
2288 self.knn_search_index = self.precomputed_knn[2]
-> 2290 self._validate_parameters()
2292 if self.verbose:
2293 print(str(self))

File /opt/conda/lib/python3.10/site-packages/umap/umap_.py:1930, in UMAP._validate_parameters(self)
1925 raise ValueError(
1926 "precomputed_knn[0] and precomputed_knn[1]"
1927 " must be numpy arrays of the same size."
1928 )
1929 if not isinstance(self.knn_search_index, NNDescent):
-> 1930 raise ValueError(
1931 "precomputed_knn[2] (knn_search_index)"
1932 " must be an NNDescent object."
1933 )
1934 if self.knn_dists.shape[1] < self.n_neighbors:
1935 warn(
1936 "precomputed_knn has a lower number of neighbors than "
1937 "n_neighbors parameter. precomputed_knn will be ignored"
1938 " and the k-nn will be computed normally."
1939 )

ValueError: precomputed_knn[2] (knn_search_index) must be an NNDescent object.

Is the documentation right ? Can we really provide precomputed_knn from other packages ?

@jlmelville
Copy link
Collaborator

This feature is available, but only if installing directly from this repo. Otherwise, it will become available when there is a new release of this package.

@blabarthe1
Copy link
Author

Thanks for youre quick answer !
I'll try it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants