Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
38 deletions.
There are no files selected for viewing
Submodule data
updated
4 files
43 changes: 43 additions & 0 deletions
43
doc/cookbook/source/examples/classifier/multiclass_linearmachine.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
========================== | ||
Multi-class Linear Machine | ||
========================== | ||
|
||
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 :sgclass:`CLibLinear` to multi-class cases with :sgclass:`CLinearMulticlassMachine`. | ||
|
||
`See the linear SVM cookbook <http://shogun.ml/cookbook/latest/examples/classifier/linear_svm.html>`_ for the infomration about :sgclass:`CLibLinear` binary classifier. | ||
|
||
------- | ||
Example | ||
------- | ||
|
||
Imagine we have files with training and test data. We create CDenseFeatures (here 64 bit floats aka RealFeatures) and :sgclass:`CMulticlassLabels` as | ||
|
||
.. sgexample:: multiclass_linearmachine.sg:create_features | ||
|
||
We use :sgclass:`CLibLinear` as base classifier and create an instance of :sgclass:`CLibLinear`. | ||
|
||
.. sgexample:: multiclass_linearmachine.sg:create_classifier | ||
|
||
In order to run :sgclass:`CLinearMulticlassMachine`, we need to specify an multi-class strategy from :sgclass:`CMulticlassOneVsRestStrategy` and :sgclass:`CMulticlassOneVsOneStrategy`. | ||
|
||
.. sgexample:: multiclass_linearmachine.sg:choose_strategy | ||
|
||
We create an instance of the :sgclass:`CLinearMulticlassMachine` classifier by passing it the strategy, dataset, binary classifer and the labels. | ||
|
||
.. sgexample:: multiclass_linearmachine.sg:create_instance | ||
|
||
Then we train and apply it to test data, which here gives :sgclass:`CMulticlassLabels`. | ||
|
||
.. sgexample:: multiclass_linearmachine.sg:train_and_apply | ||
|
||
We can evaluate test performance via e.g. :sgclass:`CMulticlassAccuracy`. | ||
|
||
.. sgexample:: multiclass_linearmachine.sg:evaluate_accuracy | ||
|
||
---------- | ||
References | ||
---------- | ||
|
||
:wiki:`Multiclass_classification` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
CSVFile f_feats_train("../../data/classifier_4class_2d_linear_features_train.dat") | ||
CSVFile f_feats_test("../../data/classifier_4class_2d_linear_features_test.dat") | ||
CSVFile f_labels_train("../../data/classifier_4class_2d_linear_labels_train.dat") | ||
CSVFile f_labels_test("../../data/classifier_4class_2d_linear_labels_test.dat") | ||
|
||
#![create_features] | ||
RealFeatures features_train(f_feats_train) | ||
RealFeatures features_test(f_feats_test) | ||
MulticlassLabels labels_train(f_labels_train) | ||
MulticlassLabels labels_test(f_labels_test) | ||
#![create_features] | ||
|
||
#![create_classifier] | ||
LibLinear classifier() | ||
#![create_classifier] | ||
|
||
#![choose_strategy] | ||
MulticlassOneVsOneStrategy strategy() | ||
#![choose_strategy] | ||
|
||
#![create_instance] | ||
LinearMulticlassMachine mc_classifier(strategy, features_train, classifier, labels_train) | ||
#![create_instance] | ||
|
||
#![train_and_apply] | ||
mc_classifier.train() | ||
MulticlassLabels labels_predict = mc_classifier.apply_multiclass(features_test) | ||
#![train_and_apply] | ||
|
||
#![evaluate_accuracy] | ||
MulticlassAccuracy eval() | ||
real accuracy = eval.evaluate(labels_predict, labels_test) | ||
#![evaluate_accuracy] | ||
|
||
# integration testing variables | ||
RealVector output = labels_predict.get_labels() |
37 changes: 0 additions & 37 deletions
37
examples/undocumented/python_modular/classifier_multiclasslinearmachine_modular.py
This file was deleted.
Oops, something went wrong.