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

Function TrainModel

catboost/libs/train_lib/train_model.cpp:950–1178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

948TTrainerFactory::TRegistrator<TCPUModelTrainer> CPURegistrator(ETaskType::CPU);
949
950static void TrainModel(
951 const NJson::TJsonValue& trainOptionsJson,
952 const NCatboostOptions::TOutputFilesOptions& outputOptions,
953 TQuantizedFeaturesInfoPtr quantizedFeaturesInfo,
954 const TMaybe<TCustomObjectiveDescriptor>& objectiveDescriptor,
955 const TMaybe<TCustomMetricDescriptor>& evalMetricDescriptor,
956 const TMaybe<TCustomCallbackDescriptor>& callbackDescriptor,
957 TDataProviders pools,
958
959 // can be non-empty only if there is single fold
960 TMaybe<TPrecomputedOnlineCtrData> precomputedSingleOnlineCtrDataForSingleFold,
961 TMaybe<TFullModel*> initModel,
962 THolder<TLearnProgress> initLearnProgress,
963 const NCatboostOptions::TPoolLoadParams* poolLoadOptions,
964 const TString& outputModelPath,
965 TFullModel* dstModel,
966 const TVector<TEvalResult*>& evalResultPtrs, // can be empty - do not compute in this case
967 TMetricsAndTimeLeftHistory* metricsAndTimeHistory,
968 THolder<TLearnProgress>* dstLearnProgress,
969 NPar::ILocalExecutor* const executor)
970{
971 CB_ENSURE(pools.Learn != nullptr, "Train data must be provided");
972 CB_ENSURE((evalResultPtrs.size() == 0) || (pools.Test.size() == evalResultPtrs.size()));
973
974 THolder<IModelTrainer> modelTrainerHolder;
975
976 const ETaskType taskType = NCatboostOptions::GetTaskType(trainOptionsJson);
977
978 CB_ENSURE(
979 (taskType == ETaskType::CPU) || (pools.Test.size() <= 1),
980 "Multiple eval sets not supported for GPU"
981 );
982
983 NCatboostOptions::TOutputFilesOptions updatedOutputOptions(outputOptions);
984 if (outputModelPath) {
985 updatedOutputOptions.ResultModelPath = outputModelPath;
986 }
987
988 NJson::TJsonValue updatedTrainOptionsJson = trainOptionsJson;
989
990 const bool isGpuDeviceType = taskType == ETaskType::GPU;
991 if (isGpuDeviceType && TTrainerFactory::Has(ETaskType::GPU)) {
992 modelTrainerHolder.Reset(TTrainerFactory::Construct(ETaskType::GPU));
993 } else {
994 CB_ENSURE(!isGpuDeviceType, "Can't load GPU learning library. Module was not compiled or driver is incompatible with package. Please install latest NVDIA driver and check again");
995 modelTrainerHolder.Reset(TTrainerFactory::Construct(ETaskType::CPU));
996 }
997
998 if (outputOptions.SaveSnapshot()) {
999 UpdateUndefinedRandomSeed(taskType, updatedOutputOptions, &updatedTrainOptionsJson, [&](IInputStream* in, TString& params) {
1000 ::Load(in, params);
1001 });
1002 }
1003
1004 const auto learnFeaturesLayout = pools.Learn->MetaInfo.FeaturesLayout;
1005
1006 NCatboostOptions::TCatBoostOptions catBoostOptions(taskType);
1007 catBoostOptions.Load(updatedTrainOptionsJson);

Callers 14

ModeFitImplMethod · 0.50
Y_UNIT_TESTFunction · 0.50
Y_UNIT_TESTFunction · 0.50
Y_UNIT_TESTFunction · 0.50
TrainModelOnPoolFunction · 0.50
Y_UNIT_TESTFunction · 0.50
TrainFloatCatboostModelFunction · 0.50
DefaultTrainCatOnlyModelFunction · 0.50
TrainCatBoostFunction · 0.50
Y_UNIT_TESTFunction · 0.50

Calls 15

HasFunction · 0.85
IsPairLogitFunction · 0.85
xrangeFunction · 0.85
ShuffleLearnDataIfNeededFunction · 0.85
HaveFeaturesInMemoryFunction · 0.85
MakeMaybeFunction · 0.85
NothingFunction · 0.85

Tested by 2

TrainFloatCatboostModelFunction · 0.40
DefaultTrainCatOnlyModelFunction · 0.40