I am new to python and machine learning. I want to fit SVM to the training sets.
JavaScript
x
5
1
from sklearn.model_selection import train_test_split
2
x_train, x_test, y_train, y_test=train_test_split(x, y, test_size=0.3)
3
clf=SVC(kernel='rbf')
4
clf.fit(x_train,y_train)
5
Then I got an error: ValueError: y should be a 1d array, got an array of shape (73584, 15) instead.
JavaScript
1
2
1
x_train.shape, x_test.shape, y_train.shape, y_test.shape
2
Output:
JavaScript
1
2
1
((73584, 37), (31536, 37), (73584, 15), (31536, 15))
2
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.