MultiOutputClassifier<T>
Models & Types · AiDotNet.Classification.Meta
Multi-output classifier for independent multi-label classification.
Inheritance: ClassifierBase<T> → ProbabilisticClassifierBase<T> → MetaClassifierBase<T> → MultiOutputClassifier<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
MultiOutputClassifier is the simplest multi-label approach:
For labels A, B, C:
- Classifier 1: Predict A using features X
- Classifier 2: Predict B using features X
- Classifier 3: Predict C using features X
Each classifier is completely independent.
When to use:
- When labels are truly independent
- As a simple baseline for multi-label problems
- When you don’t need to model label correlations
Note: Unlike ClassifierChain, this does NOT capture label dependencies.
How It Works
MultiOutputClassifier fits one classifier per target label, treating each label as independent of the others.
Example
// Create multi-output classifier with independent per-label classifiers
var options = new MetaClassifierOptions<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 one independent classifier per target label
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new MultiOutputClassifier<double>())
.Build(features, labels);
// Predict each label independently
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 |
|---|---|
MultiOutputClassifier() |
Initializes a new instance with default settings using Gaussian Naive Bayes as the base estimator. |
MultiOutputClassifier(Func<IClassifier<T>> estimatorFactory, MetaClassifierOptions<T> options, IRegularization<T, Matrix<T>, Vector<T>> regularization) |
Initializes a new instance of the MultiOutputClassifier class. |
Properties
| Property | Summary |
|---|---|
int NumLabels { get; } |
Gets the number of labels (same as number of classes for multi-label). |
string[] LabelNames { get; set; } |
Gets or sets the label names if available. |
Methods
| Method | Summary |
|---|---|
Matrix<T> PredictLogProbabilities(Matrix<T> input) |
|
Matrix<T> PredictMultiLabel(Matrix<T> input) |
Predicts multi-label output for the given input. |
Matrix<T> PredictMultiLabelProbabilities(Matrix<T> input) |
|
Matrix<T> PredictProbabilities(Matrix<T> input) |
|
Vector<T> Predict(Matrix<T> input) |
|
void Train(Matrix<T> x, Vector<T> y) |
Standard training method - converts single labels to multi-label format. |
void TrainMultiLabel(Matrix<T> x, Matrix<T> yMultiLabel) |
Returns the model type identifier for this classifier. |