Orange Forum • View topic - Error using SVM RFE

Error using SVM RFE

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

Error using SVM RFE

Postby jasonzutty » Tue Mar 19, 2013 18:42

Does this error mean anything to anyone? I can't figure out what I am doing wrong.

Traceback (most recent call last):
File "build/bdist.linux-x86_64/egg/GPFramework/gtMOEP.py", line 202, in evaluate
x = func(_inst.dataPair)
File "<string>", line 1, in <lambda>
File "build/bdist.linux-x86_64/egg/GPFramework/methods.py", line 217, in svmFE
dataPair.testData.orange = RFE(dataPair.testData.orange,K)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/utils/__init__.py", line 199, in wrap_call
return func(*args, **kwargs)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/utils/__init__.py", line 199, in wrap_call
return func(*args, **kwargs)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 1261, in __call__
scores = self.get_attr_scores(data, progress_callback=progress_callback)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/utils/__init__.py", line 199, in wrap_call
return func(*args, **kwargs)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/utils/__init__.py", line 199, in wrap_call
return func(*args, **kwargs)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 1234, in get_attr_scores
scores = [(scorer(attr, data), attr) for attr in attrs]
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 1134, in __call__
weights = self._extract_weights(classifier, data.domain.attributes)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 1145, in _extract_weights
weights = get_linear_svm_weights(classifier, sum=True)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 994, in get_linear_svm_weights
bin_classifier = classifier.get_binary_classifier(i, j)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 580, in get_binary_classifier
coef = self.coef[classifier_i]
IndexError: list index out of range

Re: Error using SVM RFE

Postby Ales » Wed Mar 20, 2013 11:03

This happens when the training dataset for SVM does not have any instances for some class (or a subset of classes). The folowing code reproduces the error
Code: Select all
iris = Orange.data.Table("iris")
iris_missing = Orange.data.Table(iris[50:])  # Remove all Iris-setosa instances
svm_l = Orange.classification.svm.SVMLearner()
svm_c = svm_l(iris_missing)
# This breaks
svm_c.get_binary_classifier(1, 2)

This should be considered a bug in SVMLearner.

Note also that using LinearSVMLearner with RFE should work.

Re: Error using SVM RFE

Postby jasonzutty » Wed Mar 20, 2013 13:41

Does it do any work to split the data internally, because I think I am sending it data with two classes and only two fields for classes.

Re: Error using SVM RFE

Postby Ales » Wed Mar 20, 2013 14:00

jasonzutty wrote:Does it do any work to split the data internally
I'm pretty sure it does not.
jasonzutty wrote:because I think I am sending it data with two classes and only two fields for classes.
Can you provide a dataset that reproduces the problem?

Re: Error using SVM RFE

Postby jasonzutty » Wed Mar 20, 2013 14:01

By changing to LinearSVMLearner I now have a different error!
'orange.ExampleTable': merging constructor was given no datasets to merge
Traceback (most recent call last):
File "build/bdist.linux-x86_64/egg/GPFramework/gtMOEP.py", line 226, in evaluate
x = func(_inst.dataPair)
File "<string>", line 1, in <lambda>
File "build/bdist.linux-x86_64/egg/GPFramework/methods.py", line 217, in svmFE
dataPair.trainData.orange = RFE(dataPair.trainData.orange,K)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/utils/__init__.py", line 199, in wrap_call
return func(*args, **kwargs)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/utils/__init__.py", line 199, in wrap_call
return func(*args, **kwargs)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 1261, in __call__
scores = self.get_attr_scores(data, progress_callback=progress_callback)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/utils/__init__.py", line 199, in wrap_call
return func(*args, **kwargs)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/utils/__init__.py", line 199, in wrap_call
return func(*args, **kwargs)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 1234, in get_attr_scores
scores = [(scorer(attr, data), attr) for attr in attrs]
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 1134, in __call__
weights = self._extract_weights(classifier, data.domain.attributes)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 1145, in _extract_weights
weights = get_linear_svm_weights(classifier, sum=True)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 994, in get_linear_svm_weights
bin_classifier = classifier.get_binary_classifier(i, j)
File "/home/jason/ENV1/local/lib/python2.7/site-packages/Orange/classification/svm/__init__.py", line 596, in get_binary_classifier
all_sv = Orange.data.Table(all_sv)
KernelException: 'orange.ExampleTable': merging constructor was given no datasets to merge

Re: Error using SVM RFE

Postby jasonzutty » Wed Mar 20, 2013 14:10

I am back to the original error with the new classifier as well. It would take some legwork to get my datasets up here, but I'll see what I can do. Also, as a note, it doesn't error out immediately, it can take on the upwards of 5 minutes before I get to any problem.

Re: Error using SVM RFE

Postby Ales » Wed Mar 20, 2013 14:20

From the stack trace it seems that SVMLearner is still used.
... line 596, in get_binary_classifier ...
This is is in SVMClassifier class returned by SVMLearner. LinearSVMLearner returns a LinearClassifier which does not have this method.

How are you constructing/using the RFE class?

Re: Error using SVM RFE

Postby jasonzutty » Wed Mar 20, 2013 14:35

You are right! I made the change so my code reads
SVMLearner = Orange.classification.svm.LinearSVMLearner()
# Use the learner to create a feature extractor
RFE = Orange.classification.svm.RFE(learner=SVMLearner)

But I was actually pickling in an old RFE built on the old learner to apply to the dataset rather than regenerating it with this line of code. I will let you know how it works. Thanks!


Return to Questions & Support