Add bold max score per model in b_list results

This commit is contained in:
2024-03-11 17:02:58 +01:00
parent 52d689666a
commit 72cda3784a
5 changed files with 72 additions and 24 deletions

View File

@@ -1,7 +1,8 @@
# Platform
<a href="#"><img src="https://img.shields.io/badge/c++-%2300599C.svg?style=flat&logo=c%2B%2B&logoColor=white"></img></a>
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
![C++](https://img.shields.io/badge/c++-%2300599C.svg?style=flat&logo=c%2B%2B&logoColor=white)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](<https://opensource.org/licenses/MIT>)
![Gitea Last Commit](https://img.shields.io/gitea/last-commit/rmontanana/platform?gitea_url=https://gitea.rmontanana.es:3000&logo=gitea)
Platform to run Bayesian Networks and Machine Learning Classifiers experiments.

View File

@@ -1,5 +1,4 @@
#include "ResultsDatasetExcel.h"
#include <iostream>
namespace platform {
ResultsDatasetExcel::ResultsDatasetExcel()
{
@@ -25,11 +24,21 @@ namespace platform {
writeString(row, col++, name, "bodyHeader");
}
// Body
std::string bold = "_bold";
double maxResult = data["maxResult"].get<double>();
for (const auto& item : data["results"]) {
row++;
col = 0;
std::string style = item["score"] == data["maxResult"] ? "_bold" : "";
std::string style = "";
auto score = item["score"].get<double>();
if (score == data["max_models"][item["model"].get<std::string>()]) {
boldBlue();
style = bold;
}
if (score == maxResult) {
boldRed();
style = bold;
}
writeInt(row, col++, row - 3, "ints" + style);
writeString(row, col++, item["model"], "text" + style);
writeString(row, col++, item["date"], "text" + style);
@@ -39,8 +48,8 @@ namespace platform {
}
// Format columns
worksheet_freeze_panes(worksheet, 3, 2);
auto modelSize = data["maxModel"].get<int>();
auto hyperSize = data["maxHyper"].get<int>();
auto modelSize = data["lengths"]["maxModel"].get<int>();
auto hyperSize = data["lengths"]["maxHyper"].get<int>();
std::vector<int> columns_sizes = { 5, modelSize + 3, 12, 9, 11, hyperSize + 10 };
for (int i = 0; i < columns_sizes.size(); ++i) {
worksheet_set_column(worksheet, i, i, columns_sizes.at(i), NULL);

View File

@@ -89,31 +89,21 @@ void list_results(argparse::ArgumentParser& program)
std::cerr << Colors::RED() << "No results found for dataset " << dataset << " and model " << model << Colors::RESET() << std::endl;
exit(1);
}
//
// List data
//
int maxModel = results.maxModelSize();
int maxHyper = results.maxHyperSize();
double maxResult = results.maxResultScore();
std::cout << Colors::GREEN() << "Results of dataset " << dataset << " - for " << model << " model" << std::endl;
std::cout << "There are " << results.size() << " results" << std::endl;
std::cout << Colors::GREEN() << " # " << std::setw(maxModel + 1) << std::left << "Model" << "Date Time Score Hyperparameters" << std::endl;
std::cout << "=== " << std::string(maxModel, '=') << " ========== ======== =========== " << std::string(maxHyper, '=') << std::endl;
auto i = 0;
// Build data for the Report
json data = json::object();
data["results"] = json::array();
data["max_models"] = json::object(); // Max score per model
for (const auto& result : results) {
auto results = result.getData();
if (!data["max_models"].contains(result.getModel())) {
data["max_models"][result.getModel()] = 0;
}
for (const auto& item : results["results"]) {
if (item["dataset"] == dataset) {
auto color = (i % 2) ? Colors::BLUE() : Colors::CYAN();
color = item["score"].get<double>() == maxResult ? Colors::RED() : color;
std::cout << color << std::setw(3) << std::fixed << std::right << i++ << " ";
std::cout << std::setw(maxModel) << std::left << result.getModel() << " ";
std::cout << color << result.getDate() << " ";
std::cout << color << result.getTime() << " ";
std::cout << std::setw(11) << std::setprecision(9) << std::fixed << item["score"].get<double>() << " ";
std::cout << item["hyperparameters"].dump() << std::endl;
// Store data for Excel report
json res = json::object();
res["date"] = result.getDate();
@@ -122,16 +112,39 @@ void list_results(argparse::ArgumentParser& program)
res["score"] = item["score"].get<double>();
res["hyperparameters"] = item["hyperparameters"].dump();
data["results"].push_back(res);
if (item["score"].get<double>() > data["max_models"][result.getModel()]) {
data["max_models"][result.getModel()] = item["score"].get<double>();
}
break;
}
}
}
//
// List the results
//
std::cout << Colors::GREEN() << "Results of dataset " << dataset << " - for " << model << " model" << std::endl;
std::cout << "There are " << results.size() << " results" << std::endl;
std::cout << Colors::GREEN() << " # " << std::setw(maxModel + 1) << std::left << "Model" << "Date Time Score Hyperparameters" << std::endl;
std::cout << "=== " << std::string(maxModel, '=') << " ========== ======== =========== " << std::string(maxHyper, '=') << std::endl;
auto i = 0;
for (const auto& item : data["results"]) {
auto color = (i % 2) ? Colors::BLUE() : Colors::CYAN();
auto score = item["score"].get<double>();
color = score == data["max_models"][item["model"].get<std::string>()] ? Colors::YELLOW() : color;
color = score == maxResult ? Colors::RED() : color;
std::cout << color << std::setw(3) << std::fixed << std::right << i++ << " ";
std::cout << std::setw(maxModel) << std::left << item["model"].get<std::string>() << " ";
std::cout << color << item["date"].get<std::string>() << " ";
std::cout << color << item["time"].get<std::string>() << " ";
std::cout << std::setw(11) << std::setprecision(9) << std::fixed << score << " ";
std::cout << item["hyperparameters"].get<std::string>() << std::endl;
}
if (excel) {
data["dataset"] = dataset;
data["score"] = score;
data["model"] = model;
data["maxModel"] = maxModel;
data["maxHyper"] = maxHyper;
data["lengths"]["maxModel"] = maxModel;
data["lengths"]["maxHyper"] = maxHyper;
data["maxResult"] = maxResult;
auto report = platform::ResultsDatasetExcel();
report.report(data);

View File

@@ -64,6 +64,27 @@ namespace platform {
}
return efectiveStyle;
}
void ExcelFile::boldFontColor(const uint32_t color)
{
createFormats();
for (const std::string& style : { "text", "ints", "result" }) {
for (const std::string& suffix : { "_odd", "_even" }) {
format_set_font_color(styles[style + "_bold" + suffix], lxw_color_t(color));
}
}
}
void ExcelFile::boldGreen()
{
boldFontColor(0x00FF00);
}
void ExcelFile::boldRed()
{
boldFontColor(0xFF0000);
}
void ExcelFile::boldBlue()
{
boldFontColor(0x0000FF);
}
void ExcelFile::writeString(int row, int col, const std::string& text, const std::string& style)
{
worksheet_write_string(worksheet, row, col, text.c_str(), efectiveStyle(style));

View File

@@ -26,6 +26,10 @@ namespace platform {
void writeInt(int row, int col, const int number, const std::string& style = "");
void writeDouble(int row, int col, const double number, const std::string& style = "");
void createFormats();
void boldFontColor(const uint32_t color); // the same color for bold styles
void boldRed(); //set red color for the bold styles
void boldBlue(); //set blue color for the bold styles
void boldGreen(); //set green color for the bold styles
void createStyle(const std::string& name, lxw_format* style, bool odd);
void addColor(lxw_format* style, bool odd);
lxw_format* efectiveStyle(const std::string& name);