| 查看: 1870 | 回复: 1 | ||
[求助]
有用过reliefF函数的吗?
|
|
有用过这个函数的吗: function W = reliefF(Dnolabel,Dlabel,Num,k,typeD,Topn) 这里面的参数都代表什么,应该怎么设置呢?要是有个例子就更好了,谢谢~ 函数内容如下: function W = reliefF(Dnolabel,Dlabel,Num,k,typeD,Topn) % % To achieve attribute ranking using reliefF % Dlabel is the array of the label for each record % The data in Dlabel should be format 1,2,3 and so on % Dnolabel is the array of each record without label % Num is loop time for randomly choose instance % k is the number of nearest hits and miss choosed % Weight is output and it is the ranking of each attribute % typeD is the type of Nolabel data, if it is numerical, typeD=0; % if it is nominal attributes, typeD=1; % [y,x]=size(Dnolabel); W = zeros(1,Topn); %calculate the label probability LabelRange=max(Dlabel)-min(Dlabel)+1; LabelCount=zeros(1,LabelRange); LabelP=zeros(1,LabelRange); for i=1:y LabelCount(Dlabel(i))=LabelCount(Dlabel(i))+1; end for j=1:LabelRange LabelP(j)=LabelCount(j)/y; end LabelP %********************************************* DistanceArray=zeros(y-1,2); %Weight=zeros(1,x); Weight=zeros(x,2); Diff=0; for i=1:x dominoDiff(i) = max(Dnolabel(:,i))- min(Dnolabel(:,i)); end %for each loop of random choose instance for NumN=1:Num NumN %randomly choose a instance InstanceId = round([y.*rand(1)]); while InstanceId==0, InstanceId = round([y.*rand(1)]); end index = 1; %calculate the distance to the choosed instance for each other instance for i=1:y if (i~=InstanceId) for j=1:x DistanceArray(index,1)=DistanceArray(index,1)+... (Dnolabel(i,j)-Dnolabel(InstanceId,j))^2; end DistanceArray(index,1)=(DistanceArray(index,1)/x)^(0.5); DistanceArray(index,2)=i; index = index+1; end end %sort distance ascending DistanceArray=sortrows(DistanceArray,1); Result=zeros(LabelRange,y); classSize = zeros(1,LabelRange); for i=1:y-1 class = Dlabel(DistanceArray(i,2)); classSize(class) = classSize(class)+1; Result(class,classSize(class))=DistanceArray(i,2); end %for each attribute MissW=0; %the initial value for the part relative Miss in the weight HitW=0; %the initial value for the part relative Hit in the weight for AttributeNum=1:x %calculate the difference of min-max value in this attribute diff = Weight(AttributeNum,1); if (dominoDiff(AttributeNum)<0.0000001) Weight(AttributeNum,1)=0; Weight(AttributeNum,2)=AttributeNum; continue; end %calculate the weight for each attribute for i=1:k %k is the number of nearest neighbours chosen by user idHit = Result(Dlabel(InstanceId),k ); %for the Hits if(round(typeD)==0) diff = diff - abs( Dnolabel(idHit, AttributeNum) -... Dnolabel(InstanceId, AttributeNum) )... /dominoDiff(AttributeNum)/k; else if (round(Dnolabel(InstanceId,AttributeNum))... ==round(Dnolabel(idHit, AttributeNum))) diff=diff-0; else diff=diff-1; end end end for c=1:LabelRange if (c==Dlabel(InstanceId)) continue; end P=LabelP(c)/(1-LabelP(Dlabel(InstanceId))); for i=1:k idMiss = Result(c,i); %for the misses if (round(typeD)==0) diff = diff + P*abs( Dnolabel(idMiss, AttributeNum) -... Dnolabel(InstanceId, AttributeNum) )... /dominoDiff(AttributeNum)/k; else if (round(Dnolabel(InstanceId,AttributeNum))... ==round(Dnolabel(idHit, AttributeNum))) diff=diff; else diff=diff+1; end end end end % for m=1:LabelRange Weight(AttributeNum,1)=diff; Weight(AttributeNum,2)=AttributeNum; end % for AttributeNum=1:x end % for NumN=1:Num Weight(AttributeNum,1)=diff/Num; Weight(AttributeNum,2)=AttributeNum; W1 = sortrows(Weight); for i = 1:Topn W(i) = W1(x-i+1,2); end |
» 猜你喜欢
有时候真觉得大城市人没有县城人甚至个体户幸福
已经有11人回复
表哥与省会女结婚,父母去帮带孩子被省会女气回家生重病了
已经有7人回复
同年申请2项不同项目,第1个项目里不写第2个项目的信息,可以吗
已经有8人回复
依托企业入选了国家启明计划青年人才。有无高校可以引进的。
已经有7人回复
依托企业入选了国家启明计划青年人才。有无高校可以引进的。
已经有10人回复
天津大学招2026.09的博士生,欢迎大家推荐交流(博导是本人)
已经有9人回复
有院领导为了换新车,用横向课题经费买了俩车
已经有10人回复
AI 太可怕了,写基金时,提出想法,直接生成的文字比自己想得深远,还有科学性
已经有6人回复

2楼2013-09-18 10:43:50













回复此楼