python - 为文本挖掘创建词汇字典

标签 python nlp text-mining

我有以下代码:

train_set = ("The sky is blue.", "The sun is bright.")
test_set = ("The sun in the sky is bright.",
    "We can see the shining sun, the bright sun.")

现在我正在尝试像这样计算词频:

    from sklearn.feature_extraction.text import CountVectorizer
    vectorizer = CountVectorizer()

接下来我想打印词汇表。因此我这样做:

vectorizer.fit_transform(train_set)
print vectorizer.vocabulary

现在我没有得到输出。虽然我期待这样的事情:

{'blue': 0, 'sun': 1, 'bright': 2, 'sky': 3}

有什么地方出了问题吗?

最佳答案

我想你可以试试这个:

print vectorizer.vocabulary_

关于python - 为文本挖掘创建词汇字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41699065/

相关文章:

python - 布局 - Tkinter - 将按钮分组在一起

python - 执行词干提取会输出乱码/连接词

R:提取关键字后的值和行(文本文件挖掘)

javascript - 美丽汤/正则表达式 : Find specific value from href

python - Twitter oauth 与flask_oauthlib,无法生成请求 token

python - 如何在 python 的单行理解中提取子列表的项目?

nlp - 在 spacy 中,是否可以在匹配的匹配中获取相应的规则 ID

python - 它在 awk 中可能更简单,但我怎么能在 Python 中这样说呢?

r - 使用 R 进行机器学习多标签文本分类

python - 查找相似/同义词/上下文单词 Python