From b9201cfeea28caf2f68b90c4adfd895426916722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Wed, 5 Jul 2023 20:45:21 +0200 Subject: [PATCH] Check result with KDB(k=3) Same experiment with KDB(k=3), dataset glass, from bayesclass & bayesnet Had same result 0.841121 --- .vscode/launch.json | 2 +- sample/ArffFiles.cc | 6 +++--- sample/main.cc | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index fde5435..63a5fcf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "program": "${workspaceFolder}/build/sample/main", "args": [ "-f", - "iris" + "glass" ], "cwd": "${workspaceFolder}", "preLaunchTask": "CMake: build" diff --git a/sample/ArffFiles.cc b/sample/ArffFiles.cc index b576699..b3336fe 100644 --- a/sample/ArffFiles.cc +++ b/sample/ArffFiles.cc @@ -63,7 +63,7 @@ void ArffFiles::load(const string& fileName, bool classLast) type = ""; while (ss >> type_w) type += type_w + " "; - attributes.emplace_back(attribute, trim(type)); + attributes.emplace_back(trim(attribute), trim(type)); continue; } if (line[0] == '@') { @@ -111,8 +111,8 @@ void ArffFiles::generateDataset(bool classLast) string ArffFiles::trim(const string& source) { string s(source); - s.erase(0, s.find_first_not_of(" \n\r\t")); - s.erase(s.find_last_not_of(" \n\r\t") + 1); + s.erase(0, s.find_first_not_of(" '\n\r\t")); + s.erase(s.find_last_not_of(" '\n\r\t") + 1); return s; } diff --git a/sample/main.cc b/sample/main.cc index b5cec25..56ee711 100644 --- a/sample/main.cc +++ b/sample/main.cc @@ -213,7 +213,13 @@ int main(int argc, char** argv) map maxes; tie(Xd, maxes) = discretize(X, y, features); maxes[className] = *max_element(y.begin(), y.end()) + 1; - // Build Network + cout << "Features: "; + for (auto feature : features) { + cout << "[" << feature << "] "; + } + cout << endl; + cout << "Class name: " << className << endl; + // Build Network auto network = bayesnet::Network(); build_network(network, network_name, maxes); network.fit(Xd, y, features, className);