%% Display Unscaled Points When Using Missing Data
% Create a creditscorecard object using the CreditCardData.mat file to load the data with missing values.

load CreditCardData.mat 
head(dataMissing,5)

fprintf('Number of rows: %d\n',height(dataMissing))
fprintf('Number of missing values CustAge: %d\n',sum(ismissing(dataMissing.CustAge)))
fprintf('Number of missing values ResStatus: %d\n',sum(ismissing(dataMissing.ResStatus)))

% Use creditscorecard with the name-value argument 'BinMissingData' set to true to bin the missing numeric or categorical data in a separate bin. Apply automatic binning.

sc = creditscorecard(dataMissing,'IDVar','CustID','BinMissingData',true);
sc = autobinning(sc);

disp(sc)

%
% Display and plot bin information for numeric data for 'CustAge' that includes missing data in a separate bin labelled <missing>.

[bi,cp] = bininfo(sc,'CustAge');
disp(bi)
plotbins(sc,'CustAge')

% Display and plot bin information for categorical data for 'ResStatus' that includes missing data in a separate bin labelled <missing>.

[bi,cg] = bininfo(sc,'ResStatus');
disp(bi)
plotbins(sc,'ResStatus')

% For the 'CustAge' and 'ResStatus' predictors, there is missing data (NaNs and <undefined>) in the training data, and the binning process estimates a WOE value of -0.15787 and 0.026469 respectively for missing data in these predictors, as shown above.
%
% Use fitmodel to fit a logistic regression model using Weight of Evidence (WOE) data. fitmodel internally transforms all the predictor variables into WOE values, using the bins found with the automatic binning process. fitmodel then fits a logistic regression model using a stepwise method (by default). For predictors that have missing data, there is an explicit <missing> bin, with a corresponding WOE value computed from the data. When using fitmodel, the corresponding WOE value for the <missing> bin is applied when performing the WOE transformation.

[sc,mdl] = fitmodel(sc);

%
% Display unscaled points for predictors retained in the fitting model (to scale points use formatpoints).

PointsInfo = displaypoints(sc)

% Notice that points for the <missing> bin for CustAge and ResStatus are explicitly shown. These points are computed from the WOE value for the <missing> bin and the logistic model coefficients.
% For predictors that have no missing data in the training set, there is no explicit <missing> bin, and by default the points are set to NaN for missing data, and they lead to a score of NaN when running score. For predictors that have no explicit <missing> bin, use the name-value argument 'Missing' in formatpoints to indicate how missing data should be treated for scoring purposes.
% Copyright 2018 The MathWorks, Inc.