setmodel

Syntax

Description

sc = setmodel(sc,ModelPredictors,ModelCoefficients)
sets the predictors and coefficients of a linear logistic regression model
fitted outside the creditscorecard object and returns an
updated creditscorecard object. The predictors and
coefficients are used for the computation of scorecard points. Use
setmodel in lieu of fitmodel, which fits a
linear logistic regression model, because setmodel offers
increased flexibility. For example, when a model fitted with fitmodel needs to be
modified, you can use setmodel. For more information, see
Workflows for Using setmodel.

Note

When using setmodel, the following assumptions apply:

The model coefficients correspond to a linear logistic
regression model (where only linear terms are included
in the model and there are no interactions or any other
higher-order terms).

The model was previously fitted using Weight of
Evidence (WOE) data with the response mapped so that
‘Good’ is 1 and ‘Bad’ is
0.

Examples

Modify a GLM Model Fitted with fitmodel

This example shows how to use setmodel to make modifications to a logistic regression model initially fitted using the fitmodel function, and then set the new logistic regression model predictors and coefficients back into the creditscorecard object.

Create a creditscorecard object using the CreditCardData.mat file to load the data (using a dataset from Refaat 2011).

The standard workflow is to use the fitmodel function to fit a logistic regression model using a stepwise method. However, fitmodel only supports limited options regarding the stepwise procedure. You can use the optional mdl output argument from fitmodel to get a copy of the fitted GeneralizedLinearModel object, to later modify.

Suppose you want to include, or "force," the predictor 'UtilRate' in the logistic regression model, even though the stepwise method did not include it in the fitted model. You can add 'UtilRate' to the logistic regression model using the GeneralizedLinearModel object mdl directly.

Use setmodel to update the model predictors and model coefficients in the creditscorecard object. The ModelPredictors input argument does not explicitly include a string for the intercept. However, the ModelCoefficients input argument does have the intercept information as its first element.

Fit a Logistic Regression Model Outside of the creditscorecard Object

This example shows how to use setmodel to fit a logistic regression model directly, without using the fitmodel function, and then set the new model predictors and coefficients back into the creditscorecard object. This approach gives more flexibility regarding options to control the stepwise procedure. This example fits a logistic regression model with a nondefault value for the 'PEnter' parameter, the criterion to admit a new predictor in the logistic regression model during the stepwise procedure.

Create a creditscorecard object using the CreditCardData.mat file to load the data (using a dataset from Refaat 2011). Use the 'IDVar' argument to indicate that 'CustID' contains ID information and should not be included as a predictor variable.

The logistic regression model needs to be fit with Weight of Evidence (WOE) data. The WOE transformation is a special case of binning, since the data first needs to be binned, and then the binned information is mapped to the corresponding WOE values. This transformation is done using the bindata function. bindata has an argument that prepares the data for the model fitting step. By setting the bindata name-value pair argument for 'OutputType' to WOEModelInput':

All predictors are converted to WOE values.

The output contains only predictors and response (no 'IDVar' or any unused variables).

Predictors with infinite or undefined (NaN) WOE values are discarded.

The response values are mapped so that "Good" is 1 and "Bad" is 0 (this implies that higher unscaled scores correspond to better, less risky customers).

bd = bindata(sc,'OutputType','WOEModelInput');

For example, the first ten rows in the original data for the variables 'CustAge', 'ResStatus', 'CustIncome', and 'status' (response variable) look like this:

Fit a logistic linear regression model using a stepwise method with the Statistics and Machine Learning Toolbox™ function stepwiseglm, but use a nondefault value for the 'PEnter' and 'PRemove' optional arguments. The predictors 'ResStatus' and 'OtherCC' would normally be included in the logistic linear regression model using default options for the stepwise procedure.

Use setmodel to update the model predictors and model coefficients in the creditscorecard object. The ModelPredictors input argument does not explicitly include a string for the intercept. However, the ModelCoefficients input argument does have the intercept information as its first element.

Input Arguments

sc — Credit scorecard modelcreditscorecard object

Credit scorecard model, specified as a
creditscorecard object. Use creditscorecard to create
a creditscorecard object.

ModelPredictors — Predictor names included in fitted modelcell array of character vectors with predictor values
{'PredictorName1','PredictorName2',...}

Predictor names included in the fitted model, specified as a cell
array of character vectors as
{'PredictorName1','PredictorName2',...}. The
predictor names must match predictor variable names in the
creditscorecard object.

Note

Do not include a character vector for the constant term in
ModelPredictors,
setmodel internally handles the
'(Intercept)' term based on the number of
model coefficients (see
ModelCoefficients).

Model coefficients corresponding to the model predictors, specified as
a numeric array of model coefficients,
[coeff1,coeff2,..]. If N is
the number of predictor names provided in
ModelPredictors, the size of
ModelCoefficients can be N
or N+1. If ModelCoefficients has
N+1 elements, then the first coefficient is used
as the '(Intercept)' of the fitted model. Otherwise,
the '(Intercept)' is set to
0.

Data Types: double

Output Arguments

sc — Credit scorecard modelcreditscorecard object

Credit scorecard model, returned as an updated
creditscorecard object. The
creditscorecard object contains information about
the model predictors and coefficients of the fitted model. For more
information on using the creditscorecard object, see
creditscorecard.

More About

Workflows for Using setmodel

When using setmodel, there are two
possible workflows to set the final model predictors and model coefficients into
a creditscorecard object.

The first workflow is:

Use fitmodel to get the
optional output argument mdl. This is a
GeneralizedLinearModel object and you can add
and remove terms, or modify the parameters of the stepwise
procedure. Only linear terms can be in the model (no interactions or
any other higher-order terms).

Once the GeneralizedLinearModel object is
satisfactory, set the final model predictors and model coefficients
into the creditscorecard object using the
setmodel input arguments for
ModelPredictors and
ModelCoefficients.

An alternate workflow is:

Obtain the Weight of Evidence (WOE) data using bindata. Use the
'WOEModelInput' option for the
'OutputType' name-value pair argument in
bindata to ensure that:

The predictors data is transformed to WOE.

Only predictors whose bins have finite WOE values are
included.

The response variable is placed in the last
column.

The response variable is mapped (“Good”
is 1 and “Bad” is
0).

Use the data from the previous step to fit a linear logistic
regression model (only linear terms in the model, no interactions,
or any other higher-order terms). See, for example, stepwiseglm.

Once the GeneralizedLinearModel object is
satisfactory, set the final model predictors and model coefficients
into the creditscorecard object using the
setmodel input arguments for
ModelPredictors and
ModelCoefficients.