diff --git a/decisiontree.py b/decisiontree.py index 115d879..9bc4023 100644 --- a/decisiontree.py +++ b/decisiontree.py @@ -13,7 +13,8 @@ def __init__(self, trainingData, maxDepth): ''' S : is a Series ''' - def selfEntropy(self, S): # S is a pandas::Series + @staticmethod + def selfEntropy(S): # S is a pandas::Series value_probabilies = S.value_counts() / len(S) return - ( value_probabilies * value_probabilies.apply(math.log2) ).sum() @@ -23,7 +24,8 @@ def selfEntropy(self, S): # S is a pandas::Series -> returns the conditional entropy H(Y | X) using : sum(p(x and y)* log(p(x) / p(x and y)) ) ''' - def conditionalEntropy(self, X_Y:list): + @staticmethod + def conditionalEntropy(X_Y:list): # Series of the form (index = (X,Y), value = P(x and y) ) probability_XandY = X_Y.groupby(list(X_Y.columns)).size() / len(X_Y) probability_X = probability_XandY.groupby(level=0).sum()