| 7000 | } |
| 7001 | |
| 7002 | void 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 | |
| 7037 | static EMetricBestValue GetOptimumType(TStringBuf lossFunction) { |
| 7038 | const auto metric = CreateMetricsFromDescription({TString(lossFunction)}, /*approxDim*/ 1); |
nothing calls this directly
no test coverage detected