第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Python 中的基本決策樹(shù)

Python 中的基本決策樹(shù)

元芳怎么了 2023-02-07 11:01:29
我正在學(xué)習(xí)機(jī)器學(xué)習(xí)書(shū)中決策樹(shù)的基本知識(shí)。書(shū)中出現(xiàn)這個(gè)例子是為了理解一些東西(我知道這不是決策樹(shù),但有些東西我不明白)def gini (p):    return (p)*(1-(p))-(1-p)*(1-(1-p))def entropy(p):    return -p*np.log2(p)-(1-p)*np.log2((1-p))def error(p):    return 1- np.max([p, 1-p])x=np.arange(0.0, 1.0, 0.01)ent=[entropy(p) if p != 0 else None for p in x]sc_ent = [e*0.5 if e else None for e in ent]err= [error(i) for i in x]fig = plt.figure()ax=plt.subplot(111)for i, lab, ls, c, in zip ([ent, sc_ent, gini(x), err], ['Entropy', 'Entropy(scaled)', 'Gini Impurity', 'Misclassification Error'], ['-', '-', '--', '-.'], ['black', 'lightgray','red','green', 'cyan']):    line= ax.plot(x,i,label=lab, linestyle=ls, lw=2, color =c)ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.15), ncol=5, fancybox=True, shadow=False)ax.axhline(y=0.5, linewidth= 1, color='k', linestyle='--')ax.axhline(y=1, linewidth= 1, color='k', linestyle='--')plt.ylim([0, 1.1])plt.xlabel('p(i=1)')plt.ylabel('Impurity index')plt.show()有人可以解釋這里發(fā)生了什么嗎?ent=[entropy(p) if p != 0 else None for p in x]sc_ent = [e*0.5 if e else None for e in ent]err= [error(i) for i in x]
查看完整描述

1 回答

?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊

x是一個(gè)數(shù)字列表。的熵0顯然是未定義的(所以我們返回None),但對(duì)于其他數(shù)字,它返回一個(gè)我們返回的數(shù)字。這是第一行。

第二行采用熵列表,并將每個(gè)數(shù)值除以 2(它對(duì) a 不執(zhí)行任何操作None)。第三行給出了一個(gè)錯(cuò)誤列表,每個(gè)錯(cuò)誤對(duì)應(yīng)列表中的一個(gè)元素x。


查看完整回答
反對(duì) 回復(fù) 2023-02-07
  • 1 回答
  • 0 關(guān)注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)