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

Function SplitByClass

catboost/libs/data/objects_grouping.h:257–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255
256 template <class TClassId>
257 TVector<TVector<ui32>> SplitByClass(
258 const TObjectsGrouping& objectsGrouping,
259 TConstArrayRef<TClassId> objectClasses
260 ) {
261 CB_ENSURE(objectsGrouping.IsTrivial(), "Stratified split is not supported for data with groups");
262
263 const ui32 objectCount = objectsGrouping.GetObjectCount();
264
265 CheckDataSize(
266 objectClasses.size(),
267 (size_t)objectCount,
268 "objectClasses",
269 false,
270 "objects size",
271 true
272 );
273
274 TVector<std::pair<TClassId, ui32>> classWithObject;
275 classWithObject.reserve(objectCount);
276 for (ui32 i = 0; i < objectCount; ++i) {
277 classWithObject.emplace_back(objectClasses[i], i);
278 }
279 Sort(classWithObject.begin(), classWithObject.end());
280
281 TVector<TVector<ui32>> splittedByClass;
282 for (ui32 i = 0; i < classWithObject.size(); ++i) {
283 if (i == 0 || classWithObject[i].first != classWithObject[i - 1].first) {
284 splittedByClass.emplace_back();
285 }
286 splittedByClass.back().push_back(classWithObject[i].second);
287 }
288
289 return splittedByClass;
290 }
291
292 template <class TClassId>
293 void StratifiedTrainTestSplit(

Callers 2

StratifiedTrainTestSplitFunction · 0.85
StratifiedSplitToFoldsFunction · 0.85

Calls 11

CheckDataSizeFunction · 0.85
SortFunction · 0.50
IsTrivialMethod · 0.45
GetObjectCountMethod · 0.45
sizeMethod · 0.45
reserveMethod · 0.45
emplace_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected