How do kernels allow SVMs to be applied to non-vector data such as strings or graphs?

Quick Overview

Explain how a support vector machine can learn on strings, graphs and other non-vector data through kernel functions. Tests understanding of the SVM dual and Gram matrix, common string and graph kernels, and the positive semidefinite requirement on a similarity.

How do kernels allow SVMs to be applied to non-vector data such as strings or graphs?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

How do kernels allow SVMs to be applied to non-vector data such as strings or graphs? Think of inputs like DNA sequences or molecular graphs, which have no natural fixed-length feature vector. ```hint Where the data enters Write out the SVM dual objective and the decision function. Which operations on the training points do they actually perform? ``` ```hint What a kernel must satisfy Not every similarity score can stand in for an inner product. Think about which property of the Gram matrix keeps the optimization convex. ``` ### What a Strong Answer Covers - Why SVM training and prediction depend on the data only through pairwise kernel values (the Gram matrix, and kernel values against the support vectors). - At least one concrete kernel for strings and one for graphs, with the feature space each one uses implicitly and how it is computed. - The validity requirement (symmetric, positive semidefinite) and what to do when a natural similarity such as edit distance fails it. - The cost of the approach: a quadratic number of kernel evaluations, expensive graph kernels, and normalization for objects of different sizes. - How a custom kernel is passed to a library in practice (a precomputed Gram matrix, with test-by-train shape at prediction time). ### Follow-up Questions - How would you show that a proposed similarity function is a valid kernel, or prove that it is not? - Edit distance gives a Gram matrix with negative eigenvalues on your data. What are your options, and what does each one cost? - You have 500,000 molecules and the full Gram matrix does not fit in memory. How would you scale training? - When would you choose a graph neural network over a Weisfeiler-Lehman kernel SVM?

Overview: Explain how a support vector machine can learn on strings, graphs and other non-vector data through kernel functions. Tests understanding of the SVM dual and Gram matrix, common string and graph kernels, and the positive semidefinite requirement on a similarity.

PracHub logo
General
Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

How do kernels allow SVMs to be applied to non-vector data such as strings or graphs?

Think of inputs like DNA sequences or molecular graphs, which have no natural fixed-length feature vector.

What a Strong Answer Covers Guidance

  • Why SVM training and prediction depend on the data only through pairwise kernel values (the Gram matrix, and kernel values against the support vectors).
  • At least one concrete kernel for strings and one for graphs, with the feature space each one uses implicitly and how it is computed.
  • The validity requirement (symmetric, positive semidefinite) and what to do when a natural similarity such as edit distance fails it.
  • The cost of the approach: a quadratic number of kernel evaluations, expensive graph kernels, and normalization for objects of different sizes.
  • How a custom kernel is passed to a library in practice (a precomputed Gram matrix, with test-by-train shape at prediction time).

Follow-up Questions Guidance

  • How would you show that a proposed similarity function is a valid kernel, or prove that it is not?
  • Edit distance gives a Gram matrix with negative eigenvalues on your data. What are your options, and what does each one cost?
  • You have 500,000 molecules and the full Gram matrix does not fit in memory. How would you scale training?
  • When would you choose a graph neural network over a Weisfeiler-Lehman kernel SVM?