Class SVMOptions<T>
Configuration options for Support Vector Machine classifiers.
public class SVMOptions<T> : ClassifierOptions<T>
Type Parameters
TThe data type used for calculations.
- Inheritance
-
SVMOptions<T>
- Inherited Members
Remarks
Support Vector Machines (SVMs) find the optimal hyperplane that maximizes the margin between classes. They are particularly effective in high-dimensional spaces and can handle non-linear classification using kernel functions.
For Beginners: SVMs are like drawing the best possible line between classes!
Imagine you have red and blue dots on paper. You want to draw a line that:
- Separates the red dots from the blue dots
- Stays as far as possible from both sets of dots
The "margin" is the gap between the line and the nearest dots on each side. SVMs find the line that maximizes this margin.
Key concepts:
- C parameter: How much to penalize misclassifications (higher = stricter)
- Kernel: How to measure similarity between points (linear, RBF, polynomial)
- Support vectors: The dots closest to the line that define its position
SVMs work great when:
- You have clear separation between classes
- You have many features but not tons of samples
- You need a robust classifier
Properties
C
Gets or sets the regularization parameter C.
public double C { get; set; }
Property Value
- double
The regularization strength. Default is 1.0.
Remarks
C controls the trade-off between achieving a low training error and a low testing error (generalization). Higher C means less regularization and the model will try harder to classify all training points correctly.
For Beginners: C controls how strictly the SVM fits the training data.
- C = 0.01: Very flexible boundary, allows many misclassifications
- C = 1.0: Balanced (default), good starting point
- C = 100: Very strict, tries to classify all training points correctly
If your model overfits (high training accuracy, low test accuracy), try lower C. If your model underfits (low training accuracy), try higher C.
CacheSize
Gets or sets the cache size in MB for kernel computations.
public double CacheSize { get; set; }
Property Value
- double
The cache size in megabytes. Default is 200.
Coef0
Gets or sets the independent term (coef0) in kernel function.
public double Coef0 { get; set; }
Property Value
- double
The coefficient. Default is 0.0.
Remarks
Used in polynomial and sigmoid kernels.
Degree
Gets or sets the degree for polynomial kernel.
public int Degree { get; set; }
Property Value
- int
The polynomial degree. Default is 3.
Remarks
Only used when Kernel is Polynomial. Higher degrees can model more complex relationships but may overfit.
Gamma
Gets or sets the kernel coefficient gamma.
public double? Gamma { get; set; }
Property Value
- double?
The gamma value, or null for "scale" (1 / (n_features * variance)). Default is null.
Remarks
Gamma defines how far the influence of a single training example reaches. Low gamma means 'far' (smoother decision boundary), high gamma means 'close' (more complex, wiggly boundary).
For Beginners: Gamma controls the "reach" of each training point.
- Low gamma (0.001): Each point influences a large area (smooth boundary)
- High gamma (10.0): Each point only influences nearby points (complex boundary)
If null, gamma is set automatically based on your data. Too high gamma = overfitting Too low gamma = underfitting
Kernel
Gets or sets the kernel type.
public KernelType Kernel { get; set; }
Property Value
- KernelType
The kernel function to use. Default is RBF.
Remarks
The kernel determines how similarity between samples is computed. Different kernels can capture different types of relationships.
For Beginners: Kernels let SVMs work with non-linear boundaries!
- Linear: Straight line/plane separation (fast, works when data is linearly separable)
- RBF (Radial Basis Function): Flexible curves (most popular, handles complex patterns)
- Polynomial: Curved boundaries with polynomial degree
- Sigmoid: S-shaped curves (similar to neural networks)
Start with RBF - it works well for most problems. Use Linear if you have many features or need speed.
MaxIterations
Gets or sets the maximum number of iterations.
public int MaxIterations { get; set; }
Property Value
- int
The maximum iterations, or -1 for unlimited. Default is 1000.
OneVsRest
Gets or sets whether to use one-vs-rest or one-vs-one for multi-class.
public bool OneVsRest { get; set; }
Property Value
- bool
True for one-vs-rest, false for one-vs-one. Default is false (OvO).
Remarks
For multi-class classification: - One-vs-One (OvO): Train n*(n-1)/2 classifiers, one for each pair of classes - One-vs-Rest (OvR): Train n classifiers, each separating one class from all others
For Beginners: How to handle more than 2 classes?
OvO (default):
- Creates classifiers for every pair of classes
- More classifiers but each is simpler
- Often works better in practice
OvR:
- Creates one classifier per class
- Each classifier separates one class from "everything else"
- Fewer classifiers but each may be harder to train
Probability
Gets or sets whether to calculate probability estimates.
public bool Probability { get; set; }
Property Value
- bool
True to enable probability estimation. Default is false.
Remarks
When true, the SVM will be trained to output probability estimates. This uses Platt scaling and requires extra cross-validation during training.
For Beginners: Should the SVM output probabilities?
With Probability = true:
- PredictProbabilities() returns actual probabilities (0.0 to 1.0)
- Training takes longer (needs calibration)
With Probability = false:
- PredictProbabilities() returns estimates based on decision function
- Faster training
Enable this if you need calibrated probability outputs.
RandomState
Gets or sets the random state for probability estimation.
public int? RandomState { get; set; }
Property Value
- int?
The random seed, or null for non-deterministic. Default is null.
Shrinking
Gets or sets whether to use shrinking heuristic.
public bool Shrinking { get; set; }
Property Value
- bool
True to use shrinking (default), false otherwise.
Remarks
Shrinking can speed up training by focusing on active support vectors. It usually helps but can sometimes slow things down.
Tolerance
Gets or sets the tolerance for stopping criterion.
public double Tolerance { get; set; }
Property Value
- double
The tolerance. Default is 0.001.
Remarks
The solver iterates until the change in the objective function is below this threshold. Lower values mean more precise solutions but longer training.