繁体   English   中英

如何列出逻辑回归中特征重要性的相应列名

[英]How to list corresponding column names for feature importance in logistic regression

如何列出特征重要性的实际特征名称(列名),而不是特征的索引号?

from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
X, y = make_classification(n_samples=2700, n_features=3, n_informative=5, n_redundant=5, 
random_state=1)

model = LogisticRegression()

model.fit(X, y)

importance = model.coef_[0]

for i,v in enumerate(importance):
    print('Feature: %0d, Score: %.5f' % (i,v))

output:

Feature: 0, Score: -0.11124
Feature: 1, Score: -0.04292
Feature: 2, Score: 0.00561

所需的 Output:

featurename1, Score: -0.11124
featurename2, Score: -0.04292
featurename3, Score: 0.00561

也许这会有所帮助: https://datascience.stackexchange.com/questions/29131/feature-names-in-logisticregression

还要确保发布您正在使用的 sklearn 版本。

暂无
暂无

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

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