gpt4 book ai didi

python - 带装袋分类器的逻辑回归中的特征重要性

转载 作者:行者123 更新时间:2023-11-30 21:59:41 26 4
gpt4 key购买 nike

我正在研究一个二元分类问题,我在装袋分类器中使用逻辑回归。

几行代码如下:-

    model = BaggingClassifier(LogisticRegression(), 
n_estimators=10,
bootstrap = True, random_state = 1)
model.fit(X,y,sample_weights)

我有兴趣了解该模型的特征重要性指标。如果装袋分类器的估计器是逻辑回归,该怎么办?

当决策树用作装袋分类器的估计器时,我能够获得特征重要性。其代码如下:-

    feature_importances = np.mean([tree.feature_importances_ for tree in  model.estimators_], axis=0)

最佳答案

您无法直接推断线性分类器的特征重要性。另一方面,您可以做的是查看其系数的大小。您可以通过以下方式做到这一点:

# Get an average of the model coefficients
model_coeff = np.mean([lr.coef_ for lr in model.estimators_], axis=0)
# Multiply the model coefficients by the standard deviation of the data
coeff_magnitude = np.std(X, 0) * model_coeff

这将大致告诉您每个系数的重要性。换句话说,一个值 >> 0表明该系数倾向于捕获正类和值 << 0表明该系数集中于正类。

<小时/>

以下是基于您在评论中提供的值的示例代码:

X_train = np.random.rand(2000, 3)
X_train.shape
# (2000, 3)
model_coeff = [[2.233232, 1.22435, 1.433434]]
coeff_magnitude = np.std(X_train, 0) * model_coeff
coeff_magnitude.shape
# (1, 3)

关于python - 带装袋分类器的逻辑回归中的特征重要性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54519113/

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