我使用 scikit-learn 的 AdaBoostClassifier 构建了一个模型与 Logistic regression作为基本估计器。
model = AdaBoostClassifier(base_estimator=linear_model.LogisticRegression()).fit(X_train, Y_train)
如何获得模型的系数?我想看看每个特征对目标变量 log(p/(1-p))
的数值贡献有多大。
非常感谢。
最佳答案
Adaboost 有一个 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)
关于python - 如何使用sklearn的AdaBoostClassifier获取模型的系数(以Logistic回归作为基本估计器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60364370/