+3 votes
in Machine Learning by (56.7k points)
recategorized by

I am running a classifier and for that, I used np.array() to generate labels for the data. I collected all the labels in a list and then used np.array() to convert it to a numpy array.

e.g.

a= [list of labels]

Y=np.array(a)

But the above logic created Y as a matrix and because of that train_test_split function of sklearn.model_selection module is giving an error.  train_test_split function needs Y as an array, not as a matrix. Is there any way to fix this issue? I tried a few things, but  train_test_split function is still giving the error.

1 Answer

+1 vote
by (349k points)
selected by
 
Best answer

You can use flatten() function to convert numpy matrix to numpy array. See the following example:

>>> import numpy as np
>>> a=np.array([[1,0,1,1,0,0,1]])
>>> a
array([[1, 0, 1, 1, 0, 0, 1]])
>>> a.flatten()
array([1, 0, 1, 1, 0, 0, 1])
>>>


...