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.
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.