Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d28f9c

Browse files
committed
Reordered methods top-down.
1 parent bd840ea commit 8d28f9c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

learning.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,6 @@ def decision_tree_learning(self, examples, attrs, parent_examples=()):
304304
tree.add(v, subtree)
305305
return tree
306306

307-
def choose_attribute(self, attrs, examples):
308-
"Choose the attribute with the highest information gain."
309-
return argmax(attrs, lambda a: self.information_gain(a, examples))
310-
311-
def all_same_class(self, examples):
312-
"Are all these examples in the same target class?"
313-
target = self.dataset.target
314-
class0 = examples[0][target]
315-
return all(e[target] == class0 for e in examples)
316-
317307
def plurality_value(self, examples):
318308
"""Return the most popular target value for this set of examples.
319309
(If target is binary, this is the majority; otherwise plurality.)"""
@@ -324,6 +314,16 @@ def plurality_value(self, examples):
324314
def count(self, attr, val, examples):
325315
return count_if(lambda e: e[attr] == val, examples)
326316

317+
def all_same_class(self, examples):
318+
"Are all these examples in the same target class?"
319+
target = self.dataset.target
320+
class0 = examples[0][target]
321+
return all(e[target] == class0 for e in examples)
322+
323+
def choose_attribute(self, attrs, examples):
324+
"Choose the attribute with the highest information gain."
325+
return argmax(attrs, lambda a: self.information_gain(a, examples))
326+
327327
def information_gain(self, attr, examples):
328328
def I(examples):
329329
target = self.dataset.target

0 commit comments

Comments
 (0)