matlab实现SMOTE

SMOTE算法流程:


matlab实现SMOTE_第1张图片


function [ sample ] = mySMOTE( minority,radio,k,attr_type )
% [ sample ] = mySMOTE( minority,radio,k,attr_type )
%minority:少数样本,不包括属性值
%radio:生成新样本占少数样本的比例
%k: 近邻个数
%attr_type:属性类型,0:连续;1:离散
%sample:输出新样本
if(nargin<2)%nargin 函数输入变量个数
    help mySOMTE
elseif(nargin<3)
    radio=1;
    k=1;
    attr_type=zeros(1,size(minority,2));
end

[minority_num,attr_num]=size(minority);%少数样本个数
if radio<=0
%warning('radio=%d',radio,'is less than 0');
%return
 error('radio is less than 0');
elseif radio<1
    new_num=floor(radio*minority_num);
    sample_index=randperm(minority_num,new_num);%随机产生
    radio=1;
else
    radio=round(radio);
    sample_index=1:minority_num;    
en

你可能感兴趣的:(matlab实现SMOTE)