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

Function CatBoostCV_R

catboost/R-package/src/catboostr.cpp:673–772  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

671}
672
673EXPORT_FUNCTION CatBoostCV_R(SEXP fitParamsAsJsonParam,
674 SEXP poolParam,
675 SEXP foldCountParam,
676 SEXP typeParam,
677 SEXP partitionRandomSeedParam,
678 SEXP shuffleParam,
679 SEXP stratifiedParam) {
680
681 SEXP result = NULL;
682 size_t metricCount;
683 size_t columnCount;
684
685 R_API_BEGIN();
686 TPoolPtr pool = static_cast<TPoolHandle>(R_ExternalPtrAddr(poolParam));
687 pool->Ref();
688 auto fitParams = LoadFitParams(fitParamsAsJsonParam);
689
690 TCrossValidationParams cvParams;
691 cvParams.FoldCount = asInteger(foldCountParam);
692 cvParams.PartitionRandSeed = asInteger(partitionRandomSeedParam);
693 cvParams.Shuffle = asLogical(shuffleParam);
694 cvParams.Stratified = asLogical(stratifiedParam);
695
696 CB_ENSURE(TryFromString<ECrossValidation>(CHAR(asChar(typeParam)), cvParams.Type),
697 "unsupported type of cross_validation: 'Classical', 'Inverted' or 'TimeSeries' was expected");
698
699 TVector<TCVResult> cvResults;
700
701 CrossValidate(
702 fitParams,
703 TQuantizedFeaturesInfoPtr(nullptr),
704 Nothing(),
705 Nothing(),
706 pool,
707 cvParams,
708 &cvResults);
709
710 metricCount = cvResults.size();
711 TVector<size_t> offsets(metricCount);
712
713 columnCount = 0;
714 size_t currentColumnCount = 0;
715 for (size_t metricIdx = 0; metricIdx < metricCount; ++metricIdx) {
716 offsets[metricIdx] = columnCount;
717 if (cvResults[metricIdx].AverageTrain.size() == 0) {
718 currentColumnCount = 2;
719 } else {
720 currentColumnCount = 4;
721 }
722 columnCount += currentColumnCount;
723 }
724
725 result = PROTECT(allocVector(VECSXP, columnCount));
726 SEXP columnNames = PROTECT(allocVector(STRSXP, columnCount));
727
728 for (size_t metricIdx = 0; metricIdx < metricCount; ++metricIdx) {
729 TString metricName = cvResults[metricIdx].Metric;
730 size_t numberOfIterations = cvResults[metricIdx].Iterations.size();

Callers

nothing calls this directly

Calls 6

LoadFitParamsFunction · 0.85
CrossValidateFunction · 0.85
NothingFunction · 0.85
RefMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected