【发布时间】:2013-01-23 00:57:22
【问题描述】:
我想从文本中获取最相关的词以准备标签云。
我使用了 scikit-learn 包中的 CountVectoriser:
cv = CountVectorizer(min_df=1, charset_error="ignore",
stop_words="english", max_features=200)
这很好,因为它给了我单词和频率:
counts = cv.fit_transform([text]).toarray().ravel()
words = np.array(cv.get_feature_names())
我可以过滤掉不常用的词:
words = words[counts > 1]
counts = counts[counts > 1]
还有单词,即数字:
words = words[np.array(map(lambda x: x.isalpha(), words))]
counts = counts[np.array(map(lambda x: x.isalpha(), words))]
但它仍然不完美......
我的问题是:
- 如何过滤掉动词?
- 如何进行词干提取以去除同一个词的不同形式?
- 如何调用 CountVectoriser 过滤掉两个字母的单词?
另请注意:
- 我对 nltk 没问题,但像“你应该尝试 nltk”这样的回答不是答案,请给我一个代码。
- 我不想使用贝叶斯分类器和其他需要训练模型的技术。我没有时间,也没有训练分类器的示例。
- 语言是英语
【问题讨论】:
标签: python data-mining nltk text-mining scikit-learn