我再次检查了self.xTrainTest和self.yTrainTest,它们都是密集的numpy数组,具有相同的行数。
如果将require_dense更改为[False,False],则模型将返回另一个错误,指出形状self.xTrainTest和self.yTrainTest [317,1]之间不匹配。似乎只有self.yTrainTest的一行传递到了模型中。
print (type(self.xTrainTest),type(self.yTrainTest))
print (self.xTrainTest.shape,self.yTrainTest.shape)
parameters = {'classifier': [SVC(probability=True)],
'classifier__kernel': ['linear', 'poly', 'rbf'],
'classifier__C': [0.1,1,10],
'classifier__gamma': ['auto'],
'classifier__degree': [1, 5,10,20]}
Random0 = RandomizedSearchCV(BinaryRelevance(require_dense=[False, True]), parameters, scoring='roc_auc', cv=5)
Random0.fit(self.xTrainTest,self.yTrainTest)
<class 'numpy.ndarray'> <class 'numpy.ndarray'>
(397, 74706), (397, 9)
raise TypeError('A sparse matrix was passed, but dense '
TypeError: A sparse matrix was passed, but dense data is required. Use X.toarray() to convert to a dense numpy array.