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

Function CalcFeatureEffectAverageChange

catboost/libs/fstr/calc_fstr.cpp:94–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94TVector<std::pair<double, TFeature>> CalcFeatureEffectAverageChange(
95 const TFullModel& model,
96 TConstArrayRef<double> weights)
97{
98 if (model.GetTreeCount() == 0) {
99 return TVector<std::pair<double, TFeature>>();
100 }
101 TVector<double> effect;
102 TVector<TFeature> features;
103
104 THashMap<TFeature, int, TFeatureHash> featureToIdx = GetFeatureToIdxMap(model, &features);
105 if (model.IsOblivious()) {
106 TVector<TMxTree> trees = BuildTrees(featureToIdx, model);
107
108 TVector<TConstArrayRef<double>> mxTreeWeightsPresentation;
109 auto applyData = model.ModelTrees->GetApplyData();
110 auto leafOffsetPtr = applyData->TreeFirstLeafOffsets.data();
111 const auto leafSizes = model.ModelTrees->GetModelTreeData()->GetTreeSizes();
112 const int approxDimension = model.ModelTrees->GetDimensionsCount();
113 for (size_t treeIdx = 0; treeIdx < model.GetTreeCount(); ++treeIdx) {
114 mxTreeWeightsPresentation.push_back(
115 TConstArrayRef<double>(
116 weights.data() + leafOffsetPtr[treeIdx] / approxDimension,
117 (1ull << leafSizes[treeIdx])
118 )
119 );
120 }
121 effect = CalcEffect(
122 trees,
123 mxTreeWeightsPresentation
124 );
125 } else {
126 effect = CalcEffectForNonObliviousModel(
127 model,
128 featureToIdx,
129 weights
130 );
131 }
132
133 TVector<std::pair<double, int>> effectWithFeature;
134 for (int i = 0; i < effect.ysize(); ++i) {
135 effectWithFeature.emplace_back(effect[i], i);
136 }
137 StableSort(effectWithFeature.begin(), effectWithFeature.end(), std::greater<std::pair<double, int>>());
138
139 TVector<std::pair<double, TFeature>> result;
140 for (int i = 0; i < effectWithFeature.ysize(); ++i) {
141 result.emplace_back(effectWithFeature[i].first, features[effectWithFeature[i].second]);
142 }
143 return result;
144}
145
146static TVector<std::pair<double, TFeature>> CalcFeatureEffectAverageChange(
147 const TFullModel& model,

Callers 2

CalcFeatureEffectFunction · 0.85

Calls 15

GetFeatureToIdxMapFunction · 0.85
BuildTreesFunction · 0.85
CalcEffectFunction · 0.85
StableSortFunction · 0.85
CollectLeavesStatisticsFunction · 0.85
GetApplyDataMethod · 0.80
GetTreeSizesMethod · 0.80
GetLeafWeightsMethod · 0.80
GetTreeCountMethod · 0.45
IsObliviousMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected