0
votes

I don't understand how to deal with multi class classification with SVM. All I have found at internet is one to all approach which is for binary classification only. But, my target is for example:

print(target)

Output:

[ 0  0  0 ... 9 9 9] 

So, How to deal this with SVM properly? I have just build the model like those examples. But, it seems to me that's not correct way for multi label classification. Please guide me. If SVM is not a good choice at all, suggest me please which one will be good (and easy to implement like my example below if possible) among Random Forest, decision trees, K nearest neighbors etc. (except NN and CNN as I have already implemented with those two algorithms in my dataset, I just need one more algorithm to compare my results). So far, My coding:

X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=42)

from sklearn.svm import SVC
model_svm = SVC(kernel='linear')
clf_svm = model_svm.fit(X_train,y_train)
y_svm = model_svm.predict(X_test)

from sklearn.metrics import accuracy_score
print('Accuracy of SVM: ', accuracy_score(y_svm, y_test))
1
Please clarify if you are actually talking about multi-label (a sample can belong to more than one classes simultaneously) or simple multi-class (many classes, but a sample can belong to one and only one class) classification. - desertnaut
multi-class, for example Fashion-MNIST; I have edited title of my question - user1896653
What exactly you ask is unclear; do you have any specific issues with the code shown here? - desertnaut

1 Answers

0
votes

you have used linear kernel, which is good only for linear boundaries:

model_svm = SVC(kernel='linear')

Try using, rbf that can be used for mostly non linear boundaries and very efficient.

model_svm = SVC(kernel='rbf')

reference: https://scikit-learn.org/stable/auto_examples/svm/plot_svm_kernels.html