2
$\begingroup$

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)

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – learneRS Jun 6 '18 at 17:19
  • $\begingroup$ 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.) $\endgroup$ – gung Jun 6 '18 at 17:27
  • 1
    $\begingroup$ 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) $\endgroup$ – learneRS Jun 6 '18 at 17:37
  • $\begingroup$ 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. $\endgroup$ – gung Jun 6 '18 at 17:56
  • $\begingroup$ 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 $\endgroup$ – learneRS Jun 6 '18 at 18:06
1
$\begingroup$

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.

Importantly, this doesn't necessarily require you to work with a machine learning method which is specialized for histograms, since you've already pre-processed the histogram data into a format which is amenable to SVM.

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.

$\endgroup$
  • $\begingroup$ well good news! thank you! Do you know the R function that does that? $\endgroup$ – learneRS Jun 8 '18 at 9:03
  • 1
    $\begingroup$ @Sanette I've updated my answer. $\endgroup$ – Sycorax Jun 8 '18 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.