Class ClassifierOptions<T>
Configuration options for classification models, which are machine learning methods used to predict categorical outcomes (discrete classes) rather than continuous values.
public class ClassifierOptions<T> : ModelOptions
Type Parameters
TThe data type used in matrix operations for the classifier model.
- Inheritance
-
ClassifierOptions<T>
- Derived
- Inherited Members
Remarks
Classification is a supervised learning technique where the goal is to predict which category or categories a sample belongs to. This class provides base configuration options for all classification models, with specific classifiers potentially extending these options.
For Beginners: Classification is about predicting categories, not numbers.
Think of examples like:
- Is this email spam or not? (Binary classification)
- What type of animal is in this picture? (Multi-class classification)
- What topics does this article cover? (Multi-label classification)
- How satisfied is this customer? (Ordinal classification)
This class lets you configure how the classification model is set up and trained.
Properties
ClassWeights
Gets or sets custom class weights for each class.
public double[]? ClassWeights { get; set; }
Property Value
- double[]
An array of weights corresponding to each class, or null to use default weights. When UseClassWeights is true and this is null, weights are computed automatically.
Remarks
Custom class weights allow fine-grained control over the importance of each class. This can be useful when the cost of misclassification varies by class in ways that are not captured by simple frequency-based weighting.
For Beginners: Sometimes you want specific control over how much each class "counts."
Example: In a medical diagnosis scenario with 3 conditions:
- Class 0: Common cold (low severity)
- Class 1: Flu (moderate severity)
- Class 2: Serious illness (high severity)
You might set ClassWeights = [1.0, 2.0, 10.0] to make the model try extra hard not to miss the serious illness.
The weights don't need to sum to 1 or match any particular formula - they just indicate relative importance. A weight of 10.0 means that class is considered 10x as important as a class with weight 1.0.
DecisionThreshold
public double DecisionThreshold { get; set; }
Property Value
TaskType
Gets or sets the type of classification task.
public ClassificationTaskType TaskType { get; set; }
Property Value
- ClassificationTaskType
The classification task type. Default is Binary, which assumes a two-class problem. The task type will be automatically inferred from training data if not explicitly set.
Remarks
The task type determines how the model interprets targets and outputs predictions. While this can be set explicitly, most classifiers will automatically detect the appropriate task type based on the training data.
For Beginners: This tells the model what kind of classification problem you're solving.
- Binary: Two classes (yes/no, spam/not-spam)
- MultiClass: Multiple exclusive classes (pick exactly one)
- MultiLabel: Multiple non-exclusive labels (pick all that apply)
- Ordinal: Ordered classes (poor/fair/good/excellent)
Usually, you don't need to set this manually - the model will figure it out from your training data. But you can set it explicitly if needed.
UseClassWeights
Gets or sets whether to use class weights to handle imbalanced datasets.
public bool UseClassWeights { get; set; }
Property Value
- bool
True to automatically compute class weights inversely proportional to class frequencies. False (default) to treat all classes equally.
Remarks
Class weights help address class imbalance by giving more importance to minority classes during training. When enabled, the weight for each class is typically computed as n_samples / (n_classes * n_samples_per_class).
For Beginners: Real-world data is often imbalanced - one category appears much more often than others.
Example: In fraud detection, 99% of transactions are legitimate, 1% are fraudulent. Without class weights, the model might just predict "legitimate" for everything and still get 99% accuracy - but it would miss all the fraud!
With UseClassWeights = true:
- Rare classes get higher weight (fraud becomes "worth" more)
- Common classes get lower weight (legitimate becomes "worth" less)
- The model is incentivized to correctly classify both types
Enable this when your classes have very different frequencies.