We extend the application of linear machines to multi-class datasets by constructing generic multiclass classifiers with ensembles of binary classifiers.
In this example, we show how to apply CLibLinear
to multi-class cases with CLinearMulticlassMachine
.
See the linear SVM cookbook for the infomration about CLibLinear
binary classifier.
Imagine we have files with training and test data. We create CDenseFeatures (here 64 bit floats aka RealFeatures) and CMulticlassLabels
as
multiclass_linearmachine.sg:create_features
We use CLibLinear
as base classifier and create an instance of CLibLinear
.
multiclass_linearmachine.sg:create_classifier
In order to run CLinearMulticlassMachine
, we need to specify an multi-class strategy from CMulticlassOneVsRestStrategy
and CMulticlassOneVsOneStrategy
.
multiclass_linearmachine.sg:choose_strategy
We create an instance of the CLinearMulticlassMachine
classifier by passing it the strategy, dataset, binary classifer and the labels.
multiclass_linearmachine.sg:create_instance
Then we train and apply it to test data, which here gives CMulticlassLabels
.
multiclass_linearmachine.sg:train_and_apply
We can evaluate test performance via e.g. CMulticlassAccuracy
.
multiclass_linearmachine.sg:evaluate_accuracy
Multiclass_classification