Add friedman hyperparameter
This commit is contained in:
parent
f0d0abe891
commit
cab8e14b2d
@ -237,11 +237,9 @@ namespace platform {
|
|||||||
cout << "Can't make the Friedman test with less than 3 models and/or less than 3 datasets." << endl;
|
cout << "Can't make the Friedman test with less than 3 models and/or less than 3 datasets." << endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cout << Colors::BLUE() << "Friedman test: H0: 'There is no significant differences between all the classifiers.'" << endl;
|
cout << Colors::BLUE() << endl;
|
||||||
cout << "N datasets: " << nDatasets << endl;
|
cout << "*************************************************************************************" << endl;
|
||||||
cout << "N models: " << nModels << endl;
|
cout << "Friedman test: H0: 'There is no significant differences between all the classifiers.'" << endl;
|
||||||
cout << "Significance: " << significance << endl;
|
|
||||||
cout << "Nº Ranks: " << ranks.size() << endl;
|
|
||||||
for (const auto& rank : ranks) {
|
for (const auto& rank : ranks) {
|
||||||
sum += rank.second;
|
sum += rank.second;
|
||||||
}
|
}
|
||||||
@ -250,22 +248,21 @@ namespace platform {
|
|||||||
for (const auto& rank : ranks) {
|
for (const auto& rank : ranks) {
|
||||||
sumSquared += rank.second * rank.second;
|
sumSquared += rank.second * rank.second;
|
||||||
}
|
}
|
||||||
cout << "Sum Squared: " << sumSquared << endl;
|
double friedmanQ = 12.0 / (nModels * nDatasets * (nModels + 1)) * sumSquared - 3 * nDatasets * (nModels + 1);
|
||||||
cout << "Degrees of freedom: " << degreesOfFreedom << endl;
|
cout << "Friedman statistic: " << friedmanQ << endl;
|
||||||
double friedman = 12.0 / (nModels * nDatasets * (nModels + 1)) * sumSquared - 3 * nDatasets * (nModels + 1);
|
|
||||||
cout << "Friedman statistic: " << friedman << endl;
|
|
||||||
// Calculate the critical value
|
// Calculate the critical value
|
||||||
boost::math::chi_squared chiSquared(degreesOfFreedom);
|
boost::math::chi_squared chiSquared(degreesOfFreedom);
|
||||||
long double p_value = (long double)1.0 - cdf(chiSquared, friedman);
|
long double p_value = (long double)1.0 - cdf(chiSquared, friedmanQ);
|
||||||
double criticalValue = quantile(chiSquared, 1 - significance);
|
double criticalValue = quantile(chiSquared, 1 - significance);
|
||||||
std::cout << "Critical Chi-Square Value for df=" << degreesOfFreedom
|
std::cout << "Critical Chi-Square Value for df=" << fixed << (int)degreesOfFreedom
|
||||||
<< " and alpha=" << significance << ": " << criticalValue << std::endl;
|
<< " and alpha=" << significance << ": " << criticalValue << std::endl;
|
||||||
cout << "p-value: " << scientific << p_value << endl;
|
cout << "p-value: " << scientific << p_value << endl;
|
||||||
if (friedman > criticalValue) {
|
if (friedmanQ > criticalValue) {
|
||||||
cout << Colors::MAGENTA() << "The null hypothesis H0 is rejected." << endl;
|
cout << Colors::MAGENTA() << "The null hypothesis H0 is rejected." << endl;
|
||||||
} else {
|
} else {
|
||||||
cout << Colors::GREEN() << "The null hypothesis H0 is accepted." << endl;
|
cout << Colors::GREEN() << "The null hypothesis H0 is accepted." << endl;
|
||||||
}
|
}
|
||||||
|
cout << Colors::BLUE() << "*************************************************************************************" << endl;
|
||||||
}
|
}
|
||||||
void BestResults::printTableResults(set<string> models, json table)
|
void BestResults::printTableResults(set<string> models, json table)
|
||||||
{
|
{
|
||||||
@ -371,7 +368,9 @@ namespace platform {
|
|||||||
cout << efectiveColor << setw(12) << setprecision(9) << fixed << (double)ranksTotal[model] / (double)origin.size() << " ";
|
cout << efectiveColor << setw(12) << setprecision(9) << fixed << (double)ranksTotal[model] / (double)origin.size() << " ";
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
friedmanTest(models.size(), table.begin().value().size(), ranksTotal, 0.05);
|
if (friedman) {
|
||||||
|
friedmanTest(models.size(), table.begin().value().size(), ranksTotal, 0.05);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void BestResults::reportAll()
|
void BestResults::reportAll()
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@ using json = nlohmann::json;
|
|||||||
namespace platform {
|
namespace platform {
|
||||||
class BestResults {
|
class BestResults {
|
||||||
public:
|
public:
|
||||||
explicit BestResults(const string& path, const string& score, const string& model) : path(path), score(score), model(model) {}
|
explicit BestResults(const string& path, const string& score, const string& model, bool friedman) : path(path), score(score), model(model), friedman(friedman) {}
|
||||||
string build();
|
string build();
|
||||||
void reportSingle();
|
void reportSingle();
|
||||||
void reportAll();
|
void reportAll();
|
||||||
@ -23,6 +23,7 @@ namespace platform {
|
|||||||
string path;
|
string path;
|
||||||
string score;
|
string score;
|
||||||
string model;
|
string model;
|
||||||
|
bool friedman;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif //BESTRESULTS_H
|
#endif //BESTRESULTS_H
|
@ -13,12 +13,14 @@ argparse::ArgumentParser manageArguments(int argc, char** argv)
|
|||||||
program.add_argument("-s", "--score").default_value("").help("Filter results of the score name supplied");
|
program.add_argument("-s", "--score").default_value("").help("Filter results of the score name supplied");
|
||||||
program.add_argument("--build").help("build best score results file").default_value(false).implicit_value(true);
|
program.add_argument("--build").help("build best score results file").default_value(false).implicit_value(true);
|
||||||
program.add_argument("--report").help("report of best score results file").default_value(false).implicit_value(true);
|
program.add_argument("--report").help("report of best score results file").default_value(false).implicit_value(true);
|
||||||
|
program.add_argument("--friedman").help("Friedman test").default_value(false).implicit_value(true);
|
||||||
try {
|
try {
|
||||||
program.parse_args(argc, argv);
|
program.parse_args(argc, argv);
|
||||||
auto model = program.get<string>("model");
|
auto model = program.get<string>("model");
|
||||||
auto score = program.get<string>("score");
|
auto score = program.get<string>("score");
|
||||||
auto build = program.get<bool>("build");
|
auto build = program.get<bool>("build");
|
||||||
auto report = program.get<bool>("report");
|
auto report = program.get<bool>("report");
|
||||||
|
auto friedman = program.get<bool>("friedman");
|
||||||
if (model == "" || score == "") {
|
if (model == "" || score == "") {
|
||||||
throw runtime_error("Model and score name must be supplied");
|
throw runtime_error("Model and score name must be supplied");
|
||||||
}
|
}
|
||||||
@ -38,12 +40,18 @@ int main(int argc, char** argv)
|
|||||||
auto score = program.get<string>("score");
|
auto score = program.get<string>("score");
|
||||||
auto build = program.get<bool>("build");
|
auto build = program.get<bool>("build");
|
||||||
auto report = program.get<bool>("report");
|
auto report = program.get<bool>("report");
|
||||||
|
auto friedman = program.get<bool>("friedman");
|
||||||
|
if (friedman && model != "any") {
|
||||||
|
cerr << "Friedman test can only be used with all models" << endl;
|
||||||
|
cerr << program;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
if (!report && !build) {
|
if (!report && !build) {
|
||||||
cerr << "Either build, report or both, have to be selected to do anything!" << endl;
|
cerr << "Either build, report or both, have to be selected to do anything!" << endl;
|
||||||
cerr << program;
|
cerr << program;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
auto results = platform::BestResults(platform::Paths::results(), score, model);
|
auto results = platform::BestResults(platform::Paths::results(), score, model, friedman);
|
||||||
if (build) {
|
if (build) {
|
||||||
if (model == "any") {
|
if (model == "any") {
|
||||||
results.buildAll();
|
results.buildAll();
|
||||||
|
Loading…
Reference in New Issue
Block a user