From 5072e9b05905ef385226a634b98189b4f9781489 Mon Sep 17 00:00:00 2001 From: kdiverson <> Date: Wed, 11 Sep 2013 11:27:58 -0400 Subject: [PATCH] adding pretty confusion matrix --- randomforest.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/randomforest.cpp b/randomforest.cpp index 852da37..1fcd23d 100644 --- a/randomforest.cpp +++ b/randomforest.cpp @@ -70,22 +70,31 @@ int RandomForest::printConfusionMatrix(map intToTreatmentMap) { vector::iterator maxPredictedOutComeIterator = max_element(predictedOutComes.begin(), predictedOutComes.end()); int majorityVotedOutcome = (int)(maxPredictedOutComeIterator - predictedOutComes.begin()); int realOutcome = dataSet[indexOfSample][numFeatures]; - cm[realOutcome][majorityVotedOutcome] = cm[realOutcome][majorityVotedOutcome] + 1; + cm[realOutcome][majorityVotedOutcome] = cm[realOutcome][majorityVotedOutcome] + 1; + } + + vector fw; + for (int w = 0; w mothurOut("confusion matrix:\n\t\t"); - for (int i = 0; i < numGroups; i++) { - m->mothurOut(intToTreatmentMap[i] + "\t"); + for (int k = 0; k < numGroups; k++) { + //m->mothurOut(intToTreatmentMap[k] + "\t"); + cout << setw(fw[k]) << intToTreatmentMap[k] << "\t"; } for (int i = 0; i < numGroups; i++) { + cout << "\n" << setw(fw[i]) << intToTreatmentMap[i] << "\t"; //m->mothurOut("\n" + intToTreatmentMap[i] + "\t"); if (m->control_pressed) { return 0; } for (int j = 0; j < numGroups; j++) { - m->mothurOut(cm[i][j] + "\t"); + //m->mothurOut(toString(cm[i][j]) + "\t"); + cout << setw(fw[i]) << cm[i][j] << "\t"; } } - m->mothurOut("\n"); - + //m->mothurOut("\n"); + cout << "\n"; + return 0; } -- 2.39.2