Skip to content

Calling NearestNeighbors.{kneighbors,radius_neighbors}_graph without first fitting should raise NotFittedError #12276

@jnothman

Description

@jnothman

Description

Running prediction methods without running fit should raise NotFittedError. This is not the case for some non-standard methods.

check_is_fitted should be applied for this purpose.

Steps/Code to Reproduce

from sklearn.neighbors import NearestNeighbors
NearestNeighbors().kneighbors_graph([[1]])

or

from sklearn.neighbors import NearestNeighbors
NearestNeighbors().radius_neighbors_graph([[1]])

Expected Results

NotFittedError raised

Actual Results

AttributeError raised

Versions

System
------
    python: 3.5.2 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:52:12)  [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)]
executable: /Users/joel/anaconda3/envs/scipy3k/bin/python
   machine: Darwin-17.7.0-x86_64-i386-64bit

BLAS
----
  lib_dirs: /Users/joel/anaconda3/envs/scipy3k/lib
    macros: SCIPY_MKL_H=None, HAVE_CBLAS=None
cblas_libs: mkl_rt, pthread

Python deps
-----------
setuptools: 37.0.0
     scipy: 1.0.0
       pip: 18.0
     numpy: 1.14.1
   sklearn: 0.21.dev0
    pandas: 0.23.4
    Cython: 0.28.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions