主要内容

fitmodel

拟合logistic回归模型与证据权重(WOE)数据

描述

例子

sc= fitmodel (sc拟合logistic回归模型的证据权重(WOE)数据,并将模型预测器名称和相应的系数存储在creditscorecard对象。

fitmodel内部将所有预测变量转换为WOE值,使用自动或手动分箱过程中找到的箱子。映射响应变量,使“Good”为1,“坏”是0.这意味着更高的(未缩放的)分数对应着更好的(风险更低的)个人(违约概率更小)。

或者,您可以使用setmodel提供您想要在逻辑回归模型中使用的预测因子名称,以及它们对应的系数。

例子

scmdl= fitmodel(sc拟合logistic回归模型的证据权重(WOE)数据,并将模型预测器名称和相应的系数存储在creditscorecard对象。fitmodel返回更新后的creditscorecard对象和GeneralizedLinearModel包含拟合模型的对象。

fitmodel内部将所有预测变量转换为WOE值,使用自动或手动分箱过程中找到的箱子。映射响应变量,使“Good”为1,“坏”是0.这意味着更高的(未缩放的)分数对应着更好的(风险更低的)个人(违约概率更小)。

或者,您可以使用setmodel提供您想要在逻辑回归模型中使用的预测因子名称,以及它们对应的系数。

例子

scmdl= fitmodel(___名称,值使用可选的名称-值对参数将逻辑回归模型拟合到证据的权重(WOE)数据中,并将模型预测器名称和相应的系数存储在creditscorecard对象。使用名称-值对参数,您可以选择哪个广义线性模型来拟合数据。fitmodel返回更新后的creditscorecard对象和GeneralizedLinearModel包含拟合模型的对象。

例子

全部折叠

创建一个creditscorecard对象使用CreditCardData.mat文件来加载数据(使用Refaat 2011的数据集)。

负载CreditCardDataSc =信用记分卡(数据,“IDVar”“CustID”
sc = creditscorecard与属性:GoodLabel: 0 responseval: 'status' WeightsVar: " VarNames: {1x11 cell} NumericPredictors: {1x6 cell} CategoricalPredictors: {'ResStatus' 'EmpStatus' 'OtherCC'} BinMissingData: 0 IDVar: 'CustID' PredictorVars: {1x9 cell} Data: [1200x11 table]

执行自动装箱。

Sc = autobinning(Sc)
sc = creditscorecard与属性:GoodLabel: 0 responseval: 'status' WeightsVar: " VarNames: {1x11 cell} NumericPredictors: {1x6 cell} CategoricalPredictors: {'ResStatus' 'EmpStatus' 'OtherCC'} BinMissingData: 0 IDVar: 'CustID' PredictorVars: {1x9 cell} Data: [1200x11 table]

使用fitmodel利用证据权重(WOE)数据拟合逻辑回归模型。fitmodel内部将所有预测变量转换为WOE值,使用自动装箱过程中找到的箱子。fitmodel然后使用逐步方法(默认)拟合逻辑回归模型。

Sc = fitmodel(Sc);
1.添加CustIncome, Deviance = 1490.8527, Chi2Stat = 32.588614, PValue = 1.1387992e-08添加TmWBank, Deviance = 1467.1415, Chi2Stat = 23.711203, PValue = 1.1192909e-063 .添加AMBalance, Deviance = 1455.5715, Chi2Stat = 11.569967, PValue = 0.00067025601。5.添加EmpStatus, Deviance = 1447.3451, Chi2Stat = 8.2264038, PValue = 0.0041285257。添加CustAge, Deviance = 1441.994, Chi2Stat = 5.3511754, PValue = 0.020708306添加ResStatus, Deviance = 1437.8756, Chi2Stat = 4.118404, PValue = 0.042419078。添加OtherCC, Deviance = 1433.707, Chi2Stat = 4.1686018, PValue = 0.041179769广义线性回归模型:状态~[7个预测因子中有8项的线性公式]分布=二项式估计系数:估计SE tStat pValue ________ ________ ______ __________(拦截)0.70239 0.064001 10.975 5.0538e-28 CustAge 0.60833 0.24932 2.44 0.014687 ResStatus 1.377 0.65272 2.1097 0.034888 EmpStatus 0.88565 0.293 3.0227 0.0025055 CustIncome 0.70164 0.21844 3.2121 0.0013179 TmWBank 1.1074 0.23271 4.7589 1.9464e-06 OtherCC 1.0883 0.52912 2.0569 0.039696 AMBalance 1.045 0.32214 3.2439 0.0011792 1200观测值,1192误差自由度离散度:1 Chi^2统计与常数模型:89.7, p-value = 1.4e-16

使用CreditCardData.mat文件以载入数据(dataWeights),其中包含一个列(RowWeights)的权重(使用Refaat 2011的数据集)。

负载CreditCardData

创建一个creditscorecard的可选名称-值对参数“WeightsVar”

sc =信用记分卡(dataWeights,“IDVar”“CustID”“WeightsVar”“RowWeights”
sc = creditscorecard与属性:GoodLabel: 0 responseval: 'status' WeightsVar: 'RowWeights' VarNames: {1x12 cell} NumericPredictors: {1x6 cell} CategoricalPredictors: {'ResStatus' 'EmpStatus' 'OtherCC'} BinMissingData: 0 IDVar: 'CustID' PredictorVars: {1x9 cell} Data: [1200x12 table]

执行自动装箱。

Sc = autobinning(Sc)
sc = creditscorecard与属性:GoodLabel: 0 responseval: 'status' WeightsVar: 'RowWeights' VarNames: {1x12 cell} NumericPredictors: {1x6 cell} CategoricalPredictors: {'ResStatus' 'EmpStatus' 'OtherCC'} BinMissingData: 0 IDVar: 'CustID' PredictorVars: {1x9 cell} Data: [1200x12 table]

使用fitmodel利用证据权重(WOE)数据拟合逻辑回归模型。fitmodel内部将所有预测变量转换为WOE值,使用自动装箱过程中找到的箱子。fitmodel然后使用逐步方法(默认)拟合逻辑回归模型。当可选的名称-值对参数“WeightsVar”用于指定观察(样本)权重,mdl输出使用加权计数stepwiseglm而且fitglm

[sc,mdl] = fitmodel(sc);
1.添加CustIncome, Deviance = 764.3187, Chi2Stat = 15.81927, PValue = 6.968927e-05添加TmWBank, Deviance = 751.0215, Chi2Stat = 13.29726, PValue = 0.0002657942加AMBalance, Deviance = 743.7581, Chi2Stat = 7.263384, PValue = 0.007037455广义线性回归模型:logit(status) ~ 1 + CustIncome + TmWBank + AMBalance分布=二项估计系数:估计SE tStat pValue ________ ________ ______ __________(拦截)0.70642 0.088702 7.964 1.6653e-15 CustIncome 1.0268 0.25758 3.9862 6.7132e-05 TmWBank 1.0973 0.31294 3.5063 0.0004543 AMBalance 1.0039 0.37576 2.6717 0.0075464 1200观测值,1196误差自由度离散度:1 Chi^2统计与常数模型:36.4,p值= 6.22e-08

创建一个creditscorecard对象使用CreditCardData.mat文件来加载数据(使用Refaat 2011的数据集)。

负载CreditCardDataSc =信用记分卡(数据,“IDVar”“CustID”
sc = creditscorecard与属性:GoodLabel: 0 responseval: 'status' WeightsVar: " VarNames: {1x11 cell} NumericPredictors: {1x6 cell} CategoricalPredictors: {'ResStatus' 'EmpStatus' 'OtherCC'} BinMissingData: 0 IDVar: 'CustID' PredictorVars: {1x9 cell} Data: [1200x11 table]

执行自动装箱。

Sc = autobinning(Sc,“算法”“EqualFrequency”
sc = creditscorecard与属性:GoodLabel: 0 responseval: 'status' WeightsVar: " VarNames: {1x11 cell} NumericPredictors: {1x6 cell} CategoricalPredictors: {'ResStatus' 'EmpStatus' 'OtherCC'} BinMissingData: 0 IDVar: 'CustID' PredictorVars: {1x9 cell} Data: [1200x11 table]

使用fitmodel利用证据权重(WOE)数据拟合逻辑回归模型。fitmodel内部将所有预测变量转换为WOE值,使用自动装箱过程中找到的箱子。设置VariableSelection到的名称-值对参数FullModel为了说明所有的预测因素必须包括在拟合的逻辑回归模型中。

Sc = fitmodel(Sc,“VariableSelection”“FullModel”);
广义线性回归模型:状态~[9个预测因子中有10项的线性公式]分布=二项估计系数:估计SE tStat pValue ________ ________ _______ _________ (Intercept) 0.70262 0.063862 11.002 3.734e-28 CustAge 0.57683 0.27064 2.1313 0.033062 TmAtAddress 1.0653 0.55233 1.9287 0.053762 ResStatus 1.4189 0.55233 2.1775 0.029441 EmpStatus 0.89916 0.29217 3.0776 0.002087 CustIncome 0.77506 0.21942 3.5323 0.0004119 TmWBank 1.0826 0.26583 4.0723 4.648e-05 OtherCC 1.1354 0.52827 2.1493 0.031612 AMBalance 0.99315 0.32642 3.0425 0.0023459 UtilRate 0.16723 0.55745 0.29999 0.76419 1200 observations,离散度:1 Chi^2统计量vs.常数模型:85.6,p值= 1.25e-14

创建一个creditscorecard对象使用CreditCardData.mat文件来加载dataMissing缺少值。

负载CreditCardData.mat头(dataMissing, 5)
ans =5×11表CustID CustAge TmAtAddress ResStatus EmpStatus CustIncome TmWBank OtherCC AMBalance UtilRate status ______ _______ ___________ ___________ _________ __________ _______ _______ _________ ________ ______ 1 53 62  Unknown 50000 55 Yes 1055.9 0.22 0 2 61 22 Home Owner Employed 52000 25 Yes 1161.6 0.24 0 3 47 30 Tenant Employed 37000 61 No 877.23 0.29 0 4 NaN 75 Home Owner Employed 53000 20 Yes 157.37 0.08 05 68 56 Home Owner Employed 53000 14 Yes 561.84 0.11 0
流('行数:%d\n'、高度(dataMissing))
行数:1200
流(CustAge: %d\n总和(ismissing (dataMissing.CustAge)))
缺少值的数量CustAge: 30
流(ResStatus: %d\n总和(ismissing (dataMissing.ResStatus)))
ResStatus: 40

使用creditscorecard使用name-value参数“BinMissingData”设置为真正的将缺失的数字或类别数据收纳到单独的收纳箱内。

sc =信用记分卡(数据丢失,“IDVar”“CustID”“BinMissingData”,真正的);Sc = autobinning(Sc);disp (sc)
带属性的信用记分卡:GoodLabel: 0 responsear: 'status' WeightsVar: " VarNames: {1×11 cell} NumericPredictors: {'CustAge' 'TmAtAddress' 'CustIncome' 'TmWBank' 'AMBalance' 'UtilRate'} CategoricalPredictors: {'ResStatus' 'EmpStatus' 'OtherCC'} BinMissingData: 1 IDVar: 'CustID' PredictorVars: {1×9 cell} Data: [1200×11 table]

的数值数据显示和绘制bin信息“CustAge”这包括丢失的数据在一个单独的箱子标记< >失踪

[bi,cp] = bininfo(sc,“CustAge”);disp (bi)
Bin Good Bad Odds WOE InfoValue _____________ _____________ ________ __________ {'[-Inf,33)'} 69 52 1.3269 -0.42156 0.018993 {'[33,37)'} 63 45 1.4 -0.36795 0.012839 {'[37,40)'} 72 47 1.5319 -0.2779 0.0079824 {'[40,46)'} 172 89 1.9326 -0.04556 0.0004549 {'[44,51)'} 59 25 2.36 0.15424 0.0016199 {'[44,51)'} 99 41 2.4146 0.17713 0.0035449 {'[51,58)'} 157 62 2.5323 0.22469 0.0088407 {''} 19 11 1.7273 -0.15787 0.00063885{'合计'}803 3972.0227 NaN 0.087112
plotbins (sc,“CustAge”

显示和绘制分类数据的bin信息“ResStatus”这包括丢失的数据在一个单独的箱子标记< >失踪

[bi,cg] = bininfo(sc,“ResStatus”);disp (bi)
Bin Good Bad Odds WOE InfoValue ______________ _____________ _________ __________ {'Tenant'} 296 161 1.8385 -0.095463 0.0035249 {'Home Owner'} 352 171 2.0585 0.017549 0.00013382 {'Other'} 128 52 2.4615 0.19637 0.0055808 {''} 27 13 2.0769 0.026469 2.3248e-05 {'Totals'} 803 397 2.0227 NaN 0.0092627
plotbins (sc,“ResStatus”

使用fitmodel利用证据权重(WOE)数据拟合逻辑回归模型。fitmodel内部将所有预测变量转换为WOE值,使用自动装箱过程中找到的箱子。fitmodel然后使用逐步方法(默认)拟合逻辑回归模型。对于缺少数据的预测器,有一个显式的< >失踪bin,并从数据中计算出相应的WOE值。当使用fitmodel,当执行WOE转换时, bin对应的WOE值将被应用。例如,客户年龄的缺失值(CustAge)以-0.15787的WOE值是什么< >失踪Bin用于CustAge预测。然而,当“BinMissingData”为false,为CustAge遗体仍下落不明()当应用WOE变换时。

[sc,mdl] = fitmodel(sc);
1.添加CustIncome, Deviance = 1490.8527, Chi2Stat = 32.588614, PValue = 1.1387992e-08添加TmWBank, Deviance = 1467.1415, Chi2Stat = 23.711203, PValue = 1.1192909e-063 .添加AMBalance, Deviance = 1455.5715, Chi2Stat = 11.569967, PValue = 0.00067025601。5.添加EmpStatus, Deviance = 1447.3451, Chi2Stat = 8.2264038, PValue = 0.0041285257。添加CustAge, Deviance = 1442.8477, Chi2Stat = 4.4974731, PValue = 0.0339449797.添加ResStatus, Deviance = 1438.9783, Chi2Stat = 3.86941, PValue = 0.049173805。加OtherCC, Deviance = 1434.9751, Chi2Stat = 4.0031966, PValue = 0.045414057广义线性回归模型:logit(status) ~ 1 + CustAge + ResStatus + EmpStatus + CustIncome + TmWBank + OtherCC + AMBalance分布=二项估计系数:估计SE tStat pValue ________ ________ ______ __________(拦截)0.70229 0.063959 10.98 4.7498e-28 CustAge 0.57421 0.25708 2.2335 0.025513 ResStatus 1.3629 0.66952 2.0356 0.04179 EmpStatus 0.88373 0.2929 3.0172 0.002551 CustIncome 0.73535 0.2159 3.406 0.00065929 TmWBank 1.1065 0.23267 4.7556 1.9783e-06 OtherCC 1.0648 0.52826 2.0156 0.043841 AMBalance 1.0446 0.32197 3.2443 0.0011775 1200观测值,1192误差自由度离散度:1 Chi^2统计与常量模型:88.5, p-value = 2.55e-16

输入参数

全部折叠

信用记分卡模型,指定为creditscorecard对象。使用creditscorecard要创建creditscorecard对象。

名称-值参数

指定可选参数对为Name1 = Value1,…,以=家,在那里的名字参数名称和价值对应的值。名称-值参数必须出现在其他参数之后,但对的顺序无关紧要。

在R2021a之前,使用逗号分隔每个名称和值,并将其括起来的名字在报价。

例子:[sc,mdl] = fitmodel(sc,'VariableSelection','FullModel')

拟合的预测变量creditscorecard对象,指定为逗号分隔的对,由“PredictorVars”和一个由字符向量组成的单元格数组。当提供时,creditscorecard对象属性PredictorsVars是更新。请注意,原始数据集中预测器的顺序是强制的,无论其顺序如何“PredictorVars”提供。类时,用于创建的预测器creditscorecard对象(通过使用creditscorecard)。

数据类型:细胞

拟合逻辑回归模型的变量选择方法,指定为由逗号分隔的对组成“VariableSelection”还有一个带值的字符向量“逐步”“FullModel”

  • 逐步-使用逐步选择方法,调用统计和机器学习工具箱™函数stepwiseglm.只有变量PredictorVars可以潜在地成为模型的一部分并使用StartingModel名称-值对参数来选择起始模型。

  • FullModel-拟合模型中所有预测变量PredictorVars名称-值对参数和调用fitglm

请注意

中的变量PredictorVars的属性creditscorecard对象可以潜在地成为逻辑回归模型的一部分,只有线性项包含在该模型中,没有相互作用或任何其他高阶项。

映射响应变量,使“Good”为1“坏”就是0

数据类型:字符

的初始模型逐步变量选择方法,指定为由逗号分隔的对组成“StartingModel”还有一个带值的字符向量“不变”“线性”.此选项确定统计和机器学习工具箱功能的初始模型(常数或线性)stepwiseglm开始。

  • 常数-使用空(仅常量)模型启动逐步方法。

  • 线性-从一个完整的(所有预测器)模型开始逐步方法。

请注意

StartingModel仅用于逐步选择VariableSelection而且对FullModel选择VariableSelection

数据类型:字符

指示符在命令行上显示模型信息,指定为逗号分隔的对,由“显示”还有一个带值的字符向量“上”“关闭”

数据类型:字符

输出参数

全部折叠

信用记分卡模型,作为更新返回creditscorecard对象。的creditscorecard对象包含关于模型预测因子和用于拟合WOE数据的系数的信息。的详细信息creditscorecard对象,看到creditscorecard

拟合逻辑模型,作为类型对象返回GeneralizedLinearModel包含拟合模型。有关a的更多信息GeneralizedLinearModel对象,看到GeneralizedLinearModel

请注意

当创建creditscorecard对象与creditscorecard,如果是可选的名称-值对参数WeightsVar被用来指定观察(样本)权重,然后mdl使用加权计数stepwiseglm而且fitglm

更多关于

全部折叠

使用fitmodel与重量

当观察权重提供在信用记分卡数据时,用权重对模型系数进行标定。

底层的统计和机器学习工具箱功能stepwiseglm而且fitglm支持观测权重。权重也通过WOE值影响logistic模型。在拟合逻辑模型之前,WOE转换应用于所有预测因子。观测权值直接影响WOE值。有关更多信息,请参见使用bininfo和Weights而且使用观察权重的信用记分卡建模

因此,通过logistic模型系数和WOE值,信用记分卡点和最终得分取决于观察权重。

模型

本文采用逻辑回归模型creditscorecard对象。

在模型中,“坏”的概率定义为:ProbBad = exp(-s) / (1 + exp(-s))

参考文献

[1]安德森信用评分工具包。牛津大学出版社,2007年。

[2] Refaat, M。信用风险记分卡:使用SAS开发和实现。lulu.com, 2011。

版本历史

在R2014b中引入

Baidu
map