gpt4 book ai didi

python - 这个 "score"到底是什么?使用 sklearn/Python 的额外树分类器

转载 作者:行者123 更新时间:2023-11-30 09:26:38 25 4
gpt4 key购买 nike

我使用 ExtraTreesClassifier 来找出数据集中哪些属性更重要。结果,它返回给我一个分数值(例如每个属性都有一个分数,如 0.0370.0250.012 等),这个分数到底意味着什么?

编辑:我实际上正在搜索它是如何计算的?哪个公式给我评分?

model = ExtraTreesClassifier()
model.fit(dataValues, dataTargetEncoded)

feat_importances = pd.Series(model.feature_importances_,index=dataValues.columns)
feat_importances.nlargest(25).plot(kind='barh')
plt.show()

最佳答案

分数本身是在 feature_importances_ 中计算的BaseForest 类。它们的计算方式为

np.mean(all_importances, axis=0, dtype=np.float64) / np.sum(all_importances)

其中 all_importancesExtraTreesClassifier 估计器的 feature_importances_ 数组。估计器的数量由参数n_estimators定义ExtraTreesClassifier。默认有 10 个估计器(n_estimators 的默认值将从 0.20 版本中的 10 更改为 0.22 版本中的 100):

est = [estimator for estimator in model.estimators_]

est[0]
Out[57]:
ExtraTreeClassifier(class_weight=None, criterion='gini', max_depth=None,
max_features='auto', max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, random_state=1045388471,
splitter='random')

len(est)
Out[58]: 10

因此,all_importances 看起来像

[x.feature_importances_ for x in est]
Out[59]:
[array([0., 0., 1.]),
array([0., 0., 1.]),
array([0., 0., 1.]),
array([0.33333333, 0. , 0.66666667]),
array([0.11111111, 0.88888889, 0. ]),
array([0., 1., 0.]),
array([0., 0., 1.]),
array([0., 1., 0.]),
array([0., 0., 1.]),
array([0.33333333, 0.66666667, 0. ])]
每个估计器的

feature_importances_compute_feature_importances 计算方法Tree在 Cython 上编写的类。它是通过迭代树节点的每个节点并添加相应的特征来计算的:

feature_importances_[node.feature] += node.weighted_n_node_samples * node.impurity -
left.weighted_n_node_samples * left.impurity -
right.weighted_n_node_samples * right.impurity

其中 weighted_n_node_samplesimpurity 是带有节点参数的数组:

est[0].tree_.feature
Out[60]: array([ 2, 2, -2, -2, -2], dtype=int64)

est[0].tree_.weighted_n_node_samples
Out[61]: array([4., 2., 1., 1., 2.])

est[0].tree_.impurity
Out[62]: array([0.375, 0.5 , 0. , 0. , 0. ])

feature_importances_ 计算后进行归一化。您可以通过使用参数 normalize=False 调用 compute_feature_importances 来查看原始值:

est[3].tree_.compute_feature_importances(normalize=False)
Out[63]: array([0.125, 0. , 0.25 ])

est[3].tree_.compute_feature_importances()
Out[64]: array([0.33333333, 0. , 0.66666667])

关于python - 这个 "score"到底是什么?使用 sklearn/Python 的额外树分类器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57094596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com