24小时热门版块排行榜    

查看: 1943  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 时间戳变了,能看出什么问题? +16 基诺咪客 2026-08-17 20/1000 2026-08-20 12:44 by 201120518022
[基金申请] 重要消息,中午系统在维护 +11 yuleib84 2026-08-18 12/600 2026-08-20 11:09 by xskun
[基金申请] 哪位老哥知道今年的国自然具体哪一天放榜? +16 Ldrop2023 2026-08-13 20/1000 2026-08-20 11:07 by xskun
[基金申请] 言之凿凿,8月21号(明天)放榜 +12 医学老男孩 2026-08-20 14/700 2026-08-20 10:53 by ran2233
[基金申请] 只有每年这种时候来逛逛小木虫 +21 yaoyewhu2008 2026-08-20 21/1050 2026-08-20 10:37 by Vivilian
[基金申请] 今天基金会出结果吗?20260819 +14 kkkl_v 2026-08-19 15/750 2026-08-20 08:21 by sunzitan
[基金申请] filecode,4个jtjc了 +11 ziyangfang 2026-08-19 13/650 2026-08-19 21:28 by aasahr
[教师之家] 为什么余额宝的年化利率越来越低?主要原因有哪些? +5 瞬息宇宙 2026-08-15 5/250 2026-08-19 20:23 by super2002521
[基金申请] 今天放榜没戏了吧 +4 yuleib84 2026-08-19 5/250 2026-08-19 19:52 by hhs666
[基金申请] 今天放榜吗? +14 布布和一二 2026-08-19 15/750 2026-08-19 18:07 by gltch
[基金申请] filecode=后面第一个是大写字母 +10 wangze12014 2026-08-14 12/600 2026-08-19 16:56 by 苦难博士
[基金申请] 2027广东省杰青 +4 奶牛小黑 2026-08-15 10/500 2026-08-19 11:02 by wanfengnew
[基金申请] 朋友圈看到的 +6 wangzilk 2026-08-18 8/400 2026-08-19 10:55 by Haru815
[基金申请] 什么时候开奖? +6 CrisMessi 2026-08-18 6/300 2026-08-19 08:06 by Equinoxhua
[基金申请] 明天放榜? +5 Shxjjxjkx 2026-08-18 5/250 2026-08-18 18:14 by -大大大大大-
[论文投稿] 投稿咨询 +4 wwm09 2026-08-17 6/300 2026-08-18 15:36 by wwm09
[基金申请] 今天维护系统维护 祝所有人 高中 +8 gjjjzhong 2026-08-18 9/450 2026-08-18 13:01 by 家与远方
[基金申请] 93BebMhtakh前后11位开头都是大写 +4 且听虎啸 2026-08-17 5/250 2026-08-18 00:49 by 蔡棒棒菂
[基金申请] 感觉是下周放榜了 +6 angus9576 2026-08-17 11/550 2026-08-17 23:57 by angus9576
[基金申请] 今天系统多次维护,明天很可能放榜! +8 zju2000 2026-08-16 9/450 2026-08-17 12:20 by lmz0216
信息提示
请填处理意见