留下一个不明确的元素

时间:2018-06-14 12:48:00

标签: python python-3.x

我是python的新手,我使用的是python 3.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()

我该如何解决?感谢

stackoverflow中有另一个主题https://stackoverflow.com/questions/10062954/valueerror-the-truth-value-of-an-array-with-more-than-one-element-is-ambiguous 我读过,逻辑操作数导致了这个错误。我的问题是如何在这种情况下使用LeaveOneOut交叉验证

0 个答案:

没有答案