【问题标题】:Machine Learning - How to extract features from pipeline机器学习 - 如何从管道中提取特征
【发布时间】:2020-07-23 02:23:38
【问题描述】:

我对这个领域完全陌生,目前我被困住了。这是我想要的和我所做的:

我有一个数据框,它在训练和测试数据集中是唯一的。培训功能是 twitter 消息,标签被分配类别。我设置了一个标记器(称为clean_text),它只保留相关的单词并将消息剥离到核心信息。该模型包括网格搜索,如下所示:

def build_model():
   pipeline = Pipeline([
        ('vectorizer', CountVectorizer(tokenizer=clean_text)),
        ('tfidf', TfidfTransformer()),
        ('clf', MultiOutputClassifier(
                RandomForestClassifier()
                ))      
        ])

    # parameters to grid search
    parameters = { 'vectorizer__max_features' : [50],#, 72, 144, 288, 576, 1152],
            'clf__estimator__n_estimators' : [100]}#, 100] }

    # initiating GridSearchCV method
    model = GridSearchCV(pipeline, param_grid=parameters, cv = 5)

    return model

拟合效果很好,评估也很好。 不是我不确定,如果模型设置正确,特征是否是消息中最常用的标记(在上述情况下为 50),或者是否存在错误。

现在的问题是: 有没有办法打印这 50 个特征并查看它们是否正确?

最好的 费利克斯

【问题讨论】:

    标签: python nlp classification feature-extraction


    【解决方案1】:

    没有样本信息,这是最好的猜测。请检查以下是否有效。如果您有样本数据,我们可以为您提供更好的帮助。

    print(vectorizer.vocabulary_)
    

    【讨论】:

      【解决方案2】:

      这应该可以工作,或者共享示例数据框

      model.estimator.named_steps['vectorizer'].get_feature_names()
      

      【讨论】:

        猜你喜欢
        • 2021-05-12
        • 2020-06-22
        • 2019-07-14
        • 2019-07-05
        • 2012-03-28
        • 1970-01-01
        • 2013-06-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多