NuSupportVectorClassifier<T>
Models & Types · AiDotNet.Classification.SVM
Nu-Support Vector Classifier using the nu-SVM formulation.
Inheritance: ClassifierBase<T> → ProbabilisticClassifierBase<T> → SVMBase<T> → NuSupportVectorClassifier<T>
For Beginners
Nu-SVC is an alternative way to control the SVM’s complexity:
Standard SVC uses C:
- C controls the penalty for misclassification
- Hard to interpret: “what does C=1.0 mean?”
Nu-SVC uses nu:
- nu is between 0 and 1
- nu is approximately the fraction of support vectors
- nu is also an upper bound on training errors
- More intuitive: “I want about 30% support vectors” means nu=0.3
Use Nu-SVC when:
- You want more interpretable regularization
- You have a target for the error rate
- The C parameter in standard SVC is hard to tune
Note: Nu-SVC and standard SVC produce very similar results when properly tuned, but nu can be easier to set intuitively.
How It Works
Nu-SVC uses a different parameterization than standard SVC. Instead of the C parameter, it uses nu which is an upper bound on the fraction of margin errors and a lower bound on the fraction of support vectors.
Example
// Create Nu-SVC with intuitive regularization parameter
var options = new SVMOptions<double>();
// Prepare training data: 6 samples with 2 features
var features = new Matrix<double>(6, 2);
features[0, 0] = 1.0; features[0, 1] = 1.1;
features[1, 0] = 1.2; features[1, 1] = 0.9;
features[2, 0] = 0.8; features[2, 1] = 1.0;
features[3, 0] = 5.0; features[3, 1] = 5.1;
features[4, 0] = 5.2; features[4, 1] = 4.9;
features[5, 0] = 4.8; features[5, 1] = 5.0;
var labels = new Vector<double>(new double[] { 0, 0, 0, 1, 1, 1 });
// Train with nu parameter controlling support vector fraction
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new NuSupportVectorClassifier<double>(options))
.Build(features, labels);
// Predict class for new sample
var newSample = new Matrix<double>(1, 2);
newSample[0, 0] = 1.1; newSample[0, 1] = 1.0;
var prediction = result.Predict(newSample);
// Result is available in the returned value
Constructors
| Constructor | Summary |
|---|---|
NuSupportVectorClassifier(SVMOptions<T> options, IRegularization<T, Matrix<T>, Vector<T>> regularization, double nu) |
Initializes a new instance of the NuSupportVectorClassifier class. |
Methods
| Method | Summary |
|---|---|
Matrix<T> DecisionFunction(Matrix<T> input) |
|
Matrix<T> PredictProbabilities(Matrix<T> input) |
|
ModelMetadata<T> GetModelMetadata() |
|
Vector<T> Predict(Matrix<T> input) |
|
void Train(Matrix<T> x, Vector<T> y) |
Returns the model type identifier for this classifier. |