X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=randomforest.cpp;h=acf87dfebcd022d37cf6974f8331c7ad940a017a;hp=1fcd23df79f8b925a0ceede3245cda94b7f2a884;hb=499f4ac6e321f9f03d4c3aa25c3b6880892c8b83;hpb=5072e9b05905ef385226a634b98189b4f9781489 diff --git a/randomforest.cpp b/randomforest.cpp index 1fcd23d..acf87df 100644 --- a/randomforest.cpp +++ b/randomforest.cpp @@ -104,6 +104,38 @@ 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) { + out << names[indexOfSample] << "\t" << intToTreatmentMap[majorityVotedOutcome] << "\t" << intToTreatmentMap[realOutcome] << endl; + + } + } + + out.close(); + return 0; + } + catch(exception& e) { + m->errorOut(e, "RandomForest", "getMissclassifications"); + exit(1); + } +} + /***********************************************************************/ int RandomForest::calcForrestVariableImportance(string filename) { try { @@ -148,7 +180,7 @@ int RandomForest::calcForrestVariableImportance(string filename) { m->openOutputFile(filename, out); out <<"OTU\tMean decrease accuracy\n"; for (int i = 0; i < globalVariableRanks.size(); i++) { - out << m->currentBinLabels[(int)globalVariableRanks[i].first] << '\t' << globalVariableImportanceList[globalVariableRanks[i].first] << endl; + out << m->currentSharedBinLabels[(int)globalVariableRanks[i].first] << '\t' << globalVariableImportanceList[globalVariableRanks[i].first] << endl; } out.close(); return 0;