Explainable Support Vector Machine

Machine Learning
Introduced by
Cortes & Vapnik (SVM); explainability layer via Lundberg & Lee (SHAP, 2017) and Ribeiro et al. (LIME, 2016)
Year
2016–2017 (XAI layer)
Type
Post-hoc explainability applied to SVM
Family
Machine learning

What does it do?

Explainable SVM pairs a trained Support Vector Machine with a post-hoc explanation layer, most often SHAP or LIME, that attributes individual predictions to input features and summarises feature importance across a dataset.

The SVM itself is left unchanged, so its predictive performance is that of the underlying model. The approach targets settings such as clinical decision support and credit scoring, where a prediction must be justified to people who did not train the model.

The intuition behind the method

An SVM finds the maximum-margin hyperplane separating two classes. For a kernel SVM, that hyperplane lives in a feature space induced by the kernel, so its decision rule cannot be read directly from the input coefficients. Post-hoc explainers such as SHAP and LIME treat the trained model as a scoring function and ask how much each input feature moved a specific prediction relative to a baseline. For SHAP, the attributions for one instance sum to the difference between that instance's model output and the base value, which is the expected model output over a background dataset. The model's parameters and decision boundary are not modified.

History

Support Vector Machines were introduced by Cortes and Vapnik, the originators named on this page. The opacity of kernel-based decision rules motivated post-hoc explanation methods in the 2016–2017 period: LIME (Ribeiro et al., 2016) explains individual predictions with a locally fitted surrogate model, and SHAP (Lundberg and Lee, 2017) grounds feature attributions in Shapley values from game theory. Applying these explainers to SVMs in medicine, bioinformatics and finance is a later extension of that work; the extent of its adoption is not documented in the sources listed here.

When to use it

Choose Explainable SVM when a support vector machine already gives acceptable predictive performance and reviewers, regulators, or domain users need justifications for individual predictions, as in clinical decision support or credit scoring. It suits tabular data where the kernel has been selected and validated, and where instance-level explanations are needed rather than only aggregate statistics. Do not use it as a substitute for an intrinsically interpretable model such as logistic regression or a shallow decision tree when those perform comparably, because native interpretability avoids the approximation and sampling variability of post-hoc attribution. A linear SVM whose weight vector already gives the feature contributions usually does not need an added explainer.

Limitations and considerations

  • For non-linear kernels, KernelSHAP must approximate Shapley values by sampling coalitions, which is computationally costly on large datasets and introduces sampling variability.
  • Attributions describe the SVM's score, not its internal reasoning; the explainer is an approximation whose values can change across random seeds.
  • A linear SVM already exposes its weight vector, so an added explainer mainly repeats information available directly.
  • Global mean absolute SHAP importance does not show the structure of feature interactions as explicitly as a decision tree does.
  • Plausible-looking attributions can be over-trusted; they are not validated against causal mechanisms and do not establish them.
  • Attributions are relative to the chosen background sample, and KernelSHAP's estimation assumes approximately independent features; with strongly correlated inputs, per-feature values can be misleading.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • The SVM is not modified, so adding an explanation layer does not change predictive performance.
  • SHAP attributions carry the efficiency, symmetry and dummy properties of Shapley values, a more principled basis than ad hoc saliency scores.
  • Because the explainer treats the SVM as a black-box scoring function, the same procedure applies to linear, RBF and polynomial kernels.
  • One set of attributions supports both instance-level justifications and dataset-level importance summaries such as mean absolute SHAP values.
  • Waterfall, beeswarm and dependence plots make the attributions straightforward to present in reports.

Applications

  • Clinical decision support: an explanation could show which symptoms or biomarkers drove an SVM-based diagnosis for a specific patient.
  • Credit risk scoring: per-applicant feature attributions could support reviewers' explanation requirements.
  • Bioinformatics: attributions could indicate which genes or proteins contributed most to an SVM classification of tissue samples.
  • Intrusion detection: attributions could show which network features contributed to an SVM anomaly alert during an investigation.
  • Text classification: SHAP could attribute sentiment or topic predictions to individual tokens or linguistic features.

How it works

How it works

1

A Support Vector Machine is fitted on labelled training data with a chosen kernel (linear, RBF, or polynomial). The kernel implicitly maps inputs into a feature space in which the separating hyperplane is found by solving a quadratic programme. The kernel type, the regularisation parameter C, and the kernel parameter gamma (the RBF bandwidth) are selected by cross-validation before the explanation step. Input features should be standardised on the training data before fitting (for example to zero mean and unit variance), because RBF and polynomial kernels and the regularisation parameter C are sensitive to feature scale. The same fitted scaler must then be applied to the background sample and to the test instances being explained.

2

A model-agnostic explainer is chosen. SHAP (SHapley Additive exPlanations) uses Shapley values from cooperative game theory to assign each feature a contribution to a specific prediction. LIME (Local Interpretable Model-agnostic Explanations) fits a locally weighted linear surrogate around the instance being explained. Both treat the SVM as a scoring function and do not require changes to its internals.

3

For SHAP, the Shapley value of feature i is a weighted average of its marginal contributions over all subsets of the other features, as in the formula above. Shapley values satisfy efficiency (attributions sum to the model output minus the base value, the expected output over the background dataset), symmetry, and the dummy property (a feature that never changes the output receives zero attribution). For non-linear SVMs, KernelSHAP estimates these values by sampling feature coalitions and fitting a weighted linear regression, so the estimates are approximate and vary with the sample. Features absent from a coalition are represented by values drawn from the background dataset, so the attributions depend on the choice of that sample, and the estimation assumes approximately independent features. SHAP is applied by default to the SVM's decision function, a signed score in decision-value units rather than a probability. Attributions expressed on a probability scale require a calibrated output, such as Platt scaling, and should be labelled as probability-scale contributions.

Formula
\phi_i = \sum_{S \subseteq F \setminus \{i\}} \frac{|S|!(|F|-|S|-1)!}{|F|!}[f(S \cup \{i\}) - f(S)]
4

Local explanations describe why the model assigned a particular score to one instance, which is useful for auditing individual decisions. Global explanations aggregate local attributions, for example as mean absolute SHAP values across the dataset, to show which features drive the model overall. This gives a summary that can be compared in spirit with regression coefficients, though it is not a coefficient.

5

Check faithfulness: if the attributions are correct, removing or masking the highest-attributed features should degrade the SVM's performance more than removing low-attributed features. Compare global SHAP importance with an independent measure such as permutation importance, and check whether attribution directions agree with domain knowledge. Confirm first that cross-validated performance is stable, since explanations of an unreliable model are not informative about the phenomenon.

Common pitfalls

  • Reporting SHAP values without first confirming that the SVM has acceptable and stable predictive performance across cross-validation folds.
  • Using KernelSHAP with too few coalition samples yields noisy, hard-to-reproduce attributions; increase the number of samples until the values stabilise across repeated runs.
  • Treating SHAP attributions as causal effects rather than as contributions to the model's prediction.
  • Ignoring class imbalance when training the SVM and then reading the attributions as if they describe the true population.
  • Presenting local explanations for a single test instance as representative of the model's global behaviour.
  • Choosing the background sample carelessly: attributions are relative to it, so use a representative training subset (or a k-means summary of it) and check feature correlations before interpreting per-feature values.
  • Reporting decision-function attributions in probability units, or comparing attributions computed on different scales or with different background samples as if they were directly comparable.

Frequently asked questions

Does adding SHAP change the SVM's predictions?

No. SHAP is a post-hoc analysis applied after training. It reads the model's outputs but does not modify the model's parameters, kernel, or decision boundary.

Which explainer should I use — SHAP or LIME?

SHAP is generally preferred when consistency properties matter, because Shapley values satisfy efficiency and the dummy property. LIME fits a separate local surrogate for each instance, so its explanations depend on the local sampling and can vary between nearby instances.

Is a linear SVM explainable without SHAP?

Yes. A linear SVM's weight vector gives the feature weights directly. Each feature's contribution to the decision function relative to zero is w_i * x_i; relative to a background mean, it is w_i * (x_i - E[x_i]), which is the attribution SHAP recovers for a linear model under feature independence. SHAP is most valuable for non-linear kernels (RBF, polynomial), where no closed-form feature attribution exists.

How many SHAP samples do I need for a stable estimate?

KernelSHAP estimates improve with more coalition samples. Increase the number until the mean absolute SHAP values stay stable across repeated runs with different random seeds.

Can I use Explainable SVM to comply with GDPR's right-to-explanation?

SHAP explanations can help produce human-readable justifications for individual decisions, the kind of information that automated-decision provisions in data-protection law concern. Whether they meet a specific legal requirement depends on jurisdiction, so a legal team should review the approach before SHAP output is used as the sole compliance mechanism.

Related methods

Sources

  1. Lundberg, S. M., & Lee, S. I. (2017). A unified approach to interpreting model predictions. Advances in Neural Information Processing Systems, 30, 4765–4774.

    Open publication reference
  2. Ribeiro, M. T., Singh, S., & Guestrin, C. (2016). 'Why should I trust you?': Explaining the predictions of any classifier. Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 1135–1144.

    Open DOI reference