【问题标题】:Recover named features from L1 regularized logistic regression从 L1 正则化逻辑回归中恢复命名特征
【发布时间】:2023-03-21 08:10:01
【问题描述】:

我有以下管道:

sg = Pipeline([('tfidf', TfidfVectorizer()),                                                                                                                                            
               ('normalize', Normalizer()),                                                                                                                                                 
               ('l1', LogisticRegression(penalty="l1", dual=False))])

在执行拟合之后,我想提取对应的标记 到非零权重。

我该怎么做?

【问题讨论】:

  • 什么是“代币”?熊猫数据框的列名?或者你在用什么?

标签: python machine-learning scikit-learn


【解决方案1】:
features = pipeline.named_steps['tfidf'].get_feature_names()
print(features[pipeline.named_steps['l1'].coef_ != 0])

参见TfidfTransformer docsLogisticRegression docsunmerged improved pipeline docs here

【讨论】:

    猜你喜欢
    • 2021-04-10
    • 2020-09-23
    • 2021-04-06
    • 1970-01-01
    • 2016-05-17
    • 2021-02-07
    • 1970-01-01
    • 2016-12-27
    • 2014-01-19
    相关资源
    最近更新 更多