Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Confusion matrix throws exception #2203

Open
2 tasks
icb088 opened this issue Sep 22, 2020 · 3 comments · May be fixed by #2213
Open
2 tasks

Confusion matrix throws exception #2203

icb088 opened this issue Sep 22, 2020 · 3 comments · May be fixed by #2213

Comments

@icb088
Copy link

icb088 commented Sep 22, 2020

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:
image

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

@davidrapan
Copy link

Hi! I slightly peeked into CM source and found this
https://github.com/accord-net/framework/blob/840aba6e077dee29c5978c6b697bcb56fae70f9d/Sources/Accord.Statistics/Analysis/Performance/ConfusionMatrix.cs#L187

Constructor used in this scenario dont alllow anything but 2 differs.
D.

@icb088
Copy link
Author

icb088 commented Sep 30, 2020 via email

@davidrapan
Copy link

Hi, yes i guess so.

@davidrapan davidrapan linked a pull request Sep 30, 2020 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants