作者ctr1 (【积π】)
看板Python
标题[问题] Bag of words 中文单字词问题
时间Tue Jun 26 10:48:06 2018
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查询呢
谢谢打家
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 59.124.158.195
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1529981292.A.316.html
※ 编辑: ctr1 (59.124.158.195), 06/26/2018 10:50:29