[问题] Bag of words 中文单字词问题

楼主: ctr1 (【积π】)   2018-06-26 10:48:06
from sklearn.feature_extraction.text import CountVectorizer
text = [
"我|爱你",
"他|爱狗",
"猫|爱鼠"
]
vectorizer = CountVectorizer()
vectorizer.fit(text)
vector = vectorizer.transform(text)
print (vectorizer.vocabulary_)
# 维度
print (vector.shape)
print (vector.toarray())
▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂
输出:
{'爱你': 0, '爱狗': 1, '爱鼠': 2}
(3, 3)
[[1 0 0]
[0 1 0]
[0 0 1]]
▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂
想请问版上的各位大大
若是我希望单字(我、他、猫)也要放在bag内
要如何改写这段程式
或要用什么关键字去google查询呢
谢谢打家

Links booklink

Contact Us: admin [ a t ] ucptt.com