TypeError: only integer arrays with one element can be converted to an index
I finally got to solve the problem. Two things had to be done:
- train_argcands_target is a list and it has to be a numpy array. I'm surprised it worked well before when I just used the estimator directly.
- For some reason (I don't know why, yet), it doesn't work either if I use the sparse matrix created by the DictVectorizer. I had to, "manually", transform each feature dictionary to a feature array with just integers representing each feature value. The transformation process is similar to the one I present in the code for the target values.
Thanks to everyone who tried to help!
If anyone is still interested,
I used the CountVectorizer
on something very similar and it gave me the same error. I realized that the vectorizer gives me a COO sparse matrix which is basically a coordinate list. Elements in COO matrices can't be accessed through row indexes. It is best to convert it to a CSR matrix (Compressed Sparse Row) which indexes row-wise. The conversion can be done easily coo_matrix.tocsr()
. No other change is required, this worked for me.