您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 信息化管理 > reliefF算法源码
functionW=reliefF(Dnolabel,Dlabel,Num,k,typeD,Topn)%%ToachieveattributerankingusingreliefF%Dlabelisthearrayofthelabelforeachrecord%ThedatainDlabelshouldbeformat1,2,3andsoon%Dnolabelisthearrayofeachrecordwithoutlabel%Numislooptimeforrandomlychooseinstance%kisthenumberofnearesthitsandmisschoosed%Weightisoutputanditistherankingofeachattribute%typeDisthetypeofNolabeldata,ifitisnumerical,typeD=0;%ifitisnominalattributes,typeD=1;%[y,x]=size(Dnolabel);W=zeros(1,Topn);%calculatethelabelprobabilityLabelRange=max(Dlabel)-min(Dlabel)+1;LabelCount=zeros(1,LabelRange);LabelP=zeros(1,LabelRange);fori=1:yLabelCount(Dlabel(i))=LabelCount(Dlabel(i))+1;endforj=1:LabelRangeLabelP(j)=LabelCount(j)/y;endLabelP%*********************************************DistanceArray=zeros(y-1,2);%Weight=zeros(1,x);Weight=zeros(x,2);Diff=0;fori=1:xdominoDiff(i)=max(Dnolabel(:,i))-min(Dnolabel(:,i));end%foreachloopofrandomchooseinstanceforNumN=1:NumNumN%randomlychooseainstanceInstanceId=round([y.*rand(1)]);whileInstanceId==0,InstanceId=round([y.*rand(1)]);endindex=1;%calculatethedistancetothechoosedinstanceforeachotherinstancefori=1:yif(i~=InstanceId)forj=1:xDistanceArray(index,1)=DistanceArray(index,1)+...(Dnolabel(i,j)-Dnolabel(InstanceId,j))^2;endDistanceArray(index,1)=(DistanceArray(index,1)/x)^(0.5);DistanceArray(index,2)=i;index=index+1;endend%sortdistanceascendingDistanceArray=sortrows(DistanceArray,1);Result=zeros(LabelRange,y);classSize=zeros(1,LabelRange);fori=1:y-1class=Dlabel(DistanceArray(i,2));classSize(class)=classSize(class)+1;Result(class,classSize(class))=DistanceArray(i,2);end%foreachattributeMissW=0;%theinitialvalueforthepartrelativeMissintheweightHitW=0;%theinitialvalueforthepartrelativeHitintheweightforAttributeNum=1:x%calculatethedifferenceofmin-maxvalueinthisattributediff=Weight(AttributeNum,1);if(dominoDiff(AttributeNum)0.0000001)Weight(AttributeNum,1)=0;Weight(AttributeNum,2)=AttributeNum;continue;end%calculatetheweightforeachattributefori=1:k%kisthenumberofnearestneighbourschosenbyuseridHit=Result(Dlabel(InstanceId),k);%fortheHitsif(round(typeD)==0)diff=diff-abs(Dnolabel(idHit,AttributeNum)-...Dnolabel(InstanceId,AttributeNum)).../dominoDiff(AttributeNum)/k;elseif(round(Dnolabel(InstanceId,AttributeNum))...==round(Dnolabel(idHit,AttributeNum)))diff=diff-0;elsediff=diff-1;endendendforc=1:LabelRangeif(c==Dlabel(InstanceId))continue;endP=LabelP(c)/(1-LabelP(Dlabel(InstanceId)));fori=1:kidMiss=Result(c,i);%forthemissesif(round(typeD)==0)diff=diff+P*abs(Dnolabel(idMiss,AttributeNum)-...Dnolabel(InstanceId,AttributeNum)).../dominoDiff(AttributeNum)/k;elseif(round(Dnolabel(InstanceId,AttributeNum))...==round(Dnolabel(idHit,AttributeNum)))diff=diff;elsediff=diff+1;endendendend%form=1:LabelRangeWeight(AttributeNum,1)=diff;Weight(AttributeNum,2)=AttributeNum;end%forAttributeNum=1:xend%forNumN=1:NumWeight(AttributeNum,1)=diff/Num;Weight(AttributeNum,2)=AttributeNum;W1=sortrows(Weight);fori=1:TopnW(i)=W1(x-i+1,2);end
本文标题:reliefF算法源码
链接地址:https://www.777doc.com/doc-6259661 .html