From: kdiverson <> Date: Wed, 11 Sep 2013 18:41:42 +0000 (-0400) Subject: adding misclassification output file X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=69cb74767d8f15d7715653b6eb2119e15b335977 adding misclassification output file --- diff --git a/randomforest.cpp b/randomforest.cpp index 1fcd23d..6f40b7c 100644 --- a/randomforest.cpp +++ b/randomforest.cpp @@ -104,6 +104,42 @@ int RandomForest::printConfusionMatrix(map intToTreatmentMap) { } } +/***********************************************************************/ + +int RandomForest::getMissclassifications(string filename, map intToTreatmentMap, vector names) { + try { + ofstream out; + m->openOutputFile(filename, out); + out <<"Sample\tRF classification\tActual classification\n"; + for (map >::iterator it = globalOutOfBagEstimates.begin(); it != globalOutOfBagEstimates.end(); it++) { + + if (m->control_pressed) { return 0; } + + int indexOfSample = it->first; + vector predictedOutComes = it->second; + vector::iterator maxPredictedOutComeIterator = max_element(predictedOutComes.begin(), predictedOutComes.end()); + int majorityVotedOutcome = (int)(maxPredictedOutComeIterator - predictedOutComes.begin()); + int realOutcome = dataSet[indexOfSample][numFeatures]; + + if (majorityVotedOutcome != realOutcome) { + //write to file + //dataSet[indexOfSample][]; + + out << names[indexOfSample] << "\t" << intToTreatmentMap[majorityVotedOutcome] << "\t" << intToTreatmentMap[realOutcome] << endl; + //out << m->currentBinLabels[(int)globalVariableRanks[i].first] << '\t' << globalVariableImportanceList[globalVariableRanks[i].first] << endl; + + } + } + + out.close(); + return 0; + } + catch(exception& e) { + m->errorOut(e, "RandomForest", "calcForrestErrorRate"); + exit(1); + } +} + /***********************************************************************/ int RandomForest::calcForrestVariableImportance(string filename) { try {