99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀SAS—基于熵的連續(xù)變量的離散化
SAS—基于熵的連續(xù)變量的離散化
2017-03-31
收藏

SAS—基于熵的連續(xù)變量的離散化

今天介紹下整個程序邏輯及sas代碼的詳細介紹。

首先宏 %BinContVard調(diào)用了宏%CandSplits;然后宏%CandSplits又調(diào)用宏

%BestSplit、%GValue;最后通過宏%ApplyMap應(yīng)用于數(shù)據(jù)集。

下表是%BinContVar的參數(shù)

%BinContVar(Dsin,IVVar,DVVar,MMax,Acc,DsVarMap)

參數(shù)

描述

DSin

輸入數(shù)據(jù)集

IVVar

連續(xù)自變量

DVVar

二元因變量

MMax

設(shè)定的分組數(shù)量

Acc

最小分段的百分比規(guī)模

DsVarMap

包含映射規(guī)則的輸出數(shù)據(jù)集

首先,將初始數(shù)據(jù)集等距分為10段,然后把這些段數(shù)看作名義變量,基于熵方差利用最優(yōu)二元分類法找出最優(yōu)分群。

宏%bincontvar的主要是作用是連續(xù)變量的最優(yōu)分段,嵌套了%CandSplits,這個宏的作用是對分段后的數(shù)據(jù)集在進行分群,并選出最優(yōu)分群;宏%CandSplits嵌套了%BestSplits和%GValue兩個宏:宏%BestSplits是找出最優(yōu)分群,宏%GValue計算熵方差。

/*連續(xù)變量的最優(yōu)分段*/

/*

1.找出連續(xù)變量的最大最小值;

2.對連續(xù)變量進行等距分段,并把這些段數(shù)看成名義變量;

3.對2所分段數(shù)進行最優(yōu)分群,直到所設(shè)置的分群數(shù)

*/

%macro BinContVar(DSin, IVVar, DVVar, MMax, Acc, DSVarMap);


%local VarMax VarMin;

proc sql noprint;

select min(&IVVar), max(&IVVar) into :VarMin, :VarMax from &DSin;

quit;

%local Mbins i MinBinSize;

%let Mbins=%sysfunc(int(%sysevalf(1.0/&Acc)));/*設(shè)置等距分段數(shù)*/

%let MinBinSize=%sysevalf((&VarMax-&VarMin)/&Mbins);/*每段的長度*/

/*定義每段后每段的最大最小值*/

%do i=1 %to %eval(&Mbins);

%local Lower_&i Upper_&i;

%let Upper_&i = %sysevalf(&VarMin + &i * &MinBinSize);

%let Lower_&i = %sysevalf(&VarMin + (&i-1)*&MinBinSize);

%end;

%let Lower_1 = %sysevalf(&VarMin-0.0001);

%let Upper_&Mbins=%sysevalf(&VarMax+0.0001);

/*對連續(xù)變量 income 進行等距分段*/

data Temp_DS;

set &DSin;

%do i=1 %to %eval(&Mbins-1);

if &IVVar>=&&Lower_&i and &IVVar < &&Upper_&i Then Bin=&i;

%end;

if &IVVar>=&&Lower_&Mbins and &IVVar <= &&Upper_&MBins Then Bin=&MBins;

run;

/*計算出等距分段的每段最值*/

data temp_blimits;

%do i=1 %to %Eval(&Mbins-1);

Bin_LowerLimit=&&Lower_&i;

Bin_UpperLimit=&&Upper_&i;

Bin=&i;

output;

%end;

Bin_LowerLimit=&&Lower_&Mbins;

Bin_UpperLimit=&&Upper_&Mbins;

Bin=&Mbins;

output;

run;

proc sort data=temp_blimits;

by Bin;

run;

/*找出每段分段對應(yīng)的二元自變量每個類別的頻數(shù)*/

proc freq data=Temp_DS noprint;

table Bin*&DVvar /out=Temp_cross;

table Bin /out=Temp_binTot;

run;

proc sort data=temp_cross;

by Bin;

run;

proc sort data= temp_BinTot;

by Bin;

run;


data temp_cont;

merge Temp_cross(rename=count=Ni2 )temp_BinTot(rename=Count=total) temp_BLimits ;/*Ni2:每個分段下對應(yīng)類別的頻數(shù) total:每個分段下的總頻數(shù)*/

by Bin;

Ni1=total-Ni2;

PDV1=bin;

label Ni2= total=;

if Ni1=0 then output;

else if &DVVar=1 then output;

drop percent &DVVar;

run;


data temp_contold;

set temp_cont;

run;

/*合并所有含有ni1、ni2 、total= 0 的分段*/

proc sql noprint;

%local mx;

%do i=1 %to &Mbins;

select count(*) into : mx from Temp_cont where Bin=&i;

%if (&mx>0) %then %do;

select Ni1, Ni2, total, bin_lowerlimit, bin_upperlimit into

:Ni1,:Ni2,:total, :bin_lower, :bin_upper

from temp_cont where Bin=&i;

%if (&i=&Mbins) %then %do;

select max(bin) into :i1 from temp_cont where Bin<&Mbins;

%end;

%else %do;

select min(bin) into :i1 from temp_cont where Bin>&i;

%end;

%if (&Ni1=0) or (&Ni2=0) or (&total=0) %then %do;

update temp_cont set

Ni1=Ni1+&Ni1 ,

Ni2=Ni2+&Ni2 ,

total=total+&Total

where bin=&i1;

%if (&i<&Mbins) %then %do;

update temp_cont set Bin_lowerlimit = &Bin_lower where bin=&i1;

%end;

%else %do;

update temp_cont set Bin_upperlimit = &Bin_upper where bin=&i1;

%end;

delete from temp_cont where bin=&i;

%end;

%end;

%end;

quit;


proc sort data=temp_cont;

by pdv1;

run;

%local m;

/*將所有類別定義為宏變量m*/

data temp_cont;

set temp_cont;

i=_N_;

Var=bin;

Bin=1;

call symput("m", compress(_N_));

run;


%local Nbins ;

%let Nbins=1;

%DO %WHILE (&Nbins <&MMax);

/*從所有候選分群中根據(jù)熵選擇最優(yōu)分群*/

%CandSplits(temp_cont, Temp_Splits);

Data Temp_Cont;

set Temp_Splits;

run;

%let NBins=%eval(&NBins+1);

%end;


data temp_Map1 ;

set temp_cont(Rename=Var=OldBin);

drop Ni2 PDV1 Ni1 i ;

run;

proc sort data=temp_Map1;

by Bin OldBin ;

run;


data temp_Map2;

retain LL 0 UL 0 BinTotal 0;

set temp_Map1;

by Bin OldBin;

Bintotal=BinTotal+Total;

if first.bin then do;

LL=Bin_LowerLimit;

BinTotal=Total;

End;

if last.bin then do;

UL=Bin_UpperLimit;

output;

end;

drop Bin_lowerLimit Bin_upperLimit Bin OldBin total;

run;數(shù)據(jù)分析師培訓(xùn)

proc sort data=temp_map2;

by LL;

run;

data &DSVarMap;

set temp_map2;

Bin=_N_;

run;

%mend;


數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務(wù)器是否宕機 new_captcha: data.new_captcha, // 用于宕機時表示是新驗證碼的宕機 product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }