如何使用 sklearn 的 AdaBoostClassifier 获取模型的系数(以逻辑回归为基础估计器)

How to get the coefficients of the model using sklearn's AdaBoostClassifier (with Logistic regression as the base estimator)

我已经使用 scikit-learn 的 AdaBoostClassifier with Logistic regression 作为基础估算器构建了一个模型。

model = AdaBoostClassifier(base_estimator=linear_model.LogisticRegression()).fit(X_train, Y_train)

如何获取模型的系数?我想看看每个特征对目标变量 log(p/(1-p)).

的数值贡献有多大

非常感谢。

A​​daboost 有一个 estimators_ 属性,允许您迭代所有适合的基础学习器。并且,您可以使用每个基础学习器的 coef_ 参数来获取分配给每个特征的系数。然后你可以平均系数。请注意,您必须考虑到 Adaboost 的基础学习器被分配了单独的权重这一事实。

coefs = []
for clf,w in zip(model.estimators_,model.estimator_weights_):
    coefs.append(clf.coef_*w)
coefs = np.array(coefs).mean(axis=0)
print(coefs)

如果您有二元分类,您可能希望将循环内的行更改为:

coefs.append(clf.coef_.reshape(-1)*w)