| 467 | |
| 468 | |
| 469 | TVector<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 |
no test coverage detected