从 L1 正则化逻辑回归中恢复命名特征
Recover named features from L1 regularized logistic regression
我有以下管道:
sg = Pipeline([('tfidf', TfidfVectorizer()),
('normalize', Normalizer()),
('l1', LogisticRegression(penalty="l1", dual=False))])
并且在执行拟合之后,我想提取对应的标记
到非零权重。
我该怎么做?
features = pipeline.named_steps['tfidf'].get_feature_names()
print(features[pipeline.named_steps['l1'].coef_ != 0])
见TfidfTransformer docs, LogisticRegression docs and the unmerged improved pipeline docs here
我有以下管道:
sg = Pipeline([('tfidf', TfidfVectorizer()),
('normalize', Normalizer()),
('l1', LogisticRegression(penalty="l1", dual=False))])
并且在执行拟合之后,我想提取对应的标记 到非零权重。
我该怎么做?
features = pipeline.named_steps['tfidf'].get_feature_names()
print(features[pipeline.named_steps['l1'].coef_ != 0])
见TfidfTransformer docs, LogisticRegression docs and the unmerged improved pipeline docs here