Last active
August 8, 2018 06:05
-
-
Save lethalbrains/3bcec4e92719ae9c8d709245ae4110a0 to your computer and use it in GitHub Desktop.
Gist for "Learn ML Algorithms by coding" Blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecisionTree: | |
def fit(self, data, target): | |
self.data = data | |
self.target = target | |
self.independent = self.data.columns.tolist() | |
self.independent.remove(target) | |
def predict(self, data): | |
return np.array([self.__flow_data_thru_tree(row) for row in data.values]) | |
def __flow_data_thru_tree(self, row): | |
return self.data[self.target].value_counts() \ | |
.apply(lambda x: x/len(self.data)).tolist() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment