CatBoost特征重要性手动计算与API结果不符,求排查错误
问题:CatBoost特征重要性手动计算与API结果不符
背景
我训练了一个仅含3棵树的简单二分类模型,希望验证特征重要性结果是否符合CatBoost文档中的PredictionValuesChange公式。训练后按照CatBoost JSON模型教程导出了树结构:
{ "leaf_values": [ -0.13915912880676032, 0.1097787155963716 ], "leaf_weights": [ 2143.0251545906067, 2252.974784851074 ], "splits": [ { "border": 3.5, "float_feature_index": 13, "split_index": 0, "split_type": "FloatFeature" } ] }
模型中每棵树深度均为1,仅索引为1的树用到目标特征。我按照上述公式手动计算特征重要性,并与.get_feature_importance方法的结果对比,发现二者差异显著:
- API返回的特征重要性:28.2947825
- 手动计算值:68.06248029261762
以下是我用于特征重要性计算的代码:
tree_indx = 1 v_1 = model['oblivious_trees'][tree_indx]['leaf_values'][0] v_2 = model['oblivious_trees'][tree_indx]['leaf_values'][1] c_1 = model['oblivious_trees'][tree_indx]['leaf_weights'][0] c_2 = model['oblivious_trees'][tree_indx]['leaf_weights'][1] avr = (v_1*c_1 + v_2*c_2)/(c_1+c_2) fi = ((v_1 - avr)**2)*c_1 + ((v_2 - avr)**2)*c_2 print(fi)
请问我哪里出错了?
内容的提问来源于stack exchange,提问作者Mageentta
相关产品推荐
相关产品推荐

