Skip to content

Instantly share code, notes, and snippets.

@lethalbrains
Last active August 8, 2018 06:05
Show Gist options
  • Save lethalbrains/3bcec4e92719ae9c8d709245ae4110a0 to your computer and use it in GitHub Desktop.
Save lethalbrains/3bcec4e92719ae9c8d709245ae4110a0 to your computer and use it in GitHub Desktop.
Gist for "Learn ML Algorithms by coding" Blog
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