0

This value errors is coming when I am simple comparing strings in a loop(No or,and etc) After splitting my dataset into training and testing I apply the following code on the training dataset:

normal1,dos1=[],[]
for a in range(0,24517):
    if y1_train=="normal.":
        normal1.append(X1_train)
    elif y1_train=="smurf.":
        dos1.append(X1_train)

NOTE: This error was not coming when I was using the full dataset. Hence splitting code for reference:

X1=data[:,:41]
y1=data[:,41]
y1 = y1.reshape(-1, 1)
y1=y1.ravel()
seed=7
X1_train, X1_test, y1_train, y1_test = train_test_split(X1, y1,test_size = 0.2, random_state=seed)*
  • `y1_train` is an array. The comparison `y1_train=="normal."` does not make sense, hence the ambiguity error. – ayhan May 19 '18 at 13:09
  • Would doing y1_train[a] be conceptually correct then? Comparing element of array to a string that is? – Radhika Nagpal May 19 '18 at 14:40
  • Yes. I assume you would need to change `normal1.append(X1_train)` as well. Also take a look at [boolean indexing](https://docs.scipy.org/doc/numpy-1.13.0/user/basics.indexing.html#boolean-or-mask-index-arrays) which is probably more suitable for the task you are trying to do. – ayhan May 19 '18 at 14:57

0 Answers0