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

Function BestSplit

library/cpp/grid_creator/binarization.cpp:74–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72namespace NSplitSelection {
73
74 TQuantization BestSplit(
75 TFeatureValues&& features,
76 bool featureValuesMayContainNans,
77 int maxBordersCount,
78 EBorderSelectionType type,
79 TMaybe<float> quantizedDefaultBinFraction,
80 const TMaybe<TVector<float>>& initialBorders
81 ) {
82 if (features.DefaultValue && IsNan(features.DefaultValue->Value)) {
83 if (featureValuesMayContainNans) {
84 features.DefaultValue = Nothing();
85 } else {
86 throw (yexception() << "Unexpected Nan value.");
87 }
88 }
89
90 auto firstNanPos = std::remove_if(features.Values.begin(), features.Values.end(), IsNan);
91 if (firstNanPos != features.Values.end()) {
92 if (featureValuesMayContainNans) {
93 features.Values.erase(firstNanPos, features.Values.end());
94 } else {
95 throw (yexception() << "Unexpected Nan value.");
96 }
97 }
98
99 if (quantizedDefaultBinFraction) {
100 Y_ENSURE(
101 (*quantizedDefaultBinFraction >= 0.0f) && (*quantizedDefaultBinFraction < 1.0f),
102 LabeledOutput(quantizedDefaultBinFraction) << " is not in required [0, 1) bounds"
103 );
104 }
105
106 if (features.Values.empty()) {
107 return {};
108 }
109
110 const auto binarizer = MakeBinarizer(type);
111 return binarizer->BestSplit(std::move(features), maxBordersCount, quantizedDefaultBinFraction, initialBorders);
112 }
113
114 THolder<IBinarizer> MakeBinarizer(const EBorderSelectionType type) {
115 switch (type) {

Callers

nothing calls this directly

Calls 15

NothingFunction · 0.85
yexceptionClass · 0.85
MakeBinarizerFunction · 0.85
TFeatureValuesClass · 0.85
MakeArrayRefFunction · 0.85
LowerBoundFunction · 0.85
BestSplitMethod · 0.80
IsNanFunction · 0.50
moveFunction · 0.50
MaxFunction · 0.50
make_tupleFunction · 0.50
MinFunction · 0.50

Tested by

no test coverage detected