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

Skip to content

Commit 8cfb62d

Browse files
committed
Tweaked information_gain().
1 parent 9639eed commit 8cfb62d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

learning.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,13 @@ def choose_attribute(attrs, examples):
299299
lambda a: information_gain(a, examples))
300300

301301
def information_gain(attr, examples):
302+
"Return the expected reduction in entropy from splitting by attr."
302303
def I(examples):
303304
return information_content([count(target, v, examples)
304305
for v in values[target]])
305306
N = float(len(examples))
306-
remainder = 0
307-
for (v, examples_i) in split_by(attr, examples):
308-
remainder += (len(examples_i) / N) * I(examples_i)
307+
remainder = sum((len(examples_i) / N) * I(examples_i)
308+
for (v, examples_i) in split_by(attr, examples))
309309
return I(examples) - remainder
310310

311311
def split_by(attr, examples):

0 commit comments

Comments
 (0)