其他
SAS评分卡建模—PSI
The following article is from 风控建模
今天小编就介绍一下PSI这个指标。PSI也属于KL散度的一种,它的计算公式和IV的计算公式一样,同样是衡量两个样本的独立程度,值越大,独立程度越大,所以两个样本就发生了变化,这里注意和IV是反的。
话不多说了,毕竟小编的表达能力很不好,上SAS代码吧:
%macro psi(moddata=,indata=,scorename=,psi=);
/*
moddata : 参照数据集(这里是模型数据集)
indata:比较数据集(这里是验证数据集)
同时要注意两个数据集需要比较的特征名要一样,这里是验证分数稳定性,因此模型分数名称要一样
分数要自己分割
*/
proc sql;
create table temp001 as select min(&scorename) as min,max(&scorename) as max
from &moddata;
quit;
data temp002;
set &moddata;
if &scorename<=300 then score_level=1;
else if &scorename<=350 then score_level=2;
else if &scorename<=400 then score_level=3;
else if &scorename<=450 then score_level=4;
else if &scorename<=500 then score_level=5;
else if &scorename<=550 then score_level=6;
else if &scorename<=600 then score_level=7;
else if &scorename<=650 then score_level=8;
else if &scorename<=700 then score_level=9;
else score_level=10;
run;
proc sql;
create table temp003 as select score_level,count(*) as count
from temp002
group by score_level;
quit;
proc sql;
select count(*) into:sum from &moddata;
quit;
data modbase;
set temp003;
model_ratio=count/&sum.;
run;
proc sql;
create table temp001 as select min(&scorename) as min,max(&scorename) as max
from &indata;
quit;
data temp002;
set &indata;
if &scorename<=300 then score_level=1;
else if &scorename<=350 then score_level=2;
else if &scorename<=400 then score_level=3;
else if &scorename<=450 then score_level=4;
else if &scorename<=500 then score_level=5;
else if &scorename<=550 then score_level=6;
else if &scorename<=600 then score_level=7;
else if &scorename<=650 then score_level=8;
else if &scorename<=700 then score_level=9;
else score_level=10;
run;
proc sql;
create table temp003 as select score_level,count(*) as count
from temp002
group by score_level;
quit;
proc sql noprint;
select count(*) into:sum from &indata;
quit;
data temp004;
set temp003;
ratio=count/&sum.;
run;
proc sql;
create table psi as select a.score_level,a.model_ratio,b.ratio
from modbase a
full join temp004 b
on a.score_level=b.score_level;
quit;
data psi;
set psi;
if model_ratio=. then model_ratio=0;
if ratio=. then ratio=0;
psi=(model_ratio-ratio)*log(model_ratio/ratio);
run;
proc sql;
create table &psi. as select sum(psi) as psi
from psi;
quit;
%mend ;
更多精彩,戳这里:
点击阅读原文,即可报名信用评分卡模型课程