MCPcopy Create free account
hub / github.com/catboost/catboost / CheckPreprocessedTarget

Function CheckPreprocessedTarget

catboost/libs/metrics/metric.cpp:7002–7035  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7000}
7001
7002void CheckPreprocessedTarget(
7003 TConstArrayRef<float> target,
7004 const NCatboostOptions::TLossDescription& lossDesciption,
7005 bool isNonEmptyAndNonConst,
7006 bool allowConstLabel
7007) {
7008 ELossFunction lossFunction = lossDesciption.GetLossFunction();
7009 if (isNonEmptyAndNonConst && (lossFunction != ELossFunction::PairLogit) && (lossFunction != ELossFunction::PairLogitPairwise)) {
7010 auto targetBounds = CalcMinMax(target);
7011 CB_ENSURE((targetBounds.Min != targetBounds.Max) || allowConstLabel, "All train targets are equal");
7012 }
7013 if (EqualToOneOf(lossFunction, ELossFunction::CrossEntropy, ELossFunction::PFound, ELossFunction::ERR)) {
7014 auto targetBounds = CalcMinMax(target);
7015 CB_ENSURE(targetBounds.Min >= 0, "Min target less than 0: " + ToString(targetBounds.Min));
7016 CB_ENSURE(targetBounds.Max <= 1, "Max target greater than 1: " + ToString(targetBounds.Max));
7017 }
7018
7019 if (lossFunction == ELossFunction::QuerySoftMax) {
7020 float minTarget = *MinElement(target.begin(), target.end());
7021 CB_ENSURE(minTarget >= 0, "Min target less than 0: " + ToString(minTarget));
7022 }
7023
7024 if (IsMultiClassOnlyMetric(lossFunction)) {
7025 CB_ENSURE(AllOf(target, [](float x) { return int(x) == x && x >= 0; }),
7026 "metric/loss-function " << lossFunction << " is a Multiclassification metric, "
7027 " each target label should be a nonnegative integer");
7028 }
7029
7030 if (lossFunction != ELossFunction::MultiRMSEWithMissingValues) {
7031 for (auto objectIdx : xrange(target.size())){
7032 CB_ENSURE(!IsNan(target[objectIdx]), "metric/loss-function " << lossFunction << " does not allow nan values in target data");
7033 }
7034 }
7035}
7036
7037static EMetricBestValue GetOptimumType(TStringBuf lossFunction) {
7038 const auto metric = CreateMetricsFromDescription({TString(lossFunction)}, /*approxDim*/ 1);

Callers

nothing calls this directly

Calls 12

CalcMinMaxFunction · 0.85
EqualToOneOfFunction · 0.85
MinElementFunction · 0.85
IsMultiClassOnlyMetricFunction · 0.85
xrangeFunction · 0.85
ToStringFunction · 0.50
AllOfFunction · 0.50
IsNanFunction · 0.50
GetLossFunctionMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected