python - 如何使用sklearn的AdaBoostClassifier获取模型的系数(以Logistic回归作为基本估计器)

标签 python scikit-learn logistic-regression adaboost

我使用 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/

相关文章:

python - 将一列中的数组值转换为原始 DataFrame 的列的最佳方法是什么?

python - 将值添加到列表中直到 Python 中的某个索引

Python - Selenium : Find/Click YT-Like Button

python - 以 python 方式从文件读取时一次性构建 2 个列表

python - scikit-learn 中 predict_proba 的输出

machine-learning - 适合 MNIST 的逻辑回归最优求解器的选择

python - 加快 Python 中 beta Pert 分布的计算

python - 无法确定要输入机器学习算法的 2D 特征矩阵结构

python - 如何使用 train_test_split 在交叉验证中保持测试大小不变?

python - 逻辑回归中的混淆矩阵