machine learning
support vector machine
SVM parameters
C parameter
gamma parameter

Support Vector Machine What are C Gamma?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction to Support Vector Machines

Support Vector Machines (SVMs) are a set of supervised learning methods used for classification, regression, and outliers detection. Developed in the 1990s, SVMs have proven to be effective in high-dimensional spaces and are versatile in both linear and non-linear classification tasks. Their primary aim is to find the optimal separating hyperplane which maximizes the margin between two classes.

Core Concepts of SVMs

Margin and Hyperplane

In the context of SVMs, a hyperplane is a decision boundary that separates different classes. The margin is defined as the distance between the closest data points (support vectors) of the two classes. The SVM algorithm seeks to maximize this margin, ensuring that the model is robust and has lower generalization error.

Non-Linear Classification and Kernel Trick

While SVMs work well with linearly separable data, many real-world problems require non-linear decision boundaries. To handle this, SVMs use kernel functions to project data into higher-dimensional spaces where a linear separator can be applied. Common kernels include linear, polynomial, radial basis function (RBF), and sigmoid.

Regularization and Hyperparameters

C - Regularization Parameter

The parameter CC controls the trade-off between maximizing the margin and minimizing the classification error. Essentially, it is a regularization parameter that influences the decision boundary's flexibility.

  • Large CC: Penalizes the model more heavily for misclassification, leading to a harder margin. This approach can cause the model to overfit as it tries to classify all training data points correctly.
  • Small CC: Produces a softer margin, allowing for some misclassifications to increase the margin. This can improve generalization but might underfit the data.

Gamma - Kernel Coefficient for RBF and Polynomial Kernels

Gamma (γ\gamma) defines how far the influence of a single training example reaches, with low values meaning "far" and high values meaning "close".

  • High γ\gamma: Leads to tighter decision boundaries around the support vectors, which can cause overfitting.
  • Low γ\gamma: Results in smoother decision boundaries, potentially leading to underfitting.

Example Use Case

Consider a classification problem with two classes of data points. By adjusting CC and γ\gamma, different decision boundaries can be formed:

  • With C=1C=1 and γ=0.1\gamma=0.1, the SVM might create a smooth boundary, potentially misclassifying some edge data points.
  • Increasing CC to 100 forces the model to achieve higher accuracy on training data by creating intricate decision boundaries.
  • With γ=1.0\gamma=1.0, the decision boundary becomes more sensitive to data points, closely wrapping around the dataset clusters.

Hyperparameter Tuning

To optimize the performance of an SVM, both CC and γ\gamma need tuning. Strategies for hyperparameter tuning include:

  1. Grid Search: Exhaustively searches through a specified subset of hyperparameter space.
  2. Random Search: Samples random combinations of hyperparameters from a defined space, which can be more efficient than grid search.
  3. Cross-Validation: Evaluates model performance by partitioning the dataset into training and validation sets multiple times.

Summary Table

ParameterDescriptionEffect on Model
CRegularization parameter that controls the trade-off between margin size and misclassification.Large CC: Narrow margin, possible overfitting. Small CC: Wider margin, possible underfitting.
Gamma (γ\gamma)Kernel coefficient for RBF and polynomial kernels. Controls the influence of single data points.High γ\gamma: Complex decision boundary, possible overfitting. Low γ\gamma: Simpler decision boundary, possible underfitting.

Advanced Topics

Multi-Class Classification with SVM

While SVMs are inherently binary classifiers, various strategies allow for multi-class classification:

  • One-vs-One (OvO): Constructs a binary classifier for each pair of classes.
  • One-vs-Rest (OvR): Constructs one binary classifier per class against all other classes.

Applications of SVMs

SVMs are applicable in various domains, such as:

  • Text Categorization: Effective for high-dimensional spaces like text classification.
  • Image Classification: Can be used in image recognition tasks, especially with kernels that handle diverse pixel representations.
  • Bioinformatics: Useful in gene classification and protein structure prediction due to their robustness in high-dimensional spaces.

Conclusion

Support Vector Machines remain a powerful tool in machine learning, especially in classification tasks requiring robustness and precision in high-dimensional data. Understanding the critical parameters CC and γ\gamma ensures effective model tuning, striking a balance between fitting accuracy and generalization. With advancements in computational techniques, SVMs continue to find new applications across diverse fields.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.