ImportError: cannot import name check_array from sklearn.utils.validation

LittleLittleQ picture LittleLittleQ · Nov 27, 2014 · Viewed 10.3k times · Source

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_

Answer

Dean Wang picture Dean Wang · Jan 1, 2020

If you use jupyter notebook, try restarting your kernel.