[問題] 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