2016-08-16 5 views
0

私は私のStockクラスにclfオブジェクトにfitメソッドにアクセスしようとしている、私はこのエラーを取得する:未結合の方法フィット()最初の引数は(代わりにストックインスタンスを得た)としてDecisionTreeClassifierインスタンスで呼び出さなければなりません

unbound method fit() must be called with DecisionTreeClassifier instance as first argument (got Stock instance instead)

ストッククラス:

0:私はクラスをインスタンス化しています

class Stock(): 
    def __init__(self,equity, history): 
     self.equity = equity 
     self.history = history 
     self.clf = tree.DecisionTreeClassifier 

    # Couldn't use built-in comparable method 
    # This method is a workaround. 
    def exists(self, allCompanies): 
     exists = False; 
     for other in allCompanies: 
      if self.equity.sid == other.equity.sid: 
       exists = True 

     return exists 

エラーがスローされ

... 
       if current > prev: 
        Stock.clf.fit(Stock, 1) 
       else: 
        Stock.clf.fit(Stock, 0) 
... 

答えて

2

が他の正解を完了するために、ここでは、あなたのバギーラインself.clf = tree.DecisionTreeClassifier意味を理解するのに役立ちます少し例を示します

class f(object): 

    def __init__(self): 
     pass 

print(isinstance(f, f)) 
print(isinstance(f(), f)) 
1

をあなたがtree.DecisionTreeClassifierをインスタンス化していない、あなたのDecisionTreeClassifier

self.clf = tree.DecisionTreeClassifier()

1

をインスタンス化する必要があります。したがって、クラスのfit()メソッドを呼び出し、使用するインスタンスを指定する必要があります。

は、おそらくあなたがtree.DecisionTreeClassifierをインスタンス化したい:

self.clf = tree.DecisionTreeClassifier() 
関連する問題