16

When I import the function check_array from module sklearn.utils.validation, it got an Import Error (ImportError: cannot import name check_array). The tab completion got check_arrays, but I'm wondering there only exists a function called check_array in validation.py ( source code on Github). Besides, the spectral clustering algorithm implemented in scikit-learn/sklearn/cluster/spectral.py also used from ..utils.validation import check_array, not check_arrays. I'm quite confused about this, and my scikit-learn version is '0.15.0b1'. Hope somebody gives me a clue.

sample code
import numpy as np
from sklearn.utils.validation import check_array
def my_fit_affinity(X, affinity_type, n_neighbors, **kernel_params):
    """ Create an affinity matrix for X using the selected affinity type
    """    
    X = check_array(X, accept_sparse = ['csr', 'csc', 'coo']) 
    ....
    return affinity_matrix_
Community
  • 1
  • 1
LittleLittleQ
  • 440
  • 3
  • 7
  • 21

3 Answers3

14

If you use jupyter notebook, try restarting your kernel.

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
Dean Wang
  • 244
  • 3
  • 11
2

To those searching, as @eickenberg mentioned in the comments, this was something that was changed between versions. Using the latest version of scikit-learn resolved the issue.

taleinat
  • 8,441
  • 1
  • 30
  • 44
1

Hit kernel > restart and run all

  • Restarting the kernel was already mentioned in [this earlier answer](https://stackoverflow.com/a/59553425/2745495). – Gino Mempin Dec 08 '21 at 03:53