試驗(yàn)三決策樹(shù)算法試驗(yàn)試驗(yàn)報(bào)告材料_第1頁(yè)
試驗(yàn)三決策樹(shù)算法試驗(yàn)試驗(yàn)報(bào)告材料_第2頁(yè)
試驗(yàn)三決策樹(shù)算法試驗(yàn)試驗(yàn)報(bào)告材料_第3頁(yè)
試驗(yàn)三決策樹(shù)算法試驗(yàn)試驗(yàn)報(bào)告材料_第4頁(yè)
試驗(yàn)三決策樹(shù)算法試驗(yàn)試驗(yàn)報(bào)告材料_第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、實(shí)用標(biāo)準(zhǔn)文檔實(shí)驗(yàn)三決策樹(shù)算法實(shí)驗(yàn)一、實(shí)驗(yàn)?zāi)康模?二、實(shí)驗(yàn)原理: 三、實(shí)驗(yàn)條件: 四、實(shí)驗(yàn)內(nèi)容:熟悉和掌握決策樹(shù)的分類原理、實(shí)質(zhì)和過(guò)程;掌握典型的學(xué)習(xí)算法 決策樹(shù)學(xué)習(xí)和分類.和實(shí)現(xiàn)技術(shù)。根據(jù)現(xiàn)實(shí)生活中的原型自己創(chuàng)建一個(gè)簡(jiǎn)單的決策樹(shù)。要求用這個(gè)決策樹(shù)能解決實(shí)際分類決策問(wèn)題。五、實(shí)驗(yàn)步驟:1、驗(yàn)證性實(shí)驗(yàn):(1)算法偽代碼算法 Decision_Tree(data,AttributeName)輸入由離散值屬性描述的訓(xùn)練樣本集data; 候選屬 T集合 AttributeName 。輸出一棵決策樹(shù)。(1)創(chuàng)建節(jié)點(diǎn)N;(2) If samples都在同一類 C中then (3) 返回N作為葉節(jié)點(diǎn),以類C

2、標(biāo)記;(4) If attribute_list為空then(5)返回N作為葉節(jié)點(diǎn),以以test_attribute 標(biāo)記節(jié)點(diǎn)(8) For each test_attribute(9)由節(jié)點(diǎn)N分出一個(gè)對(duì)應(yīng)(6)選擇 attribute_listsamples中最普遍的類標(biāo)記;/多數(shù)表決 N;的已知值v / 劃分samples ;test_attribute=v 的分支;中具有最高信息增益的屬性test_attribute;(10令Sv為samples中test_attribute=v 的樣本集合;/ 一個(gè)劃分塊(12)加上一個(gè)葉節(jié)點(diǎn),以 samples中最普遍的類標(biāo)記;(13) Else 加

3、入一個(gè)由 Decision_Tree(Sv,attribute_list-test_attribute)(11) If Sv 為空返回節(jié)點(diǎn)值。then(2)實(shí)驗(yàn)數(shù)據(jù)預(yù)處理FEMAL- “1”; MALE- “2”Income: 50002 萬(wàn)-“1”; 2萬(wàn)4萬(wàn)-“2”;Age:30歲以下標(biāo)記為“ 1”; 30歲以上50歲以下標(biāo)記為“ 2”; 50歲以上標(biāo)記為“ 3”。Sex:4萬(wàn)以上Region : INNER CITY“1; TOWN一 “2;RURAL一 “3;SUBURBAN一 “4”-3 Married Children Car文案大全實(shí)用標(biāo)準(zhǔn)文檔MortgagePep:以上五個(gè)條件

4、,若為“是”標(biāo)記為“1”,若為“否”標(biāo)記為“ 2”。 TOC o 1-5 h z Age sex region income married children car mortgage pep 1 2 1 1 2 1 1 2 2 12112222121412122121111222212111222212112121121211211221112112121312212121222122222122221121221121122121221211121222132121112211121112111322212131221222132331112132231211231331122132131

5、2122321311111文案大全實(shí)用標(biāo)準(zhǔn)文檔 TOC o 1-5 h z 311312112313312222324312211313322112(3) Matlab 語(yǔ)句:Tree RulesMatrix= DecisionTree(DataSet, AttributName)TK、實(shí)驗(yàn)結(jié)果:文案大全實(shí)用標(biāo)準(zhǔn)文檔The Decision Tree:The Root):Attribut refisn21 Attribut Marriedjleaf 112.leaf 2|2leaf 2I3AttributchildrenI1Attribut AgeI 1 Attribut seatAtt ri

6、but car1Attribut AgI2leafleafleaf 1Aft ribut me wieAttribut marriedleaf 1leaf 23,leaf 2Att ribut I1leaf 2Attribut carleaf 1Attribut childrenleaf 1 leaf 2leaf 1文案大全實(shí)用標(biāo)準(zhǔn)文檔Tree =Attribut: 3Child: 1x4 structRulesMatrix =11101Q001210100020101000301II1003Q1211Q030131100301012Q01010201020102Q100Q102Q200021

7、Q000002210Q00022200000230Q000Q30QQ0I00300012003001220030022200400000文案大全12212122112122212實(shí)用標(biāo)準(zhǔn)文檔實(shí)驗(yàn)程序:function Tree RulesMatrix=DecisionTree(DataSet,AttributName)喻入為訓(xùn)練集,為離散后的數(shù)字,如記錄 1:1 1 3 2 1 ;前面為屬性列,最后一列為類標(biāo)if nargin1error( 請(qǐng)輸入數(shù)據(jù)集);elseif isstr(DataSet)DataSet AttributValue=readdata2(DataSet);elseAtt

8、ributValue=;endendif narginmostlabelnum)mostlabelnum=length(ValRecords(i).matrix);mostlabel=i;end文案大全實(shí)用標(biāo)準(zhǔn)文檔endTree.Attribut=mostlabel;Tree.Child=;return;endfor i=1:length(Attributs)Sa(i) ValRecord=ComputEntropy(DataSet,i);Gains(i)=S-Sa(i);AtrributMatric(i).val=ValRecord;endmaxval maxindex=max(Gains)

9、;Tree.Attribut=Attributs(maxindex);Attributs2=Attributs(1:maxindex-1) Attributs(maxindex+1:length(Attributs);for j=1:length(AtrributMatric(maxindex).val)DataSet2=DataSet(AtrributMatric(maxindex).val(j).matrix,1:maxindex-1) DataSet(AtrributMatric(maxindex).val(j).matrix,maxindex+1:size(DataSet,2);if(

10、size(DataSet2,1)=0)mostlabelnum=0;mostlabel=0;for i=1:length(ValRecords)if(length(ValRecords(i).matrix)mostlabelnum) mostlabelnum=length(ValRecords(i).matrix); mostlabel=i;endendTree.Child(j).root.Attribut=mostlabel;文案大全實(shí)用標(biāo)準(zhǔn)文檔Tree.Child(j).root.Child=;elseTree.Child(j).root=CreatTree(DataSet2,Attrib

11、uts2);endendendfunction Entropy RecordVal=ComputEntropy(DataSet,attribut) %計(jì)算信息嫡if(attribut=0)clnum=0;for i=1:size(DataSet,1)if(DataSet(i,size(DataSet,2)clnum) %防止下標(biāo)越界classnum(DataSet(i,size(DataSet,2)=0;clnum=DataSet(i,size(DataSet,2);RecordVal(DataSet(i,size(DataSet,2).matrix=; endclassnum(DataSet

12、(i,size(DataSet,2)=classnum(DataSet(i,size(DataSet,2)+1;RecordVal(DataSet(i,size(DataSet,2).matrix=RecordVal(DataSet(i,size(DataSet,2).matrix i; endEntropy=0;for j=1:length(classnum)P=classnum(j)/size(DataSet,1);if(P=0)Entropy=Entropy+(-P)*10g2(P);endend文案大全實(shí)用標(biāo)準(zhǔn)文檔elsevalnum=0;for i=1:size(DataSet,1)

13、if(DataSet(i,attribut)valnum) %防止參數(shù)下標(biāo)越界clnum(DataSet(i,attribut)=0;valnum=DataSet(i,attribut);Valueexamnum(DataSet(i,attribut)=0;RecordVal(DataSet(i,attribut),matrix=; %將編號(hào)保留下來(lái),以方便后面按值分割數(shù)據(jù)集end if(DataSet(i,size(DataSet,2)clnum(DataSet(i,attribut) %防止下標(biāo)越界Value(DataSet(i,attribut).classnum(DataSet(i,s

14、ize(DataSet,2)=0;clnum(DataSet(i,attribut)=DataSet(i,size(DataSet,2); endValue(DataSet(i,attribut).classnum(DataSet(i,size(DataSet,2)=Value(DataSet(i,attribut).classnum(DataSet(i,size(DataSet,2)+1;Valueexamnum(DataSet(i,attribut)= Valueexamnum(DataSet(i,attribut)+1;RecordVal(DataSet(i,attribut).matr

15、ix=RecordVal(DataSet(i,attribut).matrix i; end Entropy=0; for j=1:valnumEntropys=0;for k=1:length(Value(j).classnum)P=Value(j).classnum(k)/Valueexamnum(j);if(P=0)Entropys=Entropys+(-P)*10g2(P);end文案大全實(shí)用標(biāo)準(zhǔn)文檔endEntropy=Entropy+(Valueexamnum(j)/size(DataSet,1)*Entropys; endendendfunction showTree(Tree,

16、level,value,branch,AttributValue,AttributName) blank=;for i=1:level-1if(branch(i)=1) TOC o 1-5 h z blank=blank 口;elseblank=blank ;endendblank=blank ;if(level=0)blank= (The Root):;elseif isempty(AttributValue)blank=blank | int2str(value) ;elseblank=blank | value ;endendif(length(Tree.Child)=0) %非葉子節(jié)點(diǎn)

17、if isempty(AttributName)文案大全實(shí)用標(biāo)準(zhǔn)文檔disp(blank Attribut int2str(Tree.Attribut); else disp(blank Attribut AttributNameTree.Attribut); end if isempty(AttributValue) for j=1:length(Tree.Child)-1showTree(Tree.Child(j).root,level+1,j,branch 1,AttributValue,AttributName); end showTree(Tree.Child(length(Tree

18、.Child).root,level+1,length(Tree.Child),branch(1:length(branch)-1)01,AttributValue,AttributName); else for j=1:length(Tree.Child)-1showTree(Tree.Child(j).root,level+1,AttributValueTree.Attributj,branch 1,AttributValue,AttributName); endshowTree(Tree.Child(length(Tree.Child).root,level+1,AttributValueTree.Attributlength(Tree.

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論