Skip to content
Advertisement

How to solve “ValueError: y should be a 1d array, got an array of shape (73584, 15) instead.”

I am new to python and machine learning. I want to fit SVM to the training sets.

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test=train_test_split(x, y, test_size=0.3)
clf=SVC(kernel='rbf')
clf.fit(x_train,y_train)

Then I got an error: ValueError: y should be a 1d array, got an array of shape (73584, 15) instead.

x_train.shape, x_test.shape, y_train.shape, y_test.shape

Output:

((73584, 37), (31536, 37), (73584, 15), (31536, 15))

So how should I fix this problem? Would appreciate a lot if any advices.


Shape of y:

Examples of label y are:

Advertisement

Answer

SVM output is, for each data point, one class. Therefore, with 73584 data points of 37 features, your target needs to be a vector of 73584 classifications, each of which is a class number. Did you one-hot encode your output? You should undo that.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement