【问题标题】:CountVectorizer ignores Upper CaseCountVectorizer 忽略大写
【发布时间】:2018-02-20 03:31:07
【问题描述】:

CountVectorizer 忽略大写单词的原因是什么?

cv = CountVectorizer(stop_words=None,analyzer='word',token_pattern='.*',max_features=None)
text = ['this','is','a','Test','!']
fcv = cv.fit_transform(list)
fcv = [cv.vocabulary_.get(t) for t in text]
print fcv

返回

[5, 3, 2, None, 1]

【问题讨论】:

    标签: python pandas numpy scikit-learn


    【解决方案1】:

    这是因为CountVectorizerlowercase默认设置为True,添加lowercase=False

    cv = CountVectorizer(stop_words=None, analyzer='word', token_pattern='.*',
            max_features=None, lowercase=False)
    

    【讨论】:

    • 是的。虽然,可能您只想要 [cv.vocabulary_.get(t.lower()) for t in text] 而不是为 "Test""test" 提供不同的功能....
    • 哎呀我没有注意到有一个参数。谢谢! scikit-learn.org/stable/modules/generated/…
    • @Sindico 是的,但您可能不想使用该参数!默认为True 是有充分理由的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-29
    • 2014-02-08
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多