Decision Structure |
Namespace: Accord.MachineLearning
The Decision type exposes the following members.
Name | Description | |
---|---|---|
Equals | Indicates whether this instance and a specified object are equal. (Inherited from ValueType.) | |
GetHashCode | Returns the hash code for this instance. (Inherited from ValueType.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
ToString |
Returns a String that represents this instance.
(Overrides ValueTypeToString.) | |
ToTuple |
Converts to a triplet (class_a, class_b, winner).
|
Name | Description | |
---|---|---|
HasMethod |
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) | |
IsEqual |
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.) | |
To(Type) | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) | |
ToT | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) |
The Decision structure is used to represent the outcome of a binary classifier for the problem of deciding between two classes. For example, let's say we would like to represent that, given the problem of deciding between class #4 and class #2, a binary classsifier has opted for deciding that class #2 was more likely than class #4. This could be represented by a Decision structure by instantiating it using Decision(i: 4, j: 2, winner: 2).
The Decision structure is more likely to be used or found when dealing with strategies for creating multi-class and/or multi-label classifiers using a set of binary classifiers, such as when using OneVsOneTBinary, TInput and OneVsRestTModel, TInput. In the example below, we will extract the sequence of binary classification problems and their respective decisions when evaluating a multi-class SVM using the one-vs-one decision strategy for multi-class problems:
// Generate always same random numbers Accord.Math.Random.Generator.Seed = 0; // The following is a simple auto association function in which // the last column of each input correspond to its own class. This // problem should be easily solved using a Linear kernel. // Sample input data double[][] inputs = { new double[] { 1, 2, 0 }, new double[] { 6, 2, 3 }, new double[] { 1, 1, 1 }, new double[] { 7, 6, 2 }, }; // Output for each of the inputs int[] outputs = { 0, 3, 1, 2 }; // Create the multi-class learning algorithm for the machine var teacher = new MulticlassSupportVectorLearning<Linear>() { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new SequentialMinimalOptimization<Linear>() { // If you would like to use other kernels, simply replace // the generic parameter to the desired kernel class, such // as for example, Polynomial or Gaussian: Kernel = new Linear() // use the Linear kernel } }; // Estimate the multi-class support vector machine using one-vs-one method MulticlassSupportVectorMachine<Linear> ovo = teacher.Learn(inputs, outputs); // Obtain class predictions for each sample int[] predicted = ovo.Decide(inputs); // Compute classification error double error = new ZeroOneLoss(outputs).Loss(predicted);
// The decision process in a multi-class SVM is actually based on a series of // smaller, binary decisions combined together using a one-vs-one strategy. It // is possible to determine the results of each of those internal one-vs-one // decisions using: // First, call Decide, Scores, LogLikelihood or Probability methods: int y = ovo.Decide(new double[] { 6, 2, 3 }); // result should be 3 // Now, call method GetLastDecisionPath(): Decision[] path = ovo.GetLastDecisionPath(); // contains 3 decisions // The binary decisions obtained while computing the last decision // above (i.e. the last call to the Decide method), were: // // - Class 0 vs. class 3, winner was 3 // - Class 1 vs. class 3, winner was 3 // - Class 2 vs. class 3, winner was 3 // The GetLastDecisionPath() method is thread-safe and will always // return the last computed path in the current calling thread.