Skip to content

Isomap doesn't actually support NearestNeighbors as input to .fit #13596

@thatsmesasha

Description

@thatsmesasha

Description

Documentation for Isomap at https://scikit-learn.org/stable/modules/generated/sklearn.manifold.Isomap.html#sklearn.manifold.Isomap says I can provide NearestNeighbors object to .fit function. However it doesn't. It throws the error expecting 2D array.
Looking at the source code, I don't see any checks for the type of X data, just if it's a 2D array.
I'm using approach of NN + Isomap because NearestNeighbors supports callable metrics, unlike Isomap.

Expected Results

No error is thrown.

Actual Results

ValueError: Expected 2D array, got scalar array instead:
array=NearestNeighbors(algorithm='auto', leaf_size=30,
         metric=<function isomap_distance at 0x7fa0638c9488>,
         metric_params=None, n_jobs=None, n_neighbors=5, p=2, radius=1.0).
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

Versions

System:
python: 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0]
executable: /usr/bin/python3
machine: Linux-4.14.79+-x86_64-with-Ubuntu-18.04-bionic

BLAS:
macros: SCIPY_MKL_H=None, HAVE_CBLAS=None
lib_dirs: /usr/local/lib
cblas_libs: mkl_rt, pthread

Python deps:
pip: 19.0.3
setuptools: 40.9.0
sklearn: 0.20.3
numpy: 1.14.6
scipy: 1.1.0
Cython: 0.29.6
pandas: 0.22.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions