看板 DataScience 關於我們 聯絡資訊
※ [本文轉錄自 Python 看板 #1RCQbiCM ] 作者: 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://www.ptt.cc/bbs/Python/M.1529981292.A.316.html ※ 編輯: ctr1 (59.124.158.195), 06/26/2018 10:50:29 ※ 發信站: 批踢踢實業坊(ptt.cc) ※ 轉錄者: ctr1 (59.124.158.195), 06/26/2018 11:12:34
jr55662003: 用結巴斷詞? 06/26 16:29
b24333666: 把 |換成空白 06/27 07:05
b24333666: google tokenization nlp 06/27 07:07
ctr1: |就是用結巴斷詞出來的,換成空白還是一樣呢。 06/27 08:29