Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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_
like image 488
LittleLittleQ Avatar asked Nov 27 '14 14:11

LittleLittleQ


1 Answers

If you use jupyter notebook, try restarting your kernel.

like image 104
Dean Wang Avatar answered Sep 22 '22 06:09

Dean Wang