Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

A support vector machine, or SVM, is a machine learning method that sorts data into groups by drawing the best possible boundary between them. It is useful for classification tasks such as detecting spam, recognizing simple images, or separating medical test results into categories. The main idea is not just to separate the data, but to separate it with the widest safe space between the groups.

This makes the model more likely to work well on new data it has not seen before.

In a 2D picture, an SVM draws a line called a decision boundary between two classes of points. The closest points to that line are called support vectors, and they control where the boundary goes. The distance from the boundary to these closest points is called the margin, and the SVM tries to make this margin as large as possible.

When the data cannot be separated by a straight line, SVMs can use kernels to create curved boundaries in a transformed feature space.

Understanding AI & Machine Learning: Support Vector Machines Explained

During training, an SVM treats every example as a set of measured features. For an email, features might include the number of links, certain word counts, and whether the sender is known. The training process searches for a rule that gives the correct label to as many examples as possible while keeping the separating region stable.

Most training points eventually matter very little. Points far from the dividing region can move slightly without changing the final rule. This is why a small set of difficult examples can have such a large effect on the result.

Real data is rarely perfectly clean. A medical record may have a wrong label. Two customer groups may naturally overlap.

A soft margin SVM allows some training mistakes instead of forcing an impossible perfect split. A setting called C controls the tradeoff. A large C punishes mistakes strongly, so the model tries hard to fit the training data.

A smaller C accepts more mistakes in return for a simpler, wider separation. If C is too large, one unusual point may pull the model too far and reduce its performance on future cases.

Kernels help when the useful pattern is not straight in the original features. Imagine points from one class forming a ring around points from another class. A straight cut cannot separate them.

A kernel measures how similar pairs of examples are, which lets the SVM act as if it had extra features without calculating every extra coordinate directly. The radial basis function kernel is common because it can represent local curved patterns. Its settings need care.

A very flexible kernel can memorize noise. A very stiff kernel can miss a real curved pattern.

Feature scaling matters before using SVMs. A feature measured in thousands can dominate one measured between zero and one unless both are put on comparable scales.

Many school examples show only two groups, but practical tasks often have several. A system sorting handwritten digits must choose among ten labels. One common method trains several two group classifiers and compares their results.

SVM outputs are best understood first as signed scores showing which side an example falls on and how strongly. They are not automatically reliable probabilities. If a task needs a probability, such as estimating risk, extra calibration using separate validation data may be needed.

When studying SVMs, pay attention to the data before focusing on the algorithm. Check whether labels are trustworthy, features are meaningful, and each class has enough examples. An imbalanced dataset can be misleading.

A model that labels nearly everything as the common class can appear accurate while failing on the rare class that matters most. Test data must stay separate from training choices, including scaling and parameter tuning. Useful checks include precision, recall, and a confusion matrix.

These reveal which kinds of mistakes the model makes. SVMs work especially well with clear features and moderate sized datasets, but they can become slow with very large training sets.

Key Facts

  • An SVM classifies data by finding a decision boundary that separates classes.
  • For a line in 2D, a decision boundary can be written as w1x1 + w2x2 + b = 0.
  • The predicted class is often based on the sign of f(x) = w · x + b.
  • The margin is the distance between the decision boundary and the nearest training points.
  • Support vectors are the closest data points to the boundary and have the biggest influence on the model.
  • For linearly separable data, the margin width is 2 / ||w||, so maximizing the margin means minimizing ||w||.

Vocabulary

Support Vector Machine
A machine learning algorithm that finds a boundary with the widest margin to separate data into classes.
Decision Boundary
The line, plane, or surface that a model uses to separate one predicted class from another.
Support Vector
A training data point closest to the decision boundary that helps determine the boundary's position.
Margin
The gap between the decision boundary and the nearest data points from each class.
Kernel
A function that lets an SVM create a nonlinear boundary by comparing data as if it were in a higher-dimensional space.

Common Mistakes to Avoid

  • Choosing the line that merely separates the points, not the one with the widest margin, is wrong because SVMs look for the most confident separation, not just any separation.
  • Thinking every data point controls the boundary is wrong because only the support vectors have the strongest effect on where the boundary is placed.
  • Assuming SVMs can only draw straight lines is wrong because kernels allow SVMs to make curved decision boundaries for nonlinear patterns.
  • Ignoring feature scaling is wrong because SVMs use distances, so features with large numerical ranges can unfairly dominate the model.

Practice Questions

  1. 1 A decision boundary is f(x) = 2x1 - x2 + 1. For the point (3, 4), calculate f(x) and predict the class if positive values mean Class A and negative values mean Class B.
  2. 2 An SVM has ||w|| = 0.5 for a linearly separable dataset. Use margin width = 2 / ||w|| to find the margin width.
  3. 3 Two possible separating lines both classify all training points correctly. Line 1 has a small margin, and Line 2 has a large margin. Explain which line an SVM would choose and why.