Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message on multiclass SVM with more than 2 classes #4173

Open
bmurauer opened this issue Feb 13, 2018 · 3 comments
Open

Error message on multiclass SVM with more than 2 classes #4173

bmurauer opened this issue Feb 13, 2018 · 3 comments

Comments

@bmurauer
Copy link

bmurauer commented Feb 13, 2018

The following code fails with an error message SystemError: [ERROR] In file /opt/shogun/src/shogun/multiclass/MulticlassLibSVM.cpp line 200: SVM set failed:

import numpy as np
from shogun import SubsequenceStringKernel
from shogun import MulticlassAccuracy
from shogun import MulticlassLabels
from shogun import MulticlassLibSVM
from shogun import StringCharFeatures
from shogun import RAWBYTE
from sklearn.preprocessing import LabelEncoder

x = ['car', 'war', 'fair', 'hair', 'lift', 'gift']
y = np.array([1, 1, 2, 2, 3, 3], np.float64)

xt = ['bar', 'rift']
yt = np.array([1, 3], np.float64)

features_train = StringCharFeatures(x, RAWBYTE)
features_test = StringCharFeatures(xt, RAWBYTE) 

labels_train = MulticlassLabels(y)
labels_test = MulticlassLabels(yt)

C = 1.0
epsilon = 0.0001
kernel = SubsequenceStringKernel(features_train, features_train, 5, 1.0)

svm = MulticlassLibSVM(C, kernel, labels_train)
svm.set_epsilon(epsilon)
svm.train()
labels_predict = svm.apply_multiclass(features_test)
accu = MulticlassAccuracy()
print(accu.evaluate(labels_predict, labels_test))

however, if I change the y array to [1,1,2,2,1,1], no such error occurs. If i put four different classes in y (e.g. [1,1,2,2,3,4]), the error occurs as well. I dug into the code of MulticlassLibSVM a little bit, I suspect the lines 162-194 to be the culprit (they seem a bit 'off'), but I don't know enough about the implementation details to be of any help i fear :(

Of course, i figure the error is on my part, since the multiclass example delivered with the package runs just fine. I just figured that the error message is not very helpful at this point.

@vigsterkr
Copy link
Member

@bmurauer thnx for the bug report, indeed bug is coming from somewhere there :) it's a bit painful to look at that code, lemme try if it's easy to fix.

@vigsterkr
Copy link
Member

@bmurauer ok so a very quick fix is that you change the labeling to 0 base 💃
but yeah this shoudl work with any arbitrary labeling... i'm working on it but that'll take a bit longer to get in.

@stale
Copy link

stale bot commented Feb 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 26, 2020
@gf712 gf712 added Type: Bug and removed stale labels Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants