我是python新手,正在使用python3.6。我需要在我的项目中使用Leave-One-Out交叉验证。我有一个数据集,它有一列'pos'或'neg'值,我想在交叉验证函数中拆分它们,我编写了以下代码:
negclass = []
posclass = []
loo = LeaveOneOut()
loo.get_n_splits(x)
for train_index, test_index in loo.split(x):
x_train, x_test = x[train_index], x[test_index]
y_train, y_test = y[train_index], y[test_index]
for i in range(len(train_index)):
if(y_train == 'NEG'):
negclass.append(x_train)
elif(y_train == 'POS'):
posclass.append(x_train)
但这给了我一个错误
ValueError Traceback (most recent call last)
<ipython-input-21-b93d17acc034> in <module>()
7 y_train, y_test = y[train_index], y[test_index]
8 for i in range(len(train_index)):
----> 9 if(y_train == 'NEG'):
10 negclass.append(x_train)
11 elif(y_train == 'POS'):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我该怎么修?谢谢
stackoverflowhttps://stackoverflow.com/questions/10062954/valueerror-the-truth-value-of-an-array-with-more-than-one-element-is-ambiguous中还有一个主题 我读过,逻辑操作数导致了这个错误。我的问题是如何在这种情况下使用LeaveOneOut交叉验证
目前没有回答
相关问题 更多 >
编程相关推荐