From 9a164e937032f01612bf0394b748542aa8c134d0 Mon Sep 17 00:00:00 2001 From: Trianta <56975502+Trimutex@users.noreply.github.com> Date: Wed, 17 Apr 2024 21:25:11 -0500 Subject: [PATCH] oneR: fixed using wrong method of calculating lowest error rate --- src/arff/arff.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/arff/arff.cpp b/src/arff/arff.cpp index 9eb6025..f625495 100644 --- a/src/arff/arff.cpp +++ b/src/arff/arff.cpp @@ -220,21 +220,24 @@ namespace ARFF { results.emplace(value, 0); } for (int i = 0; i < attribute->values.size(); ++i) { + int resultsTotal = 0; if (attribute->values[i] == "?") { continue; } for (auto instance = database.begin(); instance != database.end(); ++instance) { if (instance->values[attributePos] != attribute->values[i]) { continue; } ++results[instance->values.back()]; + resultsTotal++; } debug::Log(kTrace, "Results:"); for (auto it : results) { debug::Log(kTrace, "\t" + it.first + ": " + std::to_string(it.second)); } - int lowest = 9999; + float lowest; + float lowestRate = 1.0f; std::string bestResult = results.begin()->first; for (auto it = results.begin(); it != results.end(); ++it) { - if (it->second < lowest) { - lowest = it->second; - } else { + if (((resultsTotal - it->second) / float(resultsTotal)) < lowestRate) { + lowestRate = ((resultsTotal - it->second) / float(resultsTotal)); + lowest = resultsTotal - it->second; bestResult = it->first; - } + } } evaluation.rules.emplace(attribute->values[i], bestResult); evaluation.totalError += lowest;