cu_man = z.count((‘粗’,‘男’))
num_v_h = (cu_woman + cu_man)
return cu_voive, thin_voice, cu_woman, cu_man, num_v_h
def empty2(pri_data):
hair = [] # [‘长’, ‘短’, ‘短’, ‘长’, ‘短’, ‘短’, ‘长’, ‘长’]
voice = [] # [‘粗’, ‘粗’, ‘粗’, ‘细’, ‘细’, ‘粗’, ‘粗’, ‘粗’]
sex = [] # [‘男’, ‘男’, ‘男’, ‘女’, ‘女’, ‘女’, ‘女’, ‘女’]
for one in pri_data:
hair.append(one[0])
voice.append(one[1])
sex.append(one[2])
一维列表合并成二维列表
k = list(zip(hair, sex))
long_man =k.count((‘长’,‘男’))
long_woman = k.count((‘长’,‘女’))
sum_hair1 = long_man + long_woman
short_man = k.count((‘短’,‘男’))
short_woman = k.count((‘短’,‘女’))
sum_hair2 = short_man + short_woman
sum_Hair = sum_hair1 + sum_hair2
return long_man, long_woman, sum_hair1,sum_hair2,sum_Hair,short_man,short_woman
用声音作为优先选择特征求信息增益
def xxx1(cu_voice,thin_voice,cu_woman,cu_man,num_v_h):
voice_num=cu_voice+thin_voice
A = -cu_voive/voice_num * (cu_woman/num_v_h) * np.log2(cu_woman/num_v_h) - \
cu_voive/voice_num * (cu_man/num_v_h) * np.log2(cu_man/num_v_h)
sum_v = getData(pri_data) - A
return sum_v
用头发作为优先选择特征求信息增益
def xxx2(long_man, long_woman, sum_hair,sum_hair2,sum_Hair,short_man,short_woman):
B = -sum_hair/sum_Hair* (long_man/sum_hair) * np.log2(long_man/sum_hair) - \
sum_hair/sum_Hair * (long_woman/sum_hair) * np.log2(long_woman/sum_hair) - sum_ha