Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions decisiontree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down