資源簡(jiǎn)介
此程序主要實(shí)現(xiàn)對(duì)數(shù)據(jù)的加載和處理,首先加載數(shù)據(jù),本算法選擇的數(shù)據(jù)集是鳶尾花數(shù)據(jù)集,加載的數(shù)據(jù)形式是元胞數(shù)組,本程序先把其轉(zhuǎn)換成字符串?dāng)?shù)組,后對(duì)字符串?dāng)?shù)組進(jìn)行處理,將數(shù)據(jù)部分和標(biāo)簽部分分隔開,數(shù)據(jù)部分轉(zhuǎn)換成數(shù)組形式,標(biāo)簽部分則對(duì)應(yīng)存儲(chǔ)于字符串?dāng)?shù)組中。然后對(duì)數(shù)據(jù)創(chuàng)建決策樹,結(jié)果存儲(chǔ)于結(jié)構(gòu)體中,后計(jì)算算法的準(zhǔn)確率。最后將結(jié)構(gòu)體數(shù)據(jù)轉(zhuǎn)換成元胞數(shù)據(jù),轉(zhuǎn)換成treeplot系統(tǒng)函數(shù)能識(shí)別的數(shù)據(jù)形式,并繪制決策樹。
代碼片段和文件信息
function?[bestfeatT_fen]?=?choose_feat(datafeat_indexlabel)
%這里主要是用于選擇最理想的屬性
%feat_index:需要進(jìn)行比較的屬性
%data:樣本的數(shù)據(jù)?label:對(duì)應(yīng)樣本數(shù)據(jù)的標(biāo)簽
%T_fen:對(duì)應(yīng)最優(yōu)屬性的二分法的最優(yōu)分割點(diǎn)
%bestfeat:最優(yōu)屬性的索引
best_gain=0;
bestfeat=0;
%?T_fen對(duì)應(yīng)屬性獲得最大增益時(shí)的二分法取值
for?i=feat_index
????mmat=unique(data(:i));%得到對(duì)應(yīng)屬性取值的序列
????if?length(mmat)-1==0
????????T_mat=mmat(1);
????else
????????T_mat=ones(1length(mmat)-1);%定義二分法的值
????????for?j=1:length(mmat)-1
????????????T_mat(j)=(mmat(j)+mmat(j+1))/2;
????????end
????end
????
????for?j=T_mat
????????Gain=Ent_cal_data(datalabelij);
????????if?Gain>best_gain
????????????best_gain=Gain;
????????????bestfeat=i;
????????????T_fen=j;
????????end
????end
end
end
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????807??2020-08-07?11:02??ID3決策樹算法\choose_feat.m
?????文件???????1136??2020-08-08?09:07??ID3決策樹算法\creat_tree.m
?????文件????????360??2020-08-07?18:04??ID3決策樹算法\Ent_cal_data.m
?????文件????????491??2020-08-07?18:41??ID3決策樹算法\Ent_cal_label.m
?????文件????????193??2020-08-07?16:48??ID3決策樹算法\fen_label.m
?????文件????????257??2020-08-05?18:59??ID3決策樹算法\find_label.m
?????文件????????420??2020-08-07?17:01??ID3決策樹算法\find_mlabel.m
?????文件???????1513??2020-08-08?12:04??ID3決策樹算法\ID3_v1.m
?????文件???????4551??2020-03-05?17:12??ID3決策樹算法\iris.data
?????文件????????600??2020-08-07?11:09??ID3決策樹算法\prev.m
?????文件????????425??2020-08-07?11:10??ID3決策樹算法\print_tree.m
?????目錄??????????0??2020-09-03?16:56??ID3決策樹算法
-----------?---------??----------?-----??----
????????????????10753????????????????????12
評(píng)論
共有 條評(píng)論