繁体   English   中英

套袋分类器在逻辑回归中的功能重要性

[英]Feature importance in logistic regression with bagging classifier

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

几行代码如下:

    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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM