title: Precomputed Kernels with LibSVM in Python
body: <p>I've been searching the net for ~3 hours but I couldn't find a solution yet. I want to give a precomputed kernel to libsvm and classify a dataset, but:</p>
  
  <ul>
  <li><p>How can I generate a precomputed kernel? (for example, what is the basic precomputed kernel for <a href="http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data" rel="noreferrer">Iris data</a>?)</p></li>
  <li><p>In the libsvm documentation, it is stated that:</p>
  
  <p>For precomputed kernels, the first element of each instance must be
  the ID. For example,</p>
  
  <pre><code>        samples = [[1, 0, 0, 0, 0], [2, 0, 1, 0, 1], [3, 0, 0, 1, 1], [4, 0, 1, 1, 2]]
          problem = svm_problem(labels, samples)
          param = svm_parameter(kernel_type=PRECOMPUTED)
  </code></pre></li>
  </ul>
  
  <p>What is a ID? There's no further details on that. Can I assign ID's sequentially?</p>
  
  <p>Any libsvm help and an example of precomputed kernels really appreciated.</p>