Question: 1 6 . from math import log 2 def entropy ( class _ counts ) : total _ instances = sum ( class _ counts

16. from math import log2
def entropy(class_counts):
total_instances = sum(class_counts)
return sum([-count / total_instances * log2(count / total_instances) for count in class_counts if count !=0])
# Overall entropy before splitting
entropy_before = entropy([6,4])
# Entropy of each group after splitting
entropy_group1= entropy([2,1])
entropy_group2= entropy([4,3])
# Proportion of instances in each group
proportion_group1=3/10
proportion_group2=7/10
# Overall entropy after splitting
entropy_after = proportion_group1* entropy_group1+ proportion_group2* entropy_group2
# Information gain from the split
information_gain = entropy_before - entropy_after
information_gain
Ans-0.0058021490143456145

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!