自然言語分析を行っています。
モデル生成時の語彙データに「nan」や「null」があります。
その語彙データでテスト用のテキストの汎化性能を測定する際に、その上記2つの語彙データが欠損値と認識されるためエラーが出ます。
(コード)
vectorizer = TfidfVectorizer(vocabulary = vocab_list) ← 「vocab_list」が語彙リスト。いったんcsv化した後、pandasで読み込んでリスト形式にしている。
vectorizer.fit(data_separate)
エラーメッセージ
----> 3 vectorizer.fit(data_separate)
4 print('No. of feature_words: ', len(vectorizer.get_feature_names()))
~\Anaconda3\lib\site-packages\sklearn\feature_extraction\text.py in fit(self, raw_documents, y)
1821 self._check_params()
1822 self._warn_for_unused_params()
-> 1823 X = super().fit_transform(raw_documents)
1824 self._tfidf.fit(X)
1825 return self
~\Anaconda3\lib\site-packages\sklearn\feature_extraction\text.py in fit_transform(self, raw_documents, y)
1195
1196 self._validate_params()
-> 1197 self._validate_vocabulary()
1198 max_df = self.max_df
1199 min_df = self.min_df
~\Anaconda3\lib\site-packages\sklearn\feature_extraction\text.py in _validate_vocabulary(self)
447 if vocab.setdefault(t, i) != i:
448 msg = "Duplicate term in vocabulary: %r" % t
--> 449 raise ValueError(msg)
450 vocabulary = vocab
451 else:
ValueError: Duplicate term in vocabulary: nan

回答1件
あなたの回答
tips
プレビュー