%% Display Points for creditscorecard Object That Contains Missing Data
% To create a creditscorecard object using the CreditCardData.mat file, load the data (using a dataset from Refaat 2011).  Using the dataMissing dataset, set the 'BinMissingData' indicator to true.

load CreditCardData.mat 
sc = creditscorecard(dataMissing,'BinMissingData',true); 

% Use autobinning with the creditscorecard object.

sc = autobinning(sc);

% The binning map or rules for categorical data are summarized in a "category grouping" table, returned as an optional output. By default, each category is placed in a separate bin. Here is the information for the predictor ResStatus.

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

% To group categories 'Tenant' and 'Other', modify the category grouping table cg, so the bin number for 'Other' is the same as the bin number for 'Tenant'. Then use modifybins to update the creditscorecard object.

cg.BinNumber(3) = 2; 
sc = modifybins(sc,'ResStatus','Catg',cg); 

% Display the updated bin information using bininfo. Note that the bin labels has been updated and that the bin membership information is contained in the category grouping cg.

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

% Use formatpoints with the 'Missing' name-value pair argument to indicate that missing data is assigned 'maxpoints'.

sc = formatpoints(sc,'BasePoints',true,'Missing','maxpoints','WorstAndBest',[300 800]); 

% Use fitmodel to fit the model.

sc = fitmodel(sc,'VariableSelection','fullmodel','Display','Off'); 

% Then use displaypoints with the creditscorecard object to return a table of points for all bins of all predictor variables used in the compactCreditScorecard object. By setting the displaypoints name-value pair argument for  'ShowCategoricalMembers' to true, all the members contained in each individual group are displayed.

[PointsInfo,MinScore,MaxScore] = displaypoints(sc,'ShowCategoricalMembers',true)

% Copyright 2018 The MathWorks, Inc.