问题描述
我正在尝试执行以下代码进行KFold交叉验证:
def evaluate_model(X,Y):
results = list()
n_inputs,n_outputs = X.shape[1],Y.shape[1]
# define evaluation procedure
cv = RepeatedKFold(n_splits=10,n_repeats=3,random_state=1)
# enumerate folds
for train_ix,test_ix in cv.split(X):
# prepare data
X_train,X_test = X.iloc[list(train_ix)],X.iloc[list(test_ix)]
y_train,y_test = Y.iloc[list(train_ix)],Y.iloc[list(test_ix)]
# define model
model = get_model(n_inputs,n_outputs)
# fit model
model.fit(X_train,y_train,verbose=0,epochs=100)
# make a prediction on the test set
yhat = model.predict(X_test)
# round probabilities to class labels
yhat = yhat.round()
# calculate accuracy
acc = accuracy_score(y_test,yhat)
# store result
print('>%.3f' % acc)
results.append(acc)
return results
results = evaluate_model(X,Y)
y_type,y_true,y_pred = _check_targets(y_true,y_pred)
File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\classification.py",line 99,in _check_targets
y_true = csr_matrix(y_true)
File "C:\Users\XYZ\AppData\Roaming\Python\python37\site-packages\scipy\sparse\compressed.py",line 88,in __init__
self._set_self(self.__class__(coo_matrix(arg1,dtype=dtype)))
File "C:\Users\XYZ\AppData\Roaming\Python\python37\site-packages\scipy\sparse\compressed.py",dtype=dtype)))
File "C:\Users\XYZ\AppData\Roaming\Python\python37\site-packages\scipy\sparse\coo.py",line 191,in __init__
self.row,self.col = M.nonzero()
File "C:\Users\XYZ\AppData\Roaming\Python\python37\site-packages\scipy\sparse\base.py",line 287,in __bool__
raise ValueError("The truth value of an array with more than one "
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all().
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)