24小时热门版块排行榜    

查看: 1878  |  回复: 1

chyzh1986

新虫 (初入文坛)

[求助] 有用过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
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

驹行千里

金虫 (小有名气)

以前听一个师姐汇报过 在人脸识别中 特征选择环节用过 貌似效果不错 不过没有具体了解过
新手上路,从零开始
2楼2013-09-18 10:43:50
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 chyzh1986 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 一志愿武理085500机械专业总分300求调剂 +3 an10101 2026-03-24 7/350 2026-03-25 00:00 by 山鬼0-
[考研] 考研调剂 +4 呼呼?~+123456 2026-03-24 4/200 2026-03-24 23:16 by barlinike
[考研] 300分,材料,求调剂,英一数二 +5 超赞的 2026-03-24 5/250 2026-03-24 21:07 by 星空星月
[考研] 086003食品工程求调剂 +5 淼淼111 2026-03-24 5/250 2026-03-24 20:53 by lailaisimei
[考研] 306求0703调剂一志愿华中师范 +10 纸鱼ly 2026-03-21 11/550 2026-03-24 17:22 by qingfeng258
[考研] 材料学硕,求调剂 6+3 糖葫芦888ll 2026-03-22 7/350 2026-03-24 17:11 by hello七七
[考研] 一志愿北京化工大学材料与化工 264分各科过A区国家线 +3 哈哈157349 2026-03-21 3/150 2026-03-24 14:11 by zhyzzh
[考研] 求调剂 +7 十三加油 2026-03-21 7/350 2026-03-23 23:48 by 热情沙漠
[考研] 工科0856求调剂 +5 沐析汀汀 2026-03-21 5/250 2026-03-23 17:56 by 海瑟薇-
[考研] 293求调剂 +3 涛涛Wjt 2026-03-22 5/250 2026-03-22 22:21 by jiangpengfei
[考研] 308求调剂 +3 墨墨漠 2026-03-21 3/150 2026-03-22 16:54 by i_cooler
[考研] 306求调剂 +5 来好运来来来 2026-03-22 5/250 2026-03-22 16:17 by BruceLiu320
[考研] 319求调剂 +4 小力气珂珂 2026-03-20 4/200 2026-03-22 15:53 by ColorlessPI
[考研] 求助 +5 梦里的无言 2026-03-21 6/300 2026-03-21 17:51 by 学员8dgXkO
[考研] 266求调剂 +3 哇呼哼呼哼 2026-03-20 3/150 2026-03-21 16:46 by barlinike
[考研] 22 350 本科985求调剂,求老登收留 +3 李轶男003 2026-03-20 3/150 2026-03-21 13:28 by 搏击518
[考研] 288求调剂 +16 于海海海海 2026-03-19 16/800 2026-03-20 22:28 by JourneyLucky
[考研] 261求B区调剂,科研经历丰富 +3 牛奶很忙 2026-03-20 4/200 2026-03-20 19:34 by JourneyLucky
[考研] 一志愿南理工085701环境302求调剂院校 +3 葵梓卫队 2026-03-20 3/150 2026-03-20 19:28 by zhukairuo
[考研] 本科郑州大学物理学院,一志愿华科070200学硕,346求调剂 +4 我不是一根葱 2026-03-18 4/200 2026-03-19 09:11 by 浮云166
信息提示
请填处理意见