决策树ID3源程序

决策树ID3源程序

ID:41947121

大小:102.56 KB

页数:7页

时间:2019-09-05

决策树ID3源程序_第1页
决策树ID3源程序_第2页
决策树ID3源程序_第3页
决策树ID3源程序_第4页
决策树ID3源程序_第5页
资源描述:

《决策树ID3源程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、id3算法的matlab实现嚴帖]functionD=ID3(train_features,train_targets,params,region)%ClassifyusingQuinlan´sID3algorithm%Inputs:%features一Trainfeatures%targets-Traintargets%params-[Numberofbinsforthedata,Percentageofincorrectlyassignedsamplesatanode]%region-Deci

2、sionregionvector:[-xx-yynumber_of_points]%%Outputs%D-Decisionsufrace[Ni,M]=size(trainfeatures);%Getpcirameters[Nbins,incnode]=processparams(params);incnode=incnode*M/100;%ForthedecisionregionN=region(5);mx=ones(N,1)*linspace(region(l),region(2),N);myflatxy=

3、1inspace(region(3),region(4),N)´*ones(l,N):=[mx(:),my(:)]´;%Prcprocessing[f,t,UW,m]trainfeaturesflatxy=PCA(trainfeatures,traintargets,Ni,region);=UW*(trainfeatures一m*ones(l,M));;二UW*(flatxy-m*ones(l,N^2)):;%First,binthedataandthedecisionregionda

4、ta[II,binned_features]=high_histogram(train_features,Nbins,region);[II,binned_xy]=high^histogram(flatxy,Nbins,region);%BuiIdthetreerecursivelydisp(´Buildingtree´)tree=maketree(binnodfeatures,traintargets,incnode,Nbins):%Makethedecisionregionacco

5、rdingtothetreedisp(&acule;Buildingdecisionsurfaceusingthetree&scule;)targets=usetree(binnedxy,1:N2,tree,Nbins,unique(lrtiir)targets));D=reshape(targets,N,N);%ENDfunctiontargets=use_tree(features,indices,tree,Nbins,Uc)%Classifyrecursivelyusingatreetargets=ze

6、ros(i,size(features,2));if(size(features,i)—i),%0nlyonedimensionleft,soworkonitfori=1:Nbins,in二indices(find(features(indices)二二i));if"isempty(in),ifisfinite(troc.child(i)),targets(in)=tree・child(i);else%Nodatawasfoundinthetrainingsetforthisbin,sochooseitran

7、domallyn=1+floor(rand(l)*length(Uc));targets(in)二Uc(n);endendendbreakend%Thisisnotthelastlevelofthetree,so:%First,findthedimensionwearetoworkondim=tree・splitdim;dims=findCismember(1:size(features,1),dim)):classifyaccordingtoitfori=1:Nbins,in=indices(find(fe

8、atures(dim,indices)==i)):targets=targets+use_tree(features(dims,:),in,tree.child(i),Nbins,Uc);end%ENDusc^trcefunctiontree=make^tree(features,targets,inc_node,Nbins)%Buildatreerecursively[Ni,L]=size(fea

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。