| 671 | } |
| 672 | |
| 673 | EXPORT_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(); |
nothing calls this directly
no test coverage detected