Ask Your Question
0

How do I use featureExtractors with an SVM?

asked 2013-04-29 08:21:19 -0500

blz gravatar image

updated 2013-04-29 09:33:21 -0500

Hello,

I've been trying to do simple binary classification using SimpleCV's SVMClassifier. Here's what I've tried, followed by the error:

svm = SVMClassifier([HueHistogramFeatureExtractor])
svm.train([train_airplanes, train_leaves], ['Airplanes', 'Leaves'])

error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-31-50d09bd20b62> in <module>()
      1 svm = SVMClassifier([HueHistogramFeatureExtractor])
----> 2 svm.train([train_airplanes, train_leaves], ['Airplanes', 'Leaves'])

/usr/local/lib/python2.7/dist-packages/SimpleCV/MachineLearning/SVMClassifier.pyc in train(self, paths, classNames, disp, subset, savedata, verbose)
    229         colNames = []
    230         for extractor in self.mFeatureExtractors:
--> 231             colNames.extend(extractor.getFieldNames())
    232 
    233         if(count <= 0):

TypeError: unbound method getFieldNames() must be called with HueHistogramFeatureExtractor instance as first argument (got nothing instead)

The documentation is pretty sparse, so I'm not sure what I should be doing differently.

EDIT

@kscottz

Here's what I get when I pass an instance of the featureExtractor to the SVM.

hhfe = HueHistogramFeatureExtractor()
svm = SVMClassifier([hhfe])

svm.train([train_airplanes, train_leaves], ['Airplanes', 'Leaves'])

EDIT 2

Whoops, okay. @kscottz was right. Passing an instance works -- the other problem was a typo in my data path. It would be nice if SVMClassifier checked that paths were valid and threw a more appropriate exception. I'll see if I can put together a pull-request.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-04-29 09:05:07 -0500

kscottz gravatar image

I don't think this should bomb out like it is. Just looking at the little chunk of code you gave I think you may need to pass the SVM module a class instance vs just the generic class name. E.g.

hhfe = HueHistogramFeatureExtractor()
svm = SVMClassifier([hhfe])
svm.train([train_airplanes, train_leaves], ['Airplanes', 'Leaves'])
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-04-29 08:21:19 -0500

Seen: 289 times

Last updated: Apr 29 '13