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

Function GetFeatureImportances

catboost/libs/fstr/calc_fstr.cpp:469–550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

467
468
469TVector<TVector<double>> GetFeatureImportances(
470 const EFstrType fstrType,
471 const TFullModel& model,
472 const TDataProviderPtr dataset, // can be nullptr
473 const TDataProviderPtr referenceDataset, // can be nullptr
474 int threadCount,
475 EPreCalcShapValues mode,
476 int logPeriod,
477 ECalcTypeShapValues calcType,
478 EExplainableModelOutput modelOutputType,
479 size_t sageNSamples,
480 size_t sageBatchSize,
481 bool sageDetectConvergence)
482{
483 TSetLoggingVerboseOrSilent inThisScope(logPeriod);
484 CB_ENSURE(model.GetTreeCount(), "Model is not trained");
485 if (dataset) {
486 CheckModelAndDatasetCompatibility(model, *dataset->ObjectsData.Get());
487 }
488 if (fstrType != EFstrType::PredictionValuesChange) {
489 CB_ENSURE_SCALE_IDENTITY(model.GetScaleAndBias(), "feature importance");
490 }
491 switch (fstrType) {
492 case EFstrType::PredictionValuesChange:
493 case EFstrType::LossFunctionChange:
494 case EFstrType::FeatureImportance: {
495 NPar::TLocalExecutor localExecutor;
496 localExecutor.RunAdditionalThreads(threadCount - 1);
497
498 return CalcFstr(model, dataset, fstrType, &localExecutor, calcType);
499 }
500 case EFstrType::Interaction:
501 if (dataset) {
502 CATBOOST_NOTICE_LOG << "Dataset is provided, but not used, because importance values are"
503 " cached in the model." << Endl;
504 }
505 return CalcInteraction(model);
506 case EFstrType::ShapValues: {
507 CB_ENSURE(dataset, "Dataset is not provided");
508
509 NPar::TLocalExecutor localExecutor;
510 localExecutor.RunAdditionalThreads(threadCount - 1);
511
512 return CalcShapValues(
513 model,
514 *dataset,
515 referenceDataset,
516 /*fixedFeatureParams*/ Nothing(),
517 logPeriod,
518 mode,
519 &localExecutor,
520 calcType,
521 modelOutputType
522 );
523 }
524 case EFstrType::SageValues: {
525 CB_ENSURE(dataset, "Dataset is not provided");
526

Callers 1

Calls 10

CalcFstrFunction · 0.85
CalcShapValuesFunction · 0.85
NothingFunction · 0.85
CalcSageValuesFunction · 0.85
GetPredictionDiffFunction · 0.85
RunAdditionalThreadsMethod · 0.80
CalcInteractionFunction · 0.70
GetTreeCountMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected