%% Validate a Credit Score Card Model With Weights
% Use the CreditCardData.mat file to load the data (dataWeights) that contains a column (RowWeights) for the weights (using a dataset from Refaat 2011).

load CreditCardData

%
% Create a creditscorecard object using the optional name-value pair argument for 'WeightsVar'.

sc = creditscorecard(dataWeights,'IDVar','CustID','WeightsVar','RowWeights')

%
% Perform automatic binning.

sc = autobinning(sc)

%
% Fit the model.

sc = fitmodel(sc);

%
% Format the unscaled points.

sc = formatpoints(sc, 'PointsOddsAndPDO',[500,2,50]);

%
% Score the data.

scores = score(sc);

%
% Validate the credit scorecard model by generating the CAP, ROC, and KS plots. When the optional name-value pair argument 'WeightsVar' is used to specify observation (sample) weights, the T table uses statistics, sums, and cumulative sums that are weighted counts.

[Stats,T] = validatemodel(sc,'Plot',{'CAP','ROC','KS'});
Stats
T(1:10,:)

% Copyright 2012 The MathWorks, Inc.