Complete Folding Test
This commit is contained in:
@@ -22,7 +22,8 @@ TEST_CASE("Metrics Test", "[BayesNet]")
|
||||
{"diabetes", 0.0345470614}
|
||||
};
|
||||
map<string, vector<pair<int, int>>> resultsMST = {
|
||||
{"glass", {{0,6}, {0,5}, {0,3}, {6,2}, {6,7}, {5,1}, {5,8}, {5,4}}},
|
||||
//{"glass", {{0,6}, {0,5}, {0,3}, {6,2}, {6,7}, {5,1}, {5,8}, {5,4}}},
|
||||
{"glass", {{0,6}, {0,5}, {0,3}, {5,1}, {5,8}, {5,4}, {6,2}, {6,7}}},
|
||||
{"iris", {{0,1},{0,2},{1,3}}},
|
||||
{"ecoli", {{0,1}, {0,2}, {1,5}, {1,3}, {5,6}, {5,4}}},
|
||||
{"diabetes", {{0,7}, {0,2}, {0,6}, {2,3}, {3,4}, {3,5}, {4,1}}}
|
||||
|
@@ -66,27 +66,28 @@ TEST_CASE("StratifiedKFold Test", "[Platform][StratifiedKFold]")
|
||||
auto [train_indicesv, test_indicesv] = stratified_kfoldv.getFold(fold);
|
||||
REQUIRE(train_indicest == train_indicesv);
|
||||
REQUIRE(test_indicest == test_indicesv);
|
||||
bool result = train_indicest.size() == number || train_indicest.size() == number + 1;
|
||||
REQUIRE(result);
|
||||
REQUIRE(train_indicest.size() + test_indicest.size() == raw.nSamples);
|
||||
// In the worst case scenario, the number of samples in the training set is number + raw.classNumStates
|
||||
// because in that fold can come one remainder sample from each class.
|
||||
REQUIRE(train_indicest.size() <= number + raw.classNumStates);
|
||||
// If the number of samples in any class is less than the number of folds, then the fold is faulty.
|
||||
// and the number of samples in the training set + test set will be less than nSamples
|
||||
if (!stratified_kfoldt.isFaulty()) {
|
||||
REQUIRE(train_indicest.size() + test_indicest.size() == raw.nSamples);
|
||||
} else {
|
||||
REQUIRE(train_indicest.size() + test_indicest.size() <= raw.nSamples);
|
||||
}
|
||||
auto train_t = torch::tensor(train_indicest);
|
||||
auto ytrain = raw.yt.index({ train_t });
|
||||
cout << "dataset=" << file_name << endl;
|
||||
cout << "nSamples=" << raw.nSamples << endl;;
|
||||
cout << "number=" << number << endl;
|
||||
cout << "train_indices.size()=" << train_indicest.size() << endl;
|
||||
cout << "test_indices.size()=" << test_indicest.size() << endl;
|
||||
cout << "Class Name = " << raw.classNamet << endl;
|
||||
// Check that the class labels have been equally assign to each fold
|
||||
for (const auto& idx : train_indicest) {
|
||||
counts[fold][ytrain[idx].item<int>()]++;
|
||||
counts[fold][raw.yt[idx].item<int>()]++;
|
||||
}
|
||||
}
|
||||
// Test the fold counting of every class
|
||||
for (int fold = 0; fold < nFolds; ++fold) {
|
||||
for (int j = 1; j < nFolds - 1; ++j) {
|
||||
for (int k = 0; k < raw.classNumStates; ++k) {
|
||||
REQUIRE(abs(counts.at(fold).at(k) - counts.at(fold).at(j)) <= 1);
|
||||
REQUIRE(abs(counts.at(fold).at(k) - counts.at(j).at(k)) <= 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user