2016-06-24 20 views
1

私はPythonの分類問題に取り組んでいます。事実、私はまだPythonでは良くありません。だから私は長い間ずっと同じ問題を抱えていますし、それを修正する方法もわかりません。私はこれが私のコードであるPython - テキストマイニング - TypeError:__hash__メソッドは整数を返さなければなりません

:)あなたが私を助けることができる願っています:

tableau = pandas.DataFrame({'Exigence':exigence,'Résumé':resume})  

df2, targets = encode_target(tableau,"Exigence") 
features = list(df2.columns[:4]) 

for line in resume: 
    terms = prep.ngram_tokenizer(text=line) 
    mx.add_doc(doc_id='some-unique-identifier', 
       doc_class=df2["Target"], 
       doc_terms=terms, 
       frequency=True, 
       do_padding=True) 

そして、私はこのエラーを持っている:私は見matrix.pyのライン222を行くと

objects are mutable, thus they cannot be hashed 
Traceback (most recent call last): 

    File "<ipython-input-9-072e9c71917a>", line 7, in <module> 
    do_padding=True) 

    File "C:\Users\nouguierc\AppData\Local\Continuum\Anaconda3\lib\site- packages\irlib\matrix.py", line 222, in add_doc 
    if doc_class in self.classes: 

TypeError: __hash__ method should return an integer 

をこれ:

if doc_class in self.classes: 
     self.classes[doc_class].add(my_doc_terms) 

これらの行を含む関数である:

def add_doc(self, doc_id = '', doc_class='', doc_terms=[], 
      frequency=False, do_padding=False): 
    ''' Add new document to our matrix: 
     doc_id: Identifier for the document, eg. file name, url, etc. 
     doc_class: You might need this in classification. 
     doc_terms: List of terms you got after tokenizing the document. 
     frequency: If true, term occurences is incremented by one. 
        Else, occurences is only 0 or 1 (a la Bernoulli) 
     do_padding: Boolean. Check do_padding() for more info. 
    ''' 
    # Update list of terms if new term seen. 
    # And document (row) with its associated data. 
    my_doc_terms = SuperList() 
    for term in doc_terms: 
     term_idx = self.terms.unique_append(term) 
     #my_doc_terms.insert_after_padding(self.terms.index(term)) 
     if frequency: 
      my_doc_terms.increment_after_padding(term_idx,1) 
     else: 
      my_doc_terms.insert_after_padding(term_idx,1) 
    self.docs.append({ 'id': doc_id, 
         'class': doc_class, 
         'terms': my_doc_terms}) 
    # Update list of document classes if new class seen. 
    # self.classes.unique_append(doc_class) 
    if doc_class in self.classes: 
     self.classes[doc_class].add(my_doc_terms) 
    else: 
     self.classes[doc_class] = my_doc_terms 
    if do_padding: 
     self.do_padding() 

私の問題についてどう思いますか?あなたがdoc_classとしてオブジェクトを渡している

答えて

0

df2['Target']戻り、おそらくパンダシリーズは、単一の文字列に変換し内容を確認し、それを渡します。

+0

df2 ["Target"]は:pandas.core.series.Seriesです。これは数字の行です(1; 3; 2; 6; 6; 2; ...)。私はちょうど文字列を保持する必要があります:1 3 2 6 6 2 ??? – celianou

+0

これは、メソッド全体を間違って使用していることを意味します。これは、単一の文書**を得ることになっています**、**単一のラベル** – lejlot

関連する問題