


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



import pandas as pd import numpy as np import math #Information_Gain play_data = pd.read_csv('data.csv') print(play_data) print(play_data.Emp_Sal.value_counts()) p = - (9/14)np.log2(9/14) q = - (5/14)np.log2(5/14) ovall_uncen = p + q print("Overall_Uncertainity: ",ovall_uncen) print("Emp_Sal <=50K") print(play_data.Emp_Sal == "<=50K") print("Emp_Sal >50K") print(play_data.Emp_Sal == ">50K") play_data[play_data.Edu_of_Emp == 'Bachelors'] Entropy_Play_Edu_Bachelors =-(4/6)np.log2(4/6) - (2/6)np.log2(2/6) print("Entropy_Play_Edu_Bachelors: ",Entropy_Play_Edu_Bachelors) play_data[play_data.Edu_of_Emp == 'Masters'] Entropy_Play_Edu_Masters =-(1/2)np.log2(1/2) - (1/2)np.log2(1/2) print("Entropy_Play_Edu_Masters: ",Entropy_Play_Edu_Masters) play_data[play_data.Edu_of_Emp == 'HS-grad'] Entropy_Play_Edu_HS_grad =-(1/2)np.log2(1/2) - (1/2)np.log2(1/2) print("Entropy_Play_Edu_HS_grad: ",Entropy_Play_Edu_HS_grad)
print("overall_uncertainity_on_Emp_race_type: ",overall_uncertainity_on_Emp_race_type) Gain_on_Emp_race_type = ovall_uncen - (8/14)Entropy_Play_Emp_race_type_White - (5/14)Entropy_Play_Emp_race_type_Black print("Reduction in Uncertainity Emp_race_type: ",Gain_on_Emp_race_type) Entropy_Play_sex_of_emp_Male =-(5/9)math.log2(5/9) - (4/9)math.log2(4/9) print("Entropy_Play_sex_of_emp_Male: ",Entropy_Play_sex_of_emp_Male) Entropy_Play_sex_of_emp_Female =-(4/5)np.log2(4/5) - (1/5)np.log2(1/5) print("Entropy_Play_sex_of_emp_Female: ",Entropy_Play_sex_of_emp_Female) overall_uncertainity_emp_sex = (9/14)Entropy_Play_sex_of_emp_Male + (5/14)Entropy_Play_sex_of_emp_Female print("overall_uncertainity_emp_sex: ",overall_uncertainity_emp_sex) Gain_on_sex_of_emp = ovall_uncen - (9/14)Entropy_Play_sex_of_emp_Male - (5/14)Entropy_Play_sex_of_emp_Female print("Reduction in Uncertainity sex_of_emp: ",Gain_on_sex_of_emp) #So Education Reduces the uncertainity the most OUTPUT