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

馋奶兔 提交于 2019-12-10 12:42:37

问题


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_

回答1:


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.



来源:https://stackoverflow.com/questions/27173030/importerror-cannot-import-name-check-array-from-sklearn-utils-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!