I am new in python and I'm using python 3.6. I need to use Leave One Out cross validation in my project . I have a data set that has a column 'pos' or 'neg' value, I want to split them in my cross validation function, I wrote this code:
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)
but it gives me that error
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()
How can I fix it? Thanks
There is another topic in stackoverflow https://stackoverflow.com/questions/10062954/valueerror-the-truth-value-of-an-array-with-more-than-one-element-is-ambiguous I've read that, logical operands caused this error there. my problem is about how to use LeaveOneOut cross validation in this case