From 9275de7eb1eef9d83a58d4a655144a3bffdb3bb5 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2020 04:13:01 +0000 Subject: [PATCH] Change methods not using its bound instance to ... ...staticmethods --- decisiontree.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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()