Skip to content

[7.9][ML] Fix weights to maximize minimum recall for multiclass classification #1235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/maths/CDataFrameUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,8 @@ CDataFrameUtils::maximizeMinimumRecallForMulticlass(std::size_t numberThreads,
using TMinAccumulator = CBasicStatistics::SMin<double>::TAccumulator;

CPRNG::CXorOShiro128Plus rng;
std::size_t numberSamples{std::min(std::size_t{1000}, rowMask.size())};
std::size_t numberSamples{
static_cast<std::size_t>(std::min(1000.0, rowMask.manhattan()))};

TStratifiedSamplerPtr sampler;
std::tie(sampler, std::ignore) = classifierStratifiedCrossValidationRowSampler(
Expand Down Expand Up @@ -1168,7 +1169,8 @@ CDataFrameUtils::maximizeMinimumRecallForMulticlass(std::size_t numberThreads,
};

TDoubleVector objective_;
doReduce(frame.readRows(numberThreads, 0, frame.numberRows(), computeObjective, &rowMask),
doReduce(frame.readRows(numberThreads, 0, frame.numberRows(),
computeObjective, &sampleMask),
copyObjective, reduceObjective, objective_);
return objective_.maxCoeff();
};
Expand Down Expand Up @@ -1203,7 +1205,7 @@ CDataFrameUtils::maximizeMinimumRecallForMulticlass(std::size_t numberThreads,

TDoubleMatrix objectiveAndGradient;
doReduce(frame.readRows(numberThreads, 0, frame.numberRows(),
computeObjectiveAndGradient, &rowMask),
computeObjectiveAndGradient, &sampleMask),
copyObjectiveAndGradient, reduceObjectiveAndGradient, objectiveAndGradient);
std::size_t max;
objectiveAndGradient.col(0).maxCoeff(&max);
Expand Down
4 changes: 2 additions & 2 deletions lib/maths/unittest/CDataFrameUtilsTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1308,8 +1308,8 @@ BOOST_AUTO_TEST_CASE(testMaximumMinimumRecallClassWeights) {
BOOST_TEST_REQUIRE(minRecalls[0][0] > 1.1 * minRecalls[0][1]);

// The minimum and maximum class recalls are close: we're at the global maximum.
BOOST_TEST_REQUIRE(1.02 * minRecalls[0][0] > maxRecalls[0][0]);
BOOST_TEST_REQUIRE(1.02 * minRecalls[1][0] > maxRecalls[1][0]);
BOOST_TEST_REQUIRE(1.06 * minRecalls[0][0] > maxRecalls[0][0]);
BOOST_TEST_REQUIRE(1.06 * minRecalls[1][0] > maxRecalls[1][0]);
}
}

Expand Down