简体   繁体   中英

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_

如果您使用 jupyter notebook,请尝试重新启动内核。

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.

点击内核>重新启动并运行所有

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM