我有一個包含2柱csv文件「投訴詳細」和「DispositionCode'.I要的complaintDetails分爲8不同類別dispostionCode的如‘門反鎖’ ,'供應商錯誤','缺少密鑰或鎖'... 數據集顯示在圖像中。 enter image description here無法移除停止詞; NLP
什麼是很好的方法來分類和找到準確性。
起初我試圖從ComplaintDetails去除停用詞然後用naivebayes分類
的代碼如下:
import csv
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
your_list=[]
with open('H:/Project/rash.csv', 'r') as f:
reader = csv.reader(f)
your_list = list(reader)
print(your_list)
stop_words=set(stopwords.words("english"))
words= word_tokenize(your_list)
filteredSent=[]
for w in words:
if w not in stop_words:
filteredSent.append()
print(filteredSent)
但我得到以下錯誤: -
for self in.self._lang_vars.period_context_re()。finditer(text): TypeError:期望的字符串或類似字節的對象
'word_tokenize'將一個字符串作爲參數,而不是一串字符串。在'your_list'中的每個元素上調用'word_tokenize',而不是'your_list'本身。 – bunji
這是一個列表(csv文件行)的列表,所以它需要雙重解包。 – alexis