How to use scikit-learn SVM with histograms as functions?

I want to use scikit-learn SVM with a chi-square core, as shown here . In this case, the core is on the histograms, and this is what is represented by my data. However, I cannot find an example of how they are used with histograms. What is the right way to do this?

The correct approach is simply to consider the histogram as a vector, where each element in the vector corresponds to the histogram bunker?

Thank you in advance

+4
source share
2 answers

Below is an example of using an approximate function map here . This is for the RBF core, but it works the same.

The above example uses a β€œpipeline”, but you can also just apply the transformation to your data before passing it to a linear class, since AdditiveChi2Sampler actually not fit to the data in any way.

Keep in mind that this is a fair and approximation of the kernel map (which I found to work quite well), and if you want to use the exact kernel, you have to go with ogrisel anwser.

+10
source

sklearn.svm.SVC accepts custom kernels in 2 ways:

  • arbitrary python functions passed as kernel argument to the constructor
  • precomputed kernel matrix passed as the first argument to fit and kernel=precomputed in the constructor

The first one can be much slower, but does not require allocation of the entire kernel matrix in advance (which can be prohibitive for n_samples ).

More detailed information and links to examples in the documentation on user kernels .

+2
source

Source: https://habr.com/ru/post/1432726/


All Articles