# SVM classification on distance matrix

How can I do an SVM classification when I only have a distance matrix (pairwise matrix)?

Edited: I want to classify my data in two groups: healthy and sick. My original data are histograms (which are extracted from images), so I measure the distance (euclidean and others) between all the histograms and I obtain a distance matrix, I know how to use a clustering method with distance matrix (K-medoids clustering for example) but how can I classify my subjects using a supevised classification method when my original data are histograms?

other additions: I do know which subject is sick or healthy. I measure a variable for each subject, so a subject -> a histogram. and I want to know how well can the variable separates healthy subjects from sick patients. For the clustering part that I already did, I used k-medoids (PAM algorithm) and as the input I used the distance matrix that I obtained by measuring the distances between all histograms and I want to do the same thing with a supervised classification method.

Is there a supervised classification method that can classify objects like histograms (distributions)

• Yes I do know which subject is sick or healthy. I measure a variable for each subject, so a subject -> a histogram. and I want to know how well can the variable separates healthy subjects from sick patients. For the clustering part that I already did, I used k-medoids (PAM algorithm) and as an imput i used the distance matrix that I obtained by measuring the distances between all histograms and I want to do the same thing with a supervised classification method. Jun 6, 2018 at 17:19
• Do you have the underlying measurements that were used to create the histograms? Are all the histograms based on the same number of measurements? (I appreciate your continued work on clarifying this question.) Jun 6, 2018 at 17:27
• Histograms are extracted from images. I guess my post can be summarized by this question: Is there a supervised classification method that can classify objects like histograms (distributions) Jun 6, 2018 at 17:37
• Thank you for clarifying. I have reopened this. I assume the images are something like voxel intensities from fMRIs, or something like that? I suspect what you want is to use the raw data from the scan as your input data, not the histograms or distances between histograms, but I'll have to let someone else answer. Jun 6, 2018 at 17:56
• Thank you. Something like that, yes. Actually in my case every voxel is a measure of a biomarker, so I have an "parametric" image (biomarker map) for every subject, and I extract the histograms from those images. and I want to know how to classify my subjects into 2 groups based on those histograms Jun 6, 2018 at 18:06

Kernel SVMs often operate on the distance matrix indirectly. For example, the RBF kernel with Euclidean distance is is \begin{align} k(x,y)&=\exp(−\gamma ||x−y||_2^2) \\ &=\exp(−\gamma d(x,y)^2), \end{align} but there's no mathematical impediment to using an alternative to Euclidean distance, such as a distance between two histograms. Suppose that you've recorded all of your pairwise distances in some matrix $M$. The RBF kernel matrix $K$ corresponding to the distance matrix $M$ is given by
$$K_{ij} = \exp(-\gamma M_{ij}^2)$$ where $A_{ab}$ denotes the value stored in the $a$th row of the $b$th column of matrix $A$. Most SVM software allows you to supply your own kernel matrix to the estimation routine, so you can just hand $K$ off to some software and proceed as usual.
FWIW, this functionality is implemented in Python sklearn and R kernlab. But I've found bugs in kernlab when using a custom kernel function and don't know if they've been fixed.