2024年Python最新使用Python实现ID3决策树中特征选择的先后顺序

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值