Orange Forum • View topic - Build SVM classifier with weight

Build SVM classifier with weight

A place to ask questions about methods in Orange and how they are used and other general support.

Build SVM classifier with weight

Postby aonlazio » Fri Jul 31, 2009 8:08

I want to build an SVM classifier from the data that have weights assigned. However, when I later use that classifier to classify an example (without weight, which should not have anyway because you want to classify an unseen example), I got errors like below

data = orange.ExampleTable('iris')

pp = orange.Preprocessor_addClassWeight()
pp.classWeights = [0.5,0.25,0.25]
pp.equalize = 0
datanew,weightID = pp(data)

learner = orngSVM.SVMLearner(svm_type=orange.SVMLearner.C_SVC,kernel_type = orange.SVMLearner.RBF)
classifier = learner(datanew,weight=True)

predict = classifier(data[0])

File "C:\Python25\lib\site-packages\orange\", line 135, in __call__
example = orange.Example(self.domain, example)
KernelException: 'orange.Example': the value of meta attribute 'w' is missing

I mean, come on, we want to classify "new" or "never before seen" example, why does it ask for 'w' anyway? may be this is a bug, I do not know. Could anyone explain to me?

Thanks in advance


Postby Ales » Tue Aug 04, 2009 10:38

SVM handles class weights differently than the rest of learners. It is also a recently added feature so it is not yet documented.

Try this code instead:
Code: Select all
learner = orngSVM.SVMLearner(svm_type=orange.SVMLearner.C_SVC,kernel_type = orange.SVMLearner.RBF)
learner.weight=[(0, 0.5), (1, 0.25), (2, 0.25)]
classifier = learner(data)

predict = classifier(data[0])

Return to Questions & Support