Confusion matrix throws exception #2203
Description
What would you like to submit? (put an 'x' inside the bracket that applies)
- [X ] question
- bug report
- feature request
Issue description
Hi all,
I need a little help from the experts...
In one of my projects I am using Accord.NET Machine Learning (C4.5) for predicting trading profits and the confusion matrix to calculate some parameters.
In some special cases - when the output class just contains one value (see below) - the estimation of the confusion matrix throws the following exception:
The data table is structured as follows ({Current] is only used for process flow while adding rows):
[TBO] (int) | [StdDev] (double) | [Profit] (yes/no) | [Current] (yes/no)
Working example (output = yes, no):
45 | 0.123 | yes | no
31 | 0.456 | yes | no
78 | 0.543 | no | no
56 | 0.845 | yes | no
Example throwing the exception (output = yes):
45 | 0.123 | yes | no
31 | 0.456 | yes | no
78 | 0.543 | yes | no
56 | 0.845 | yes | no
The following code fragment is used for codification, learning and creating the confusion matrix:
codebook = new Codification(c45Data);
DecisionVariable[] attributes =
{
new DecisionVariable("TBO", DecisionVariableKind.Continuous),
new DecisionVariable("StdDev", DecisionVariableKind.Continuous)
};
int classCount = codebook["Profit"].NumberOfSymbols;
tree = new DecisionTree(attributes, classCount);
C45Learning c45 = new C45Learning(tree);
DataTable symbols = codebook.Apply(c45Data);
double[][] inputs = symbols.ToJagged("TBO", "StdDev");
int[] outputs = symbols.ToArray<int>("Profit");
DecisionTree decisionTree = c45.Learn(inputs, outputs);
DecisionSet rules = tree.ToRules();
string ruleText = rules.ToString(codebook, "Profit", System.Globalization.CultureInfo.InvariantCulture);
ConfusionMatrix confusionMatrix = ConfusionMatrix.Estimate(decisionTree, inputs, outputs);
The last line is the one that throws the exception!
Can someone please advise me how to fix this issue - any help is welcome!
Many thanks in advance and best regards,
Christian