且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

sklearn 具有多个元素的数组的真值是不明确的.使用 a.any() 或 a.all() 错误

更新时间:2021-12-18 18:08:32

您使用的 check_cv 错误.根据文档:-

You are using check_cv wrong. According to the documentation:-

check_cv(cv=’warn’, y=None, classifier=False):

cv : int, 
     cross-validation generator or an iterable, optional

y : array-like, optional
    The target variable for supervised learning problems.

classifier : boolean, optional, default False
             Whether the task is a classification task, 
             in which case stratified KFold will be used

所以它需要 yestimator 输入.但是您提供的 Xy 是错误的.更改以下几行:

So it wants y and estimator in input. But you are providing X and y which is wrong. Change the below lines:

cv = check_cv(self.cv, X, y)
knn = KNeighborsClassifier(metric='precomputed', algorithm='brute')

到:

knn = KNeighborsClassifier(metric='precomputed', algorithm='brute')
cv = check_cv(self.cv, y, knn)

注意行的顺序.