python 特征提取:属性错误:"列表"对象没有属性"较低"



如果我写这个::

bow_vect = CountVectorizer(max_df=0.90, min_df=2, max_features=1000, stop_words='english')
bow = bow_vect.fit_transform(combi['tidy_tweet'])

我收到此错误::

AttributeError                            Traceback (most recent call last)
<ipython-input-65-745529b5930e> in <module>
      1 bow_vect = CountVectorizer(max_df=0.90, min_df=2, max_features=1000, stop_words='english')
----> 2 bow = bow_vect.fit_transform(combi['tidy_tweet'])
c:usersavinashappdatalocalprogramspythonpython37libsite-packagessklearnfeature_extractiontext.py in fit_transform(self, raw_documents, y)
   1010 
   1011         vocabulary, X = self._count_vocab(raw_documents,
-> 1012                                           self.fixed_vocabulary_)
   1013 
   1014         if self.binary:
c:usersavinashappdatalocalprogramspythonpython37libsite-packagessklearnfeature_extractiontext.py in _count_vocab(self, raw_documents, fixed_vocab)
    920         for doc in raw_documents:
    921             feature_counter = {}
--> 922             for feature in analyze(doc):
    923                 try:
    924                     feature_idx = vocabulary[feature]
c:usersavinashappdatalocalprogramspythonpython37libsite-packagessklearnfeature_extractiontext.py in <lambda>(doc)
    306                                                tokenize)
    307             return lambda doc: self._word_ngrams(
--> 308                 tokenize(preprocess(self.decode(doc))), stop_words)
    309 
    310         else:
c:usersavinashappdatalocalprogramspythonpython37libsite-packagessklearnfeature_extractiontext.py in <lambda>(x)
    254 
    255         if self.lowercase:
--> 256             return lambda x: strip_accents(x.lower())
    257         else:
    258             return strip_accents
AttributeError: 'list' object has no attribute 'lower'

不知道combi['tidy_tweet']实际上是什么类型,这可能是因为fit_transform期望字符串的可迭代对象,而您正在为其提供系列。

combi['tidy_tweet']实际上应该是供fit_transform工作的字符串列表。目前,它看起来像是一系列字符串列表。

因此,最好的办法是将每行(列表)中的标记连接成一个字符串,将这些字符串打包到一个列表中,然后在其上使用fit_transform。

相关内容

  • 没有找到相关文章

最新更新