0

I want to subclass the LibSvm object class exported from the mlpy machine learning package:

from mlpy import MaximumLikelihoodC, LibSvm 

class Svm(LibSvm):   

def __init__(self,Gs,ls):
    self._K = ls.shape[1]
    self._Gs = Gs
    self._N = Gs.shape[1]
    self._ls = ls
    LibSvm.__init__('c_svc','rbf',\
            gamma=1.0/self._N,C=100,probability=True)

When I call the constructor, e.g.,

svm = Svm(Gs,ls)

the interpreter ignores my init and executers the init method of LibSvm, giving an error

svm = SVM(Gs,ls)  
File "libsvm.pyx", line 146, in mlpy.libsvm.LibSvm.__cinit__ mlpy/libsvm/libsvm.c:1803)
ValueError: invalid svm_type

I have no problem subclassing MaximumLikelihoodC using the same syntax.

1
  • That should have been LibSvm.__init__(self,'c_svc','rbf',\ gamma=1.0/self._N,C=100,probability=True), but it still gives the same error. Commented Jan 25, 2013 at 11:12

1 Answer 1

1

Python classes that are implemented in C cannot be subclassed unless they are specially designed for it, see Which classes cannot be subclassed?.

By the looks of the error message, it seems pretty certain its implemented in C, and I expect the author didn't put in the extra work to make it subclassable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.