
By the end of this lesson, you should be able to:
Scope of this lesson
This lesson studies hard-margin SVM only. We assume that the training data is linearly separable. Slack variables, the penalty parameter , hinge-loss optimization, and soft-margin SVM are intentionally reserved for the next lesson.
Consider an automated quality-control system that classifies manufactured parts from two measurements:
Each part is represented by a feature vector:
The label is:
A small teaching dataset is:
| Surface-defect score | Dimension deviation | Label |
|---|---|---|
| 0.0 | 0.0 | -1 |
| 1.0 | 0.0 | -1 |
| 0.0 | 1.0 | -1 |
| 0.4 | 0.4 | -1 |
| 3.0 | 2.0 | +1 |
| 4.0 | 2.0 | +1 |
| 3.0 | 3.0 | +1 |
| 4.0 | 3.0 | +1 |
The two classes can be separated by a straight line. That sounds like a problem the Perceptron has already solved.
The Perceptron searches for parameters and that make every training example land on the correct side of:
If the data is linearly separable, the Perceptron eventually finds a separating boundary. Its convergence theorem does not say that the boundary is unique, centered between the classes, or stable under small changes in the inputs.
Logistic Regression addressed a different weakness. It kept the same linear score,
but transformed that score into an estimated probability through the sigmoid function. This made the output more interpretable for ranking risk and selecting decision thresholds.
However, Logistic Regression optimizes log loss. It does not explicitly ask:
Among all lines that separate the training examples, which line leaves the largest geometric safety gap?
That is the question hard-margin Support Vector Machines answer.

Diagram teaching notes
What appears: The same separable dataset with three different linear boundaries.
What to notice: Every line classifies the displayed training observations correctly, but the two outer lines pass very close to one class.
What to explain: Correctness is a feasibility condition, not yet a rule for choosing the best feasible boundary.
Connection: The next step is to replace “find any separator” with a measurable preference for one separator.
A model classifies every training example correctly. Does that prove the boundary is the most robust separating boundary?
No. It only proves that the boundary is feasible. Another feasible boundary may leave a larger gap between the classes.
Hard-margin SVM is not a completely different kind of predictor. It begins with the same linear decision function:
where:
The predicted class is:
Thus:
produces class , while:
produces class .
The decision boundary is the set of inputs for which:
In two dimensions, this is a line. In three dimensions, it is a plane. In higher dimensions, it is a hyperplane.
The vector is perpendicular to the decision boundary. It is therefore called a normal vector to the hyperplane.
That last point will become essential.
Suppose:
The boundary is:
Now multiply both parameters by :
The new equation is:
Dividing by gives the original line. The geometry has not changed.
Logistic Regression interprets:
as an estimated probability under a probabilistic model.
Hard-margin SVM does not apply the sigmoid and does not fit a probability model. It uses the geometry of the score relative to the separating boundary.
A probability and a geometric distance answer different questions:
Common mistake — “Logistic Regression already chooses the best boundary.”
Logistic Regression chooses parameters that reduce log loss. Hard-margin SVM chooses parameters that maximize the smallest geometric distance from the training data to the boundary. The objectives are different, so their fitted boundaries need not be the same.
Common mistake — “A probability of 0.9 means the point is 0.9 units from the boundary.”
Probability and geometric distance use different scales and different mathematical meanings. Neither can be substituted for the other.
For the quality-control data, consider boundaries of the form:
The acceptable parts satisfy:
for the closest displayed acceptable observations, while the closest reject observation satisfies:
Therefore, any value:
creates a valid separating boundary.
Three possibilities are:
All three classify the training examples correctly.
The first line passes only a short distance from the acceptable class. The third line passes only a short distance from the reject class. The middle line is centered between the closest observations from the two classes.
Suppose an acceptable part lies close to a boundary. A small amount of sensor noise could move its measured position across the line, changing the prediction even though the underlying part has not meaningfully changed.
A boundary with more empty space around it can tolerate a larger perturbation before the prediction flips.
This motivates a stronger objective:
Do not merely separate the training examples. Choose the separating hyperplane whose nearest training observation is as far away as possible.
This empty region is the margin.
A wider training margin provides a geometric form of robustness. If a training point is a distance from the boundary, any perturbation shorter than cannot cross the boundary when measured in the same feature-space geometry.
This does not guarantee that:
The margin gives a principled boundary-selection rule. It is not a universal guarantee of good predictions.
Why not choose the boundary that is farthest from the positive class only?
Because doing so could place the boundary extremely close to the negative class. The relevant quantity is the distance to the closest observation from either class.
To maximize separation, we need to measure distance. The raw score:
is not yet a geometric distance because its magnitude changes when and are rescaled.
Take the boundary:
and the point:
Using:
the score is:
Using the equivalent parameters:
the score is:
The physical point and the geometric boundary are unchanged, so the distance cannot have changed from units to units. We need a normalization that removes this arbitrary scaling.

Diagram teaching notes
What appears: One point and one boundary described by two different parameter pairs.
What to notice: The raw score changes by a factor of five, but the normalized distance does not change.
What to explain: A valid geometric quantity must be invariant to equivalent parameter scaling.
Connection: This motivates dividing the score by .
Let the hyperplane be:
For a point , the shortest path to the hyperplane must be perpendicular to the hyperplane. Because is normal to the hyperplane, the closest point must lie somewhere along the direction of .
Write:
where tells us how far to move in the normal direction.
Because lies on the boundary:
Substitute :
Distribute :
Since:
we have:
Solving for :
The displacement from to is:
Its length is:
Substitute the expression for :
Therefore:

Diagram teaching notes
What appears: A point, its perpendicular projection onto the boundary, and the normal direction .
What to notice: The shortest segment is parallel to , not parallel to either coordinate axis.
What to explain: The numerator gives a signed algebraic score; the denominator converts it into geometric units.
Connection: The next section adds the class label so that “correct side” and “incorrect side” are handled in one expression.
For:
the score is , and:
Therefore:
Using and :
The distance is unchanged, as required.
Common mistake — “A larger raw score always means a larger geometric distance.”
For one fixed fitted model, score magnitude and distance are proportional because is fixed. Across different parameter scalings or different models, raw scores cannot be compared as distances unless they are normalized by .
The distance formula uses an absolute value, but classification also requires the side of the boundary.
For a labeled example , define the functional margin:
where .
If , correct classification requires:
Multiplying by keeps the value positive.
If , correct classification requires:
Multiplying by makes the result positive.
Therefore:
means the example is on the correct side, while:
means it is on the wrong side.
The functional margin combines both label cases into one expression.
If and are multiplied by , the functional margin is also multiplied by , even though the boundary does not move.
The geometric margin of example is therefore:
This is a signed distance measured toward the example's correct class side.
For a separating boundary, every training example has a positive geometric margin.
A boundary is only as safe as its closest training example. The margin of the dataset with respect to is:
where:
Hard-margin SVM seeks the boundary that maximizes this minimum distance.
Common mistake — “The average distance should be maximized.”
A large average could hide one observation that is almost touching the boundary. The minimum distance directly controls the narrowest part of the safety gap.
Common mistake — “SVM distance is a probability-like confidence score.”
The geometric margin is measured in the geometry of the feature space. It is not constrained to , does not sum across classes, and is not automatically calibrated as a probability.
We can now write the boundary-selection goal directly:
subject to every example being correctly classified.
This expression captures the right idea, but it is inconvenient to optimize because:
The next step uses the scaling freedom deliberately.
For any separating hyperplane, all functional margins are positive. Because multiplying by a positive constant leaves the boundary unchanged, we may choose a scale at which the smallest functional margin is exactly :
This convention is called canonical scaling.
Under this scale, every training example satisfies:
At least one observation satisfies equality.
Now the dataset's geometric margin becomes:
Because the minimum numerator is :
Therefore maximizing the margin is equivalent to minimizing .
Instead of minimizing:
we minimize:
This produces the same optimal because squaring is monotone for nonnegative values. The square is smoother and easier to differentiate. The factor cancels the that appears when differentiating the squared norm:
The factor does not change the location of the optimum.
The complete optimization problem is:
Every component has a distinct role.
Minimizing the norm makes:
as large as possible. This widens the distance from the decision boundary to the closest training observations.
The constraints require every training example to:
For :
For :
The two margin hyperplanes are therefore:
and:
The decision boundary lies halfway between them:

Diagram teaching notes
What appears: The decision boundary, the two canonical margin hyperplanes, the margin band, and circled closest observations.
What to notice: No training point lies inside the band. The closest points touch its edges.
What to explain: The constraints define feasibility; the norm objective widens the band while preserving feasibility.
Connection: The touching observations will be named support vectors because they support the optimal band.
The distance from the decision boundary:
to either margin hyperplane is:
The distance from the negative margin hyperplane to the positive margin hyperplane is:
Both quantities are called “the margin” in different explanations.
This lesson uses:
Always check which convention is being used.
Suppose we minimized only:
without classification constraints. The smallest possible norm would be obtained by:
That does not define a useful separating boundary.
The objective alone prefers a small weight vector. The constraints force the small-norm solution to remain a valid separator.
Hard-margin SVM is not “minimize the weights” by itself. It is:
Find the smallest-norm weight vector among all parameter choices that keep every training observation on the correct side of the margin.
Return to the quality-control dataset.
The closest acceptable observations lie on:
The closest reject observation is:
which lies on:
The line centered between these two parallel lines is:
Written as a decision function:
This boundary is geometrically correct, but it is not yet in canonical scale. We need the closest positive example to have score and the closest negative examples to have score .
Choose:
Then:
The decision boundary is still:
Multiplying by gives , so the same line is represented.
For:
the score is:
The functional margin is:
The constraint is active exactly at equality.
For:
the same calculation gives a functional margin of .
For:
the score is:
The functional margin is:
This constraint is also active.
For the reject observation:
the score is:
Its functional margin is . It lies beyond the positive margin hyperplane and is not one of the closest observations.
The constraint table is:
| Point | Label | Score | Functional margin | Constraint status |
|---|---|---|---|---|
| -1 | -1 | 1 | Active | |
| -1 | -1 | 1 | Active | |
| +1 | 1 | 1 | Active | |
| +1 | 1.5 | 1.5 | Strictly satisfied | |
| +1 | 2 | 2 | Strictly satisfied |
The norm of is:
The distance from the boundary to the nearest training observation is:
The full margin width is:
The optimization objective at this solution is:
For a line:
the distance from a point with coordinate sum is:
For :
For :
For :
The centered boundary maximizes the minimum distance.
Consider:
The raw score is:
Because the score is positive:
The part is predicted to be rejected.
Its signed geometric distance is:
This is a distance in the chosen feature space, not a probability.
Common mistake — “Every future observation must be outside the margin.”
The hard-margin constraints apply to the training observations used to fit the model. A new observation can fall inside the margin band and still receive a class prediction based on the sign of its score.
The Perceptron learns through local mistake-driven updates. Hard-margin SVM is defined differently: it solves a constrained optimization problem over the complete training dataset.
The objective:
is quadratic in .
Each constraint:
is linear in the parameters and .
An optimization problem with a quadratic objective and linear constraints is a quadratic program.
There are two simultaneous goals:
Neither goal can replace the other.
The squared norm is a convex function. The feasible region defined by linear inequalities is also convex.
This matters because a convex optimization problem has no inferior local minima. If a numerical solver converges to an optimum that satisfies the constraints, it has reached a global optimum of the stated hard-margin problem.
The optimal weight vector is unique because the objective is strictly convex in . In unusual degenerate configurations, more than one bias value may describe the same optimal orientation while satisfying the constraints, although typical datasets pin down through support vectors from both classes.
Convexity does not guarantee strong performance on unseen data. It guarantees that the mathematical training problem is solved globally.
A practical quadratic-programming or SVM solver conceptually performs the following work:
Libraries often use specialized decomposition or coordinate-optimization methods rather than a simple full-batch gradient descent loop. Therefore, “one epoch” is not the defining unit of hard-margin SVM learning.
Input:
linearly separable training examples (x_i, y_i)
labels y_i in {-1, +1}
1. Place features on meaningful, comparable scales.
2. Define the optimization problem:
minimize (1/2) * ||w||^2
subject to y_i * (w^T x_i + b) >= 1
for every training example i
3. Solve the constrained convex quadratic program.
4. Identify training examples satisfying:
y_i * (w^T x_i + b) = 1
These are the support vectors.
5. For a new input x:
score = w^T x + b
predict +1 if score > 0
predict -1 if score < 0
6. When a geometric distance is needed:
distance = score / ||w||
Hard-margin SVM does not repeatedly repair only the latest mistake. It selects parameters by optimizing a global geometric objective under constraints from every training example.
At the optimum, some observations satisfy:
These points lie exactly on one of the margin hyperplanes. They are called support vectors.
The name is geometric: these observations support the widest feasible margin band. If the band expanded any farther without rotating or shifting appropriately, it would run into one of them.
Observations satisfying:
lie beyond the margin. They are correctly classified with extra geometric room.
Imagine moving a training observation that lies far beyond the margin. If it remains correctly classified and does not become one of the closest points, the current optimum still satisfies its constraint. The observation does not tighten the feasible region near the optimum, so the boundary may remain unchanged.
A support vector is part of the closest geometry between the two classes. Moving it can:
The boundary does not have to change after every support-vector movement in every symmetric or redundant configuration, but support vectors are the observations with direct potential to determine the optimum.

Diagram teaching notes
What appears: One scene moves a non-support observation; another moves a support vector.
What to notice: The first movement leaves the closest class geometry unchanged, while the second changes it.
What to explain: Constraints that are loose at the optimum exert no immediate pressure; active constraints define the edge of feasibility.
Connection: Lagrange multipliers provide the mathematical version of this “pressure” interpretation.
Common mistake — “All training observations contribute equally.”
All observations create constraints, but only active constraints directly hold the optimal margin in place. Non-support observations can matter if they move far enough to become active.
Common mistake — “The boundary changes whenever any training point moves.”
A small movement of a non-support observation may leave the solution exactly unchanged. The important question is whether the closest class geometry or active constraints change.
The primal formulation already defines hard-margin SVM:
A deeper question remains:
Can we show mathematically that the final weight vector is built from the observations that press against the margin?
Lagrange multipliers answer this question.
Write each constraint as:
Associate a nonnegative multiplier with it.
Intuitively, measures how strongly the -th constraint participates in holding the optimum in place.
The Lagrangian is:
The first term is the margin objective. The second term incorporates the constraints.
At the optimum, differentiate with respect to and set the result to zero:
Therefore:
This equation says that the final normal vector is a weighted combination of training observations.
Differentiate with respect to :
Therefore:
The weighted influence of the positive and negative classes must balance in this sense.
A key optimality condition is:
This product can be zero in two main ways.
If:
then:
For the product to be zero:
That observation disappears from the weighted expression for .
If:
then complementary slackness requires:
so:
The observation lies on a margin hyperplane and is a support vector.
This is the mathematical reason only a subset of observations directly determines .
Substituting the stationarity conditions into the Lagrangian gives the dual form:
Every symbol has already appeared:
The dual is not required to make predictions with a linear hard-margin SVM. Its main teaching value here is that it exposes two important facts:
The second fact will become important when nonlinear SVMs are introduced later. No nonlinear transformation is needed for the current hard-margin linear lesson.
If a training observation satisfies , what does complementary slackness imply about its multiplier?
Because the constraint is strictly satisfied, . It is not an active support vector.
Hard-margin SVM requires a feasible separator satisfying:
for every training observation after an appropriate positive rescaling of the parameters.
This is possible exactly when the training data is linearly separable in the chosen feature representation.
Hard-margin SVM is most appropriate when:
When the constraints are feasible, the hard-margin problem finds a global maximum-margin linear separator.
More precisely, it finds a feasible hyperplane that maximizes:
This gives a principled answer to the non-uniqueness problem left by the Perceptron.
The maximum training margin does not guarantee:
The guarantee is about the stated optimization problem, not every property desired from a deployed classifier.
Real datasets may contain overlap, measurement noise, or incorrect labels. A single negative-labeled observation placed inside the positive region can make perfect linear separation impossible.

Diagram teaching notes
What appears: A previously separable dataset with one conflicting acceptable label inside the reject cluster.
What to notice: No straight line can place all positive examples on one side and all negative examples on the other.
What to explain: Hard-margin SVM does not trade margin against mistakes; it declares this set of constraints infeasible.
Connection: The next SVM extension will relax the perfect-separation requirement, but that extension is outside the current lesson.
Common mistake — “A wider margin always means zero training errors.”
In hard-margin SVM, zero training errors are required before the margin is optimized. A wide margin does not cause the zero-error condition; the constraints enforce it.
Common mistake — “Increase to make hard-margin SVM better.”
The mathematical hard-margin formulation has no penalty parameter . belongs to soft-margin formulations. A library may use a very large to numerically approximate hard-margin behavior on separable data, but increasing it indefinitely is not a general performance guarantee.
The maximum-margin principle solves an important Perceptron limitation, but hard-margin SVM still has boundaries.
The prediction rule remains:
A single linear hyperplane cannot represent patterns such as concentric classes or XOR without changing the feature representation.
Overlap, label noise, and contradictory observations can make the constraints impossible to satisfy.
This is the most immediate practical limitation of hard margin.
Support-vector sparsity is useful, but it also means that unusual closest observations can strongly determine the margin and orientation.
The maximum-margin boundary is optimal for the observed feature-space geometry. If a support vector is a measurement error or unrepresentative outlier, the learned boundary may be undesirable for deployment.
The outputs of:
model.decision_function(X)
are signed scores. After normalization by , they are signed geometric distances in the model's feature space.
Neither output is automatically a class probability.
The SVM objective uses Euclidean length:
and geometric distance in feature space. Changing a feature from meters to millimeters changes the numerical geometry unless preprocessing compensates for it.
A model can run without standardization, but then its margin reflects the arbitrary measurement units. Scaling is therefore usually essential unless the units are intentionally chosen to encode relative importance.
| Hard-margin limitation | Related improvement |
|---|---|
| Cannot learn nonlinear boundaries | Kernel methods or explicit nonlinear features |
| Has no feasible solution on nonseparable data | Soft-margin SVM |
| Can be dominated by extreme support observations | Soft-margin and robust data-validation practices |
| Does not produce probabilities | Probability calibration or a probabilistic classifier such as Logistic Regression |
| Is sensitive to feature scale | Standardization inside the training pipeline |
The next lesson should begin with the second row: how to preserve the maximum-margin idea when perfect separation is unrealistic.
All three methods can use the same linear score:
Their central difference is not the prediction formula. It is what they optimize and how they interpret the output.
| Property | Perceptron | Logistic Regression | Hard-Margin SVM |
|---|---|---|---|
| Boundary shape | Linear | Linear | Linear |
| Main training goal | Find a separator through mistake-driven updates | Minimize probabilistic log loss | Maximize the minimum geometric margin |
| Requirement of perfect separability | Needed for convergence guarantee | Not required for fitting a regularized model | Required for feasibility |
| Output used for prediction | Sign of raw score | Probability threshold | Sign of raw score |
| Probability model | No | Yes | No |
| Confidence interpretation | Raw score only; not probability | Estimated probability | Geometric margin after normalization |
| Which observations influence fitting? | Mistakes encountered during training | Generally all observations contribute to loss | Support vectors determine the final boundary directly |
| Boundary-selection principle | Any separator may be found | Best log-loss parameters | Widest feasible separator |
| Sensitivity to feature scale | Yes | Important for optimization and regularization | Fundamental to margin geometry |
Suppose two models place an observation on the positive side.
Logistic Regression may report:
Hard-margin SVM may report a signed geometric distance of:
These values are not competing estimates of the same quantity.
It can, but it is not guaranteed. The two methods solve different objectives.
On some symmetric datasets, their decision boundaries may look nearly identical. On other datasets, especially when observations are distributed unevenly away from the class frontier, the boundaries can differ because Logistic Regression continues to account for all observations through log loss while hard-margin SVM is determined by its support vectors.
scikit-learn's SVC implements -Support Vector Classification. It does not expose a separate “infinite-” hard-margin estimator.
For a clean, linearly separable teaching dataset, a very large value of C can approximate the hard-margin solution. This is an implementation device, not a new theoretical component of the hard-margin formulation.
The workflow below:
Pipeline,from __future__ import annotations
import numpy as np
import pandas as pd
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
RANDOM_STATE = 42
TEST_SIZE = 0.25
HARD_MARGIN_APPROXIMATION_C = 1_000_000.0
FEATURE_COLUMNS = [
"surface_defect_score",
"dimension_deviation",
]
ACCEPT_LABEL = -1
REJECT_LABEL = 1
def create_dataset() -> tuple[pd.DataFrame, pd.Series]:
"""Create a small, linearly separable quality-control dataset."""
rows = [
# Acceptable parts (-1)
(0.0, 0.0, ACCEPT_LABEL),
(1.0, 0.0, ACCEPT_LABEL),
(0.0, 1.0, ACCEPT_LABEL),
(0.4, 0.4, ACCEPT_LABEL),
(0.8, 0.2, ACCEPT_LABEL),
(0.2, 0.8, ACCEPT_LABEL),
(1.1, 0.3, ACCEPT_LABEL),
(0.3, 1.1, ACCEPT_LABEL),
(0.8, 0.8, ACCEPT_LABEL),
(1.2, 0.5, ACCEPT_LABEL),
(0.5, 1.2, ACCEPT_LABEL),
(1.0, 1.0, ACCEPT_LABEL),
# Reject parts (+1)
(3.0, 2.2, REJECT_LABEL),
(3.2, 2.4, REJECT_LABEL),
(3.5, 2.0, REJECT_LABEL),
(3.0, 3.0, REJECT_LABEL),
(4.0, 2.2, REJECT_LABEL),
(3.8, 3.0, REJECT_LABEL),
(4.2, 2.8, REJECT_LABEL),
(3.6, 3.6, REJECT_LABEL),
(4.5, 3.2, REJECT_LABEL),
(3.2, 3.8, REJECT_LABEL),
(4.0, 4.0, REJECT_LABEL),
(4.6, 3.8, REJECT_LABEL),
]
frame = pd.DataFrame(
rows,
columns=[*FEATURE_COLUMNS, "quality_label"],
)
X = frame[FEATURE_COLUMNS].copy()
y = frame["quality_label"].copy()
return X, y
def build_model() -> Pipeline:
"""Build a leakage-safe scaling and linear-SVM pipeline."""
return Pipeline(
steps=[
("scaler", StandardScaler()),
(
"classifier",
SVC(
kernel="linear",
C=HARD_MARGIN_APPROXIMATION_C,
probability=False,
),
),
]
)
def signed_geometric_distance(
model: Pipeline,
X: pd.DataFrame,
) -> np.ndarray:
"""Return signed distance to the learned boundary in scaled space."""
scaler: StandardScaler = model.named_steps["scaler"]
classifier: SVC = model.named_steps["classifier"]
X_scaled = scaler.transform(X)
raw_scores = classifier.decision_function(X_scaled)
weight_norm = np.linalg.norm(classifier.coef_.ravel())
if weight_norm == 0:
raise ValueError("The learned weight vector has zero norm.")
return raw_scores / weight_norm
def main() -> None:
X, y = create_dataset()
X_train, X_test, y_train, y_test = train_test_split(
X,
y,
test_size=TEST_SIZE,
random_state=RANDOM_STATE,
stratify=y,
)
model = build_model()
model.fit(X_train, y_train)
train_predictions = model.predict(X_train)
test_predictions = model.predict(X_test)
print(
"Training accuracy:",
f"{accuracy_score(y_train, train_predictions):.3f}",
)
print(
"Test accuracy:",
f"{accuracy_score(y_test, test_predictions):.3f}",
)
classifier: SVC = model.named_steps["classifier"]
weight_norm = np.linalg.norm(classifier.coef_.ravel())
margin_to_boundary = 1.0 / weight_norm
full_margin_width = 2.0 / weight_norm
print("Number of support vectors:", classifier.n_support_.sum())
print("Margin to nearest support hyperplane:", f"{margin_to_boundary:.3f}")
print("Full margin width:", f"{full_margin_width:.3f}")
support_positions = classifier.support_
support_rows = X_train.iloc[support_positions].copy()
support_rows["label"] = y_train.iloc[support_positions].to_numpy()
print("\nSupport-vector training rows:")
print(support_rows.to_string(index=False))
new_part = pd.DataFrame(
[
{
"surface_defect_score": 3.4,
"dimension_deviation": 2.5,
}
]
)
raw_score = float(model.decision_function(new_part)[0])
distance = float(signed_geometric_distance(model, new_part)[0])
prediction = int(model.predict(new_part)[0])
print("\nNew part:")
print(f"Raw decision score: {raw_score:.3f}")
print(f"Signed geometric distance: {distance:.3f}")
print(
"Prediction:",
"Reject" if prediction == REJECT_LABEL else "Accept",
)
if __name__ == "__main__":
main()
The correct order is:
Placing StandardScaler inside Pipeline makes this workflow automatic. Test-set statistics are not used to fit the scaler.
The classifier is trained in standardized feature space. Its coef_ and decision_function() therefore describe that space.
The normalized quantity:
is a geometric distance in standardized units.
It is not the same as a distance measured directly in the original raw measurement units.
For SVC, the attribute:
classifier.support_
contains the positions of the training observations selected as support vectors.
The attribute:
classifier.n_support_
reports how many support vectors belong to each class.
For a linear kernel:
classifier.coef_
contains the learned weight vector.
probability=FalseHard-margin SVM does not intrinsically produce probabilities.
Enabling probability estimation in SVC adds a separate calibration procedure. That output should not be presented as part of the hard-margin derivation.
One run of the included script produced:
Training accuracy: 1.000
Test accuracy: 1.000
Number of support vectors: 2
Margin to nearest support hyperplane: 0.781
Full margin width: 1.562
Support-vector training rows:
surface_defect_score dimension_deviation label
1.0 1.0 -1
3.0 2.2 1
New part:
Raw decision score: 1.436
Signed geometric distance: 1.121
Prediction: Reject
The perfect accuracy on this small synthetic split is expected because the data was deliberately constructed to be easy and separable. It is not evidence of real-world model quality.
| Mathematical concept | Code | Interpretation |
|---|---|---|
| Feature vector | One row of X |
One manufactured part |
| Label | quality_label |
Accept or reject |
| Feature scaling | StandardScaler() |
Defines a comparable standardized geometry |
| Train/test separation | train_test_split() |
Keeps evaluation data outside fitting |
| Linear SVM | SVC(kernel="linear", ...) |
Learns a linear hyperplane |
| Approximate hard-margin behavior | Very large C on separable data |
Numerical implementation choice |
| Fit parameters | model.fit() |
Solves the library's SVM optimization |
| Class prediction | model.predict() |
Sign-based label |
| Raw score | decision_function() |
Signed unnormalized decision score |
| Weight vector | classifier.coef_ |
Normal to the boundary in scaled space |
| Support-vector positions | classifier.support_ |
Training rows active at the margin |
| Margin to one side | 1 / np.linalg.norm(coef_) |
|
| Full margin width | 2 / np.linalg.norm(coef_) |
|
| Signed geometric distance | score / np.linalg.norm(coef_) |
Distance in scaled feature space |
| Probability | Not produced | Hard-margin SVM is not probabilistic |
Implementation warning
A very large
Cis safe only as a teaching approximation on clean, separable data. On noisy or nonseparable data, it can create numerical and modeling problems. That behavior belongs to the soft-margin discussion.
Hard-margin SVM uses the same kind of decision boundary as the Perceptron and binary Logistic Regression.
The Perceptron can find any separator. Logistic Regression optimizes probability-based log loss. Neither objective explicitly selects the widest geometric gap among all feasible separators.
Normalization by removes arbitrary parameter scaling.
The label makes positive geometric margin mean “on the correct side” for both classes.
The nearest observations satisfy equality.
Minimizing the norm maximizes the margin while the constraints preserve perfect separation.
Support vectors satisfy:
They are the active observations that hold the maximum-margin solution in place.
Hard-margin SVM requires linearly separable training data. If overlap, noise, or contradictory labels make the constraints infeasible, the method has no solution.
The decision score and normalized distance do not represent .
Real data is rarely perfectly separable. The natural next question is:
How can we preserve the maximum-margin principle while allowing limited margin violations or classification errors?
That question leads to soft-margin SVM.

Active constraint
A constraint that holds with equality at the optimum. For hard-margin SVM, support-vector constraints are active.
Bias
The intercept that shifts the decision boundary without directly changing its normal direction.
Canonical scaling
A parameter scaling in which the smallest training functional margin equals .
Constraint
A requirement that every feasible solution must satisfy. Hard-margin SVM requires .
Convex optimization
Optimization in which the objective and feasible region have geometry that prevents inferior local minima.
Decision boundary
The set of points satisfying .
Dual problem
An alternative optimization formulation expressed through Lagrange multipliers .
Functional margin
The scale-dependent quantity .
Geometric margin
The normalized signed distance .
Hard-margin SVM
A maximum-margin linear classifier that requires every training example to be perfectly separated.
Hyperplane
A linear decision boundary in an arbitrary number of dimensions.
Lagrange multiplier
A nonnegative coefficient associated with a constraint. Nonzero coefficients identify observations that directly influence the SVM solution.
Margin hyperplanes
Under canonical scaling, the parallel hyperplanes and .
Normal vector
A vector perpendicular to the decision boundary.
Quadratic program
An optimization problem with a quadratic objective and linear constraints.
Support vector
A training observation that lies on a margin hyperplane and helps determine the optimal boundary.
Weight vector
The learned coefficients that determine the orientation and feature contributions of the linear decision function.