Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use scikit-learn's SVM with histograms as features?

I wish to use scikit-learn's SVM with a chi-squared kernel, as shown here. In this scenario, the kernel is on histograms, which is what my data is represented as. However, I can't find an example of these used with histograms. What is the proper way to do this?

Is the correct approach to just treat the histogram as a vector, where each element in the vector corresponds to a bin of the histogram?

Thank you in advance

like image 996
Jim Avatar asked Dec 16 '22 19:12

Jim


1 Answers

There is an example of using an approximate feature map here. It is for the RBF kernel but it works just the same.

The example above uses "pipeline" but you can also just apply the transform to your data before handing it to a linear classifer, as AdditiveChi2Sampler doesn't actually fit to the data in any way.

Keep in mind that this is just and approximation of the kernel map (that I found to work quite well) and if you want to use the exact kernel, you should go with ogrisel's anwser.

like image 76
Andreas Mueller Avatar answered Dec 28 '22 15:12

Andreas Mueller