Chapter 18 — Support Vector Machines
Maximum Margin • C • Kernels • RBF • Scaling • Model Selection
Learning decision boundaries by maximizing separation between classes in a transformed feature space
| BRIDGE FROM CHAPTER 17 Ensemble trees improve predictions by combining many models. Support Vector Machines take a different approach: they construct a decision boundary whose position is determined mainly by the observations closest to the class boundary. |
Chapter overview
Support Vector Machines (SVMs) are supervised learning methods designed to find decision boundaries with a large margin between classes. Rather than attempting to fit every training observation equally, a support vector classifier focuses on the critical observations located near the boundary. These points, called support vectors, determine the final separating surface.
For linearly separable data, the central idea is a maximum-margin hyperplane. Real datasets, however, contain overlap, measurement noise, outliers, and nonlinear relationships. Soft-margin classification introduces the parameter C to balance a wide margin against classification violations. Kernel methods then extend the same margin principle to nonlinear decision boundaries without explicitly constructing all transformed features.
This chapter emphasizes practical use. Students will learn why feature scaling is essential for SVMs, how C and gamma interact, when linear versus RBF kernels are appropriate, why probability estimation has additional cost, and how to compare models fairly inside a preprocessing pipeline.
| CENTRAL IDEA The best SVM boundary is not merely any boundary that separates the training classes. It is a boundary chosen to create a large protective margin while controlling violations. Only a subset of influential observations - the support vectors - directly defines that boundary. |
Learning objectives
- Define a separating hyperplane, margin, and support vector in a classification problem.
- Distinguish hard-margin and soft-margin support vector classification.
- Explain how the parameter C controls the penalty for margin violations and classification errors.
- Relate large and small values of C to regularization and model flexibility.
- Distinguish linear, polynomial, and radial basis function (RBF) kernels.
- Explain the kernel trick as similarity computation in an implicit transformed feature space.
- Interpret gamma as the spatial reach of individual observations in an RBF model.
- Explain the interaction between C and gamma and connect it to underfitting and overfitting.
- Use StandardScaler inside a Pipeline to prevent scale dominance and preprocessing leakage.
- Compare linear and RBF SVC models using identical train/test data and evaluation metrics.
- Inspect support-vector counts and decision-function scores as diagnostic information.
- Use cross-validation to tune C and gamma without optimizing directly on the final test set.
Table 18.1. Chapter structure
| Section | Focus | Student outcome |
|---|---|---|
| 18.1 | Maximum-margin classification | Explain hyperplanes, margins, support vectors, hard margin, and soft margin |
| 18.2 | Parameter C | Connect error penalty to regularization and model flexibility |
| 18.3 | Kernel methods | Compare linear, polynomial, and RBF similarity functions |
| 18.4 | RBF parameters | Interpret gamma and its interaction with C |
| 18.5 | Practical considerations | Apply scaling, assess computational cost, and handle probabilities |
| Practical lab | Linear versus RBF SVC | Train, evaluate, compare, tune, and interpret two SVC models |
18.1 Maximum-margin classification
Consider a binary classification problem with two groups of observations. A linear classifier predicts the class according to which side of a boundary an observation falls. In two dimensions, the boundary is a line. In three dimensions, it is a plane. In a general feature space with many dimensions, the corresponding object is called a hyperplane.
Many different hyperplanes can separate the same training observations. SVMs introduce a preference: choose a boundary that leaves the largest possible gap between the classes, subject to the violations allowed by the model. This geometric criterion is the origin of maximum-margin classification.
18.1.1 Separating hyperplane
For a linear classifier, a hyperplane can be represented by a score of the form f(x) = wᵀx + b. The vector w controls the orientation of the boundary and b controls its offset. The decision boundary itself consists of points for which f(x) = 0. The sign of the score determines the predicted side of the boundary.
| GEOMETRIC INTERPRETATION The coefficient vector w is perpendicular to the separating hyperplane. Changing b moves the hyperplane without changing its orientation. In a standardized feature space, the geometry of distances is easier to interpret because features are on comparable scales. |
Figure 18.1. From feature vectors to a separating boundary
TRAINING POINTS | → | HYPERPLANE | → | DECISION |
18.1.2 Margin
The margin is the region around the decision boundary that separates the closest observations of the competing classes. A wider margin represents a boundary that is farther from the most difficult training cases. This can improve robustness because small perturbations to noncritical observations are less likely to move the boundary substantially.
In the canonical linear SVM geometry, the two supporting planes can be written as f(x) = +1 and f(x) = -1. The distance between these planes is inversely related to the magnitude of w. Maximizing the margin is therefore equivalent to controlling the size of the coefficient vector while satisfying classification constraints.
| WHY THE MARGIN MATTERS A perfectly accurate training boundary can still generalize poorly if it passes extremely close to many observations. Margin maximization prefers a safer separation, not simply a zero-training-error separation. |
18.1.3 Support vectors
Support vectors are the observations that lie on or inside the margin, or otherwise influence the optimal boundary through a violation. They are the critical training cases. Observations far from the boundary often do not change the fitted SVM if they are moved slightly, because they do not constrain the maximum-margin solution.
This is an important conceptual difference from many other classifiers. In a nearest-neighbor model, many stored observations can be consulted at prediction time. In a support vector classifier, the decision function is determined by the support vectors and their learned coefficients. With nonlinear kernels, prediction cost therefore depends partly on how many support vectors the model retains.
PYTHON • Inspect support vectors in a fitted linear SVC from sklearn.datasets import load_breast_cancer |
| INTERPRETATION A smaller support-vector set can make prediction more economical and may indicate a relatively clean separation. However, support-vector count alone is not a quality metric; it must be interpreted together with validation performance and the chosen C and kernel. |
18.1.4 Hard margin
A hard-margin SVM requires every training observation to be correctly classified and to remain outside the margin. This formulation is appropriate only when the data are perfectly linearly separable in the chosen feature space. One overlapping point can make the constraints impossible, and one extreme outlier can force an undesirable boundary.
Hard-margin classification is therefore mainly useful for understanding the geometry of SVMs. Real machine-learning datasets often contain noisy labels, measurement error, class overlap, or observations that cannot be cleanly separated with the selected features.
| LIMITATION Do not attempt to obtain a hard-margin effect simply by using an extremely large C. A very large penalty can make the model highly sensitive to outliers and numerical details while still not producing a meaningful real-world boundary. |
18.1.5 Soft margin
Soft-margin classification relaxes the requirement that every observation be perfectly separated. The model is allowed to place some observations inside the margin or even on the wrong side of the boundary. These violations are penalized rather than forbidden. This produces a practical trade-off between margin width and training errors.
The parameter C controls the strength of this penalty. Because soft-margin classification tolerates some violations, it can find a more stable boundary on noisy data. The central question becomes not whether errors are allowed, but how expensive those errors should be relative to maintaining a simpler, wider-margin decision surface.
Figure 18.2. Soft-margin decision logic
WIDE MARGIN | → | ALLOW VIOLATIONS | → | GENERALIZE |
Table 18.2. Hard margin versus soft margin
| Aspect | Hard margin | Soft margin |
|---|---|---|
| Training errors | Not allowed | Allowed with a penalty |
| Class overlap | Cannot handle overlap cleanly | Designed for realistic overlap and noise |
| Outlier sensitivity | Very high | Controlled through C |
| Regularization view | Rigid constraints | Explicit trade-off between fit and margin |
| Practical use | Mostly conceptual / special cases | Standard approach for real datasets |
18.2 Parameter C
C is one of the most important SVM hyperparameters. It determines how strongly the optimizer penalizes observations that violate the desired margin or are misclassified. In practical terms, C controls how much the model is willing to sacrifice a wide margin in order to fit difficult training observations.
A useful mental model is that C controls the price of training violations. A high price encourages the classifier to correct more training errors, even if the resulting boundary becomes more specific. A low price permits more violations and emphasizes a smoother, more strongly regularized solution.
18.2.1 Penalty for classification errors
Soft-margin optimization combines two competing objectives: keep the separating boundary simple and wide, and reduce violations on the training observations. C multiplies the loss associated with those violations. As C increases, errors become more costly relative to margin simplicity. As C decreases, the model accepts more training violations in exchange for stronger regularization.
| TERMINOLOGY In scikit-learn, C is described as a regularization parameter, but its direction is the inverse of regularization strength: smaller C means stronger regularization; larger C means weaker regularization. |
18.2.2 Large versus small values of C
Table 18.3. Interpreting C
| Setting | Typical boundary behavior | Training fit | Main risk |
|---|---|---|---|
| Small C | Wider / more tolerant margin | More violations accepted | Underfitting |
| Moderate C | Balances margin and violations | Balanced fit | Usually a sensible search region |
| Large C | Narrower / less tolerant margin | Fewer violations encouraged | Overfitting and outlier sensitivity |
C should not be selected from training accuracy alone. A large value can produce an apparently impressive training score while degrading validation performance. Conversely, a very small value can oversimplify the decision function. Cross-validation evaluates this balance on held-out folds and is therefore the preferred way to select C.
18.2.3 Relationship with regularization
Regularization limits how aggressively a model adapts to the training sample. In an SVM, lowering C increases regularization because the optimization places relatively more emphasis on the margin term and less on eliminating every violation. Increasing C reduces regularization and pushes the model toward fitting difficult observations more closely.
Figure 18.3. C as a regularization control
SMALL C | → | BALANCED C | → | LARGE C |
PYTHON • Compare several C values with cross-validation from sklearn.model_selection import StratifiedKFold, cross_validate |
| EXPERIMENTAL RULE Choose C from cross-validation on the training data. Keep the final test set untouched until the model family and hyperparameters have been selected. |
18.3 Kernel methods
A linear SVM can only create a hyperplane in the original feature space. Many classification problems are not linearly separable. Kernel methods preserve the maximum-margin idea while allowing nonlinear boundaries. They do this by replacing ordinary dot products with kernel functions that measure similarity between observations.
A kernel can be interpreted as computing an inner product in a richer transformed feature space. The remarkable practical advantage is that the transformation does not need to be explicitly constructed. The SVM optimizer can work with pairwise kernel values instead. This is commonly called the kernel trick.
18.3.1 Linear kernel
The linear kernel corresponds to the ordinary dot product between feature vectors. It produces a linear decision boundary in the input feature space. Linear SVMs are attractive when there are many features, when the relationship is approximately linear, or when computational simplicity and interpretability of coefficients are important.
After standardization, a linear SVC can be viewed as assigning weights to features and combining them into one decision score. For very large datasets where only a linear boundary is needed, specialized linear implementations such as LinearSVC or SGDClassifier can scale more efficiently than kernel SVC.
PYTHON • Fit a linear support vector classifier inside a scaling pipeline from sklearn.pipeline import Pipeline |
18.3.2 Polynomial kernel
The polynomial kernel allows interactions between features to contribute to similarity. Its degree parameter controls the polynomial degree. A degree-2 kernel can represent pairwise interaction structure; higher degrees create increasingly flexible surfaces. The kernel also includes gamma and coef0 parameters, so several hyperparameters can influence its behavior.
Polynomial kernels can be useful when domain knowledge suggests interaction patterns that are naturally polynomial. They are less common as a default starting point than linear and RBF kernels because model behavior can become difficult to tune as degree, gamma, coef0, and C interact.
| PRACTICAL STRATEGY Start with a linear kernel as a simple reference and an RBF kernel as a flexible nonlinear reference. Introduce the polynomial kernel when its structure is justified by the data or problem domain. |
18.3.3 Radial basis function kernel
The radial basis function, or RBF, kernel gives high similarity to observations that are close together and rapidly decreasing similarity as they move farther apart. This allows the classifier to construct curved and locally adaptive decision boundaries. The RBF kernel is a strong general-purpose choice when the relationship between features and class is nonlinear and the dataset is not extremely large.
Two hyperparameters dominate the behavior of the RBF SVC: C controls the cost of violations and gamma controls how local the influence of individual observations becomes. Because these parameters interact, they should normally be tuned together.
PYTHON • Fit an RBF SVC with standard scaling from sklearn.pipeline import Pipeline |
18.3.4 Kernel trick
Suppose the original input space cannot be separated by one straight line. A feature transformation might map the observations into a higher-dimensional space where a linear separation becomes possible. Explicitly creating all transformed features could be expensive or even impractical. A valid kernel computes the similarity that would have resulted from those transformed coordinates without explicitly generating them.
Figure 18.4. Kernel-trick intuition
ORIGINAL SPACE | → | KERNEL SIMILARITY | → | IMPLICIT SPACE | → | MARGIN |
| KEY DISTINCTION The fitted RBF SVC is nonlinear in the original feature space, but the maximum-margin optimization can be interpreted as linear separation in an implicit transformed space. |
Table 18.4. Common SVC kernels
| Kernel | Boundary in original space | Key parameters | Typical use |
|---|---|---|---|
| Linear | Linear | C | High-dimensional or approximately linear problems |
| Polynomial | Curved polynomial surface | C, degree, gamma, coef0 | Structured interaction patterns |
| RBF | Flexible nonlinear surface | C, gamma | General nonlinear classification on medium-sized data |
18.4 RBF parameters
The RBF kernel is powerful because it can represent complex boundaries without explicitly defining polynomial or interaction features. That flexibility also creates tuning responsibility. Gamma controls the spatial reach of each training observation, while C controls the willingness to tolerate violations. Their combined setting determines whether the model is smooth, highly local, underfit, or overfit.
18.4.1 Gamma
Gamma determines how quickly similarity decays with distance. A small gamma means that each observation has a broad region of influence. Distant points can still have meaningful similarity, so the resulting decision boundary tends to change gradually. A large gamma means influence is highly local: similarity drops rapidly as distance increases, allowing the boundary to bend around individual observations.
| SCALE DEPENDENCY Gamma operates on distances. If one feature has values in thousands and another has values between 0 and 1, raw Euclidean distances can be dominated by the large-scale feature. Standardization therefore changes not only optimization behavior but the actual meaning of RBF similarity. |
18.4.2 Local versus smooth decision boundaries
Table 18.5. Interpreting gamma
| Gamma | Influence of one training point | Boundary | Main risk |
|---|---|---|---|
| Small | Broad | Smooth, slowly varying | Underfitting |
| Moderate | Balanced | Flexible but controlled | Often a useful region |
| Large | Very local | Highly curved / detailed | Overfitting to noise |
A very small gamma can make the RBF kernel behave almost as though every observation is similarly related to many others, which reduces local flexibility. A very large gamma can create narrow islands of influence around training points. Validation performance is required to find a useful middle ground.
18.4.3 Interaction between C and gamma
C and gamma should not be tuned independently. High gamma increases local flexibility, while high C strongly penalizes violations. The combination of high gamma and high C can therefore create a very detailed boundary that attempts to classify difficult training points correctly. Low gamma and low C can produce an excessively smooth and strongly regularized model.
Table 18.6. Joint C-gamma intuition
| C | Gamma | Likely behavior |
|---|---|---|
| Low | Low | Strong regularization and smooth boundary; underfitting possible |
| High | Low | Smooth geometry but stronger pressure to reduce violations |
| Low | High | Local similarity but greater tolerance for violations |
| High | High | Highly local, strongly fitted boundary; overfitting risk |
PYTHON • Tune C and gamma together with GridSearchCV from sklearn.model_selection import GridSearchCV, StratifiedKFold |
| SEARCH DESIGN Logarithmic grids such as 0.01, 0.1, 1, 10, and 100 are often more informative than dense linear grids because useful C and gamma values may differ by orders of magnitude. |
18.4.4 Reading a validation surface
When many C-gamma combinations are evaluated, think of validation performance as a surface over the two hyperparameters. A broad plateau of similarly strong scores is often preferable to a single isolated peak because it suggests the model is not excessively sensitive to a tiny parameter change. The final selection should also consider training time, support-vector count, and the stability of performance across folds.
If the best score lies at the extreme edge of the search grid, expand the grid in that direction. If many neighboring settings perform similarly, choose a simpler or more regularized point within the plateau unless there is a clear reason to prefer the most complex setting.
18.5 Practical considerations
SVMs have strong predictive properties, but they are less forgiving of careless preprocessing than tree models. Scaling, dataset size, kernel choice, and probability requirements should be considered before training. A carefully constructed pipeline is particularly important because the scaler must be fitted using training data only.
18.5.1 Need for scaling
SVMs depend on inner products and distances. A feature with a much larger numerical scale can dominate these calculations even when it is not more informative. Standardization gives each numeric feature a comparable scale by centering it around zero and dividing by its training-set standard deviation.
Scaling must be learned from the training data. Fitting a scaler on the entire dataset before the train/test split leaks information about the test distribution into training. A scikit-learn Pipeline solves this problem by fitting the scaler separately inside each training fold during cross-validation and applying the learned transformation to validation or test observations.
PYTHON • Use a Pipeline so scaling stays leakage-safe from sklearn.pipeline import Pipeline |
| COMMON MISTAKE Do not call scaler.fit_transform(X) before splitting the data. Put StandardScaler in a Pipeline and evaluate the whole pipeline. |
18.5.2 Computational cost
Kernel SVC training relies on pairwise relationships between observations and can become expensive as the number of training samples grows. Memory use and training time can rise rapidly on large datasets. Prediction time for nonlinear SVC also depends on the number of retained support vectors because the kernel must be evaluated against those vectors.
For a medium-sized tabular dataset, SVC can be entirely practical and may deliver excellent accuracy. For very large datasets, a linear approximation, LinearSVC, SGDClassifier, tree-based method, or another scalable estimator may be more appropriate. The correct choice depends on sample count, feature count, sparsity, latency requirements, and available hardware.
Table 18.7. Practical model choice by scale
| Situation | Possible starting point | Reason |
|---|---|---|
| Moderate samples, nonlinear structure | RBF SVC | Flexible nonlinear boundary |
| Many features, approximately linear | Linear SVC / LinearSVC | Simpler geometry and lower prediction cost |
| Very large sample count | LinearSVC, SGD, scalable tree methods | Kernel SVC training may be expensive |
| Need strong nonlinear tabular baseline | RBF SVC plus scaling | Useful reference when dataset size is manageable |
18.5.3 Suitability for medium-sized datasets
SVC is especially attractive when the dataset is large enough to learn a meaningful boundary but still small enough that kernel training is manageable. It is also effective in high-dimensional spaces, provided regularization and kernel parameters are selected carefully. This makes SVMs common in classical machine-learning applications with engineered numeric features, scientific measurements, and moderately sized datasets.
There is no universal row-count threshold separating medium and large datasets because computational cost depends on feature count, separability, hyperparameter search, class structure, and hardware. Treat timing as an empirical property: measure fit time during cross-validation and compare it with project constraints.
18.5.4 Probability estimation
The native output of an SVC is a decision score, not a class probability. The decision_function method reports signed distance-like scores relative to the learned boundary. These scores are sufficient for ranking and can be used directly for metrics such as ROC AUC in binary classification.
If calibrated-like class probabilities are required, SVC can be created with probability=True. This enables predict_proba but adds additional training work because probability parameters are estimated using internal cross-validation. The fitted probabilities can also differ from the ordering implied by the raw decision scores in some cases.
PYTHON • Enable probability estimates only when the application needs them from sklearn.pipeline import Pipeline |
| EFFICIENCY RULE If the task only needs labels or ranking scores, keep probability=False and use predict or decision_function. Enable probability estimation when downstream decisions genuinely require probabilities. |
18.5.5 Class imbalance and evaluation metrics
Accuracy alone can be misleading when one class is much more frequent than the other. SVC supports class_weight="balanced", which increases the effective penalty for minority-class errors according to class frequencies. Whether class weighting is beneficial should still be validated using metrics aligned with the problem, such as recall, precision, F1, ROC AUC, or precision-recall AUC.
PYTHON • Add balanced class weighting when justified by the task balanced_rbf = Pipeline([ |
| METRIC DISCIPLINE Class weighting changes the learning objective; it is not automatically an improvement. Select it because it improves the metrics and error types that matter for the application. |
18.5.6 Strengths and limitations
Table 18.8. Practical strengths and limitations of SVM classification
| Strengths | Limitations |
|---|---|
| Maximum-margin principle can generalize strongly | Kernel training can be expensive on large sample counts |
| Effective in high-dimensional feature spaces | Sensitive to feature scaling |
| RBF kernel models nonlinear boundaries without explicit feature engineering | C and gamma require careful tuning |
| Only support vectors determine kernel decision function | Nonlinear models are less directly interpretable |
| Decision scores support ranking metrics | Probability estimation adds training cost |
Practical lab — Comparing linear and RBF support vector classifiers
In this lab, students compare two SVM classifiers under one controlled experimental protocol. Both models use the same Breast Cancer Wisconsin diagnostic dataset, the same stratified train/test split, the same StandardScaler preprocessing, and the same evaluation metrics. The only major modeling difference is the kernel: one model uses a linear kernel and the other uses the RBF kernel.
| LAB OBJECTIVE Determine whether the additional nonlinear flexibility of the RBF kernel produces a meaningful improvement over a linear support vector classifier on the same standardized data. |
Lab 18.A — Experimental protocol
1. Load the Breast Cancer Wisconsin dataset from scikit-learn as a pandas DataFrame.
2. Separate the feature matrix X from the target y.
3. Create one stratified 75% training / 25% test split with random_state=42.
4. Build two Pipelines: StandardScaler + linear SVC and StandardScaler + RBF SVC.
5. Fit both pipelines using only the training set.
6. Evaluate accuracy, precision, recall, F1, and ROC AUC on the untouched test set.
7. Inspect the support-vector count for each model.
8. Compare results before performing any hyperparameter tuning.
9. Tune C and gamma only on the training data using cross-validation.
10. Evaluate the selected model once on the final test set and document the conclusion.
Lab 18.B — Load and split the dataset
PYTHON • Create a protected stratified holdout set import pandas as pd |
| CHECKPOINT After this cell runs, do not use X_test or y_test to choose C, gamma, kernel type, or preprocessing. The test set represents the final unseen evaluation. |
Lab 18.C — Build the two models
PYTHON • Define linear and RBF SVC pipelines from sklearn.pipeline import Pipeline |
Both models contain exactly the same scaling step. This is important: the comparison should measure the effect of the kernel rather than accidentally giving one model different preprocessing. The pipelines also guarantee that the scaler will be fitted only on the training data.
Lab 18.D — Evaluate both models
PYTHON • Compute comparable classification metrics from sklearn.metrics import ( |
Table 18.9. Reference output for the fixed split used in this chapter
| Model | Accuracy | Precision | Recall | F1 | ROC AUC | Support vectors |
|---|---|---|---|---|---|---|
| Linear SVC | 0.986 | 0.989 | 0.989 | 0.989 | 0.997 | 34 |
| RBF SVC | 0.979 | 0.989 | 0.978 | 0.983 | 0.997 | 96 |
| REPRODUCIBILITY NOTE These reference values correspond to the code, dataset version, split seed, and library behavior used to prepare this chapter. Small differences can occur across software versions. The lesson is the comparison process, not memorization of a particular score. |
On this particular split, both models perform strongly and the linear model slightly exceeds the default RBF model on several metrics while using fewer support vectors. This is a useful result pedagogically: a nonlinear kernel is not automatically better. Additional flexibility is valuable only when the data support it.
Lab 18.E — Inspect confusion matrices
PYTHON • Compare error patterns instead of accuracy alone from sklearn.metrics import ConfusionMatrixDisplay |
Students should identify which class receives false negatives and which receives false positives. In a real application, these error types rarely have identical consequences. The preferred model may therefore depend on recall or precision rather than on the highest overall accuracy.
Lab 18.F — Cross-validate the two kernels
PYTHON • Compare kernels across several folds from sklearn.model_selection import StratifiedKFold, cross_validate |
| WHY THIS STEP MATTERS A single test split is one sample of possible future data. Cross-validation on the training set helps determine whether a model advantage is stable across different validation folds. |
Lab 18.G — Tune the RBF model
PYTHON • Search C and gamma without touching the test set from sklearn.model_selection import GridSearchCV |
After tuning, students should evaluate search.best_estimator_ once on X_test. If the tuned RBF model does not meaningfully outperform the simpler linear model, the linear model remains a strong choice. Model selection should reward reproducible improvement rather than complexity.
Lab 18.H — Final evaluation of the selected RBF model
PYTHON • Evaluate the selected model once on the final test set best_rbf = search.best_estimator_ |
Lab 18.I — Optional two-dimensional boundary experiment
The Breast Cancer dataset contains many features, so its full decision boundary cannot be drawn directly in two dimensions. For geometric intuition, students can create a separate synthetic two-feature dataset and compare the boundary produced by a linear and an RBF SVC. This experiment is for visualization only; it is not a substitute for the quantitative lab above.
PYTHON • Visualize linear and RBF boundaries on a two-feature dataset import numpy as np |
| OBSERVATION TASK Explain why one straight line cannot naturally follow the crescent-shaped class structure, while the RBF kernel can create a curved boundary. Then identify how changing gamma would alter the smoothness of that boundary. |
Lab 18.J — Student questions
1. Why is StandardScaler included before both SVC models?
2. What is the geometric meaning of a support vector?
3. Why does a smaller C correspond to stronger regularization?
4. What happens to an RBF boundary when gamma becomes very large?
5. Why should C and gamma be tuned together?
6. Why might a linear SVC outperform a default RBF SVC?
7. Why is decision_function sufficient for ROC AUC even when probability=False?
8. What additional cost is introduced by probability=True?
9. How would you decide whether class_weight="balanced" is appropriate?
10. Why must the final test set remain untouched during GridSearchCV?
Lab 18.K — Deliverable
- A table comparing test accuracy, precision, recall, F1, ROC AUC, and support-vector count for the untuned linear and RBF SVC models.
- A short interpretation of which model is preferred before tuning and why.
- The best C and gamma found by training-set cross-validation for the RBF model.
- A final test-set evaluation of the selected tuned model.
- One paragraph explaining whether nonlinear flexibility produced a meaningful improvement.
- A brief discussion of scaling, computational cost, and probability estimation for the chosen deployment scenario.
Chapter summary
- Support Vector Machines construct decision boundaries using a maximum-margin principle.
- A separating hyperplane divides the feature space; support vectors are the critical observations that determine the fitted boundary.
- Hard-margin classification forbids violations and is mainly conceptual for perfectly separable data.
- Soft-margin classification permits violations and uses C to balance margin simplicity against training errors.
- Smaller C means stronger regularization and greater tolerance for violations; larger C means weaker regularization and stronger pressure to fit difficult observations.
- Kernel methods allow nonlinear boundaries by replacing ordinary inner products with similarity functions in an implicit transformed feature space.
- The linear kernel is a strong reference when the problem is approximately linear or high-dimensional.
- The RBF kernel is a flexible nonlinear choice controlled mainly by C and gamma.
- Small gamma produces broad, smooth influence; large gamma creates more local and potentially irregular boundaries.
- C and gamma interact and should normally be tuned together using cross-validation.
- SVMs require careful feature scaling because distances and inner products depend directly on numerical feature magnitude.
- Kernel SVC is well suited to many medium-sized datasets but can become computationally expensive as training size grows.
- SVC decision scores are available by default; probability estimation requires probability=True and introduces additional training cost.
- A nonlinear kernel should be selected because it improves validated performance, not because it is more sophisticated.
| TAKE-AWAY Use a leakage-safe scaling pipeline, establish a linear SVC baseline, compare it with a carefully tuned RBF SVC, and select the simplest model that gives reproducibly strong performance under the metrics that matter. |
Review checklist
| Can you explain or do this? | Self-check |
|---|---|
| Draw and label a separating hyperplane, margin, and support vectors. | □ |
| Explain the difference between hard-margin and soft-margin classification. | □ |
| Predict the effect of increasing or decreasing C. | □ |
| Explain why smaller C means stronger regularization. | □ |
| Compare linear, polynomial, and RBF kernels. | □ |
| Explain the kernel trick without explicitly constructing transformed features. | □ |
| Predict the effect of a very small or very large gamma. | □ |
| Explain why C and gamma interact. | □ |
| Build StandardScaler + SVC inside a Pipeline. | □ |
| Use decision_function for ranking metrics such as ROC AUC. | □ |
| Explain why probability=True increases fitting cost. | □ |
| Tune C and gamma with cross-validation while protecting the final test set. | □ |