You can use the ASSESS procedure in SAS® Viya® to assess the performance of a previously fitted model. For binary response models, PROC ASSESS computes a set of statistics including lift, cumulative lift, gain and others. It can also produce statistics defining the ROC curve and optimal points on that curve. For more on plotting the ROC curve with identified optimal points, see SAS KB0060666. The gain and lift statistics from PROC ASSESS focus on counts or proportions (or percentages) of the observed event level of the binary response. They are computed after grouping the predicted event proportions in the observations into quantile-based bins – typically 10 (deciles) or 20 (demi-deciles or ventiles) as controlled by the NBINS= option. By specifying the LIFTOUT= option in the PROC ASSESS statement, you can create a data set containing these statistics. You can then produce plots of these statistics as shown in the example below.
While these statistics are most commonly used for binary response data, lift and gain can also be computed for a continuous response by focusing on sums or means of the observed response within the bins rather than on counts or percentages. PROC ASSESS computes different statistics for continuous responses but the example below computes and plots lift and gain for these responses.
For both types of response, binary and continuous, panels of plots are produced using suitable templates defined using PROC TEMPLATE. See The Graphing Templates below. Once the PROC TEMPLATE statements are submitted, the resulting templates are stored in your SASUSER.TEMPLAT template store and can be used in the current or a future SAS® session. You use a template by specifying its name and the name of the data set you want to apply it to in PROC SGRENDER as shown in the following examples. The examples create the data set of assessment statistics and call PROC SGRENDER to produce the plots. They assume that the PROC TEMPLATE code has been run to define and store the templates.
The following statements use the home equity data in the SAMPSIO.HMEQ data set. The binary response, BAD, indicates delinquency of the loan (1=delinquent; 0=not). PROC LOGSELECT is used to fit a logistic model to the response after starting a CAS session in SAS Viya and creating a CAS libref called SASCAS1. LASSO model selection is used to select predictive variables to keep in the model. The OUTPUT statement saves a data set containing the predicted probabilities of the event (delinquency) and nonevent. The COPYVAR= option also saves the response variable.
This data set is then used by PROC ASSESS to compute the assessment statistics, which are saved in a data set by the LIFTOUT= option. The TARGET statement identifies the response variable. The EVENT= option specifies the value representing the event. The LEVEL=NOMINAL option indicates that the response is binary. The VAR statement identifies the variable containing the predicted event probabilities.
Finally, PROC SGRENDER applies the GainLiftNom template (below) to the LIFTOUT= data set to draw a panel of plots (not shown). Each plot includes a line representing the fitted model and a line representing best possible performance given the observed responses. You must have previously run the PROC TEMPLATE code defining the GainLiftNom template in the current or previous SAS session.
data sascas1.hmeq;
set sampsio.hmeq;
run;
proc logselect data=sascas1.hmeq association;
model bad(event='1') = loan value mortdue yoj derog delinq
clage ninq clno;
selection method=lasso details=all;
output out=sascas1.out predprobs copyvar=bad;
run;
proc assess data=sascas1.out method=exact liftout=sascas1.lift;
var _pred_1;
target bad / event="1" level=nominal;
run;
ods graphics on;
proc sgrender data=sascas1.lift template=GainLiftNom;
run;
PROC ASSESS does not include values of the statistics for a noninformative (base) model. Adding a line representing the base model to the plots provides a reference for the lowest possible performance just as the lines labeled "Best Possible" provide an upper reference. Use the GainLiftNomBase template (below) if the data contains the base statistics:
proc sql noprint;
select 100*sum(_nevents_), sum(_nobs_) into :totevnt, :totn
from sascas1.lift;
quit;
data lift; set sascas1.lift;
cumn+_nobs_;
_respbase_=100*_nobs_/&totn;
_cumrespbase_=100*cumn/&totn;
if _depth_>0 then do;
_pctrespbase_=&totevnt/&totn;
_cumpctrespbase_=&totevnt/&totn;
_liftbase_=1; _cumliftbase_=1; _gainbase_=0;
end;
run;
proc sgrender data=lift template=GainLiftNomBase;
run;
The panel of plots produced by SGRENDER using the GainLiftNomBase template is shown below. The panel of plots from the previous SGRENDER step using the GainLiftNom template (not shown) is the same except it omits the lines representing the base model labeled "Baseline."
In the plots, Depth indicates the bin number representing quantiles of the predicted event probabilities with lower-valued bins having higher probability. The Lift plots show the proportion of observations in the bin or up to that bin that are events divided by the overall proportion of events. These plots below show that bins with 20% highest predicted probabilities have two or more times the overall event probability. The best possible model would have almost five times the overall probability. The noninformative, base model would be expected to have the same proportion of events as overall, so baseline lift is 1. The %Captured plots show the percentage of total events captured in the bin or up to that bin. Note that many consider this to be the gain rather than the difference-based gain statistic discussed below. The cumulative plot shows that the top 20% from the model contain almost 60% of the events while the best possible model would contain almost all of the events. The first bin in the noncumulative plot with the 5% highest predicted probabilities contains over 20% of the events. The proportion of events expected by the base model would contain its proportion of the sample, that is 10% in each decile bin or 5% in each demi-decile bin. The Gain plot shows the percent difference between the overall proportion of events and the observed proportion of events up to that bin. This is effectively the cumulative lift plot normalized by subtracting the base-expected value of 1. As a result, the expected baseline gain is zero. The %Response plots show the event proportion in the bin or up to that bin. This is effectively lift rescaled by multiplying the lift by the overall event probability. The best possible and baseline values are similarly rescaled.
The following example uses the insurance claim loss data set, TOTLOSS, created as described in SAS KB0058455. The response variable, TOTLOSS, contains the total amount lost by the insurance company to each policyholder over one year. TOTLOSS ranges from zero to large positive values. PROC GENSELECT fits a Tweedie model to this response using several predictors. As for the binary example above, the OUTPUT statement saves the predicted and observed response values in a data set, which is then read by PROC ASSESS and the LIFTOUT= data set is created. Note that the target variable is specified as an interval level response.
data sascas1.totloss;
set totloss;
run;
proc genselect data=sascas1.totloss;
model totloss = age gender carType annualMiles education
carSafety income / dist=tweedie;
output out=sascas1.predloss pred=pred copyvar=totloss;
run;
proc assess data=sascas1.predloss method=exact
liftout=sascas1.modellift;
var pred;
target totloss / level=interval;
run;
As noted above, the statistics in the LIFTOUT= data set for an interval response do not include gain and lift. However, using sums and means of the target response within bins of the predicted response values, lift in each bin can be considered as the ratio of the target mean in the bin to the overall target mean. This is analogous to lift in the binary case where lift is the ratio of the event proportion in the bin to the overall event proportion. Note that both proportions are means when the binary response is coded 1 for the event and 0 for the nonevent. Cumulative lift is computed similarly as the cumulative target mean in bins up to the current bin divided by the overall mean. For a base, or noninformative model, both lift and cumulative lift equal 1. Gain is the cumulated sum of target values up to the current bin divided by the overall target sum. For a base model, gain is the proportion of the sample in each bin, which is a diagonal line from 0 to 1.
The following statements compute the lift and gain statistics:
proc sql noprint; select mean(totloss), sum(totloss) into :mean, :sum from sascas1.totloss; quit; data modellift; set sascas1.modellift; cumsum+_nobs_*_meant_; cumn+_nobs_; _lift_=_meant_/&mean; _liftbase_=1; if _depth_>0 then _cumlift_=(cumsum/cumn)/&mean; _cumliftbase_=1; _gain_=cumsum/∑ _gainbase_=_depth_/100; run;
The best possible model would have predicted response values that exactly replicate the observed responses. So, to obtain lift and gain values from the best possible model, use the observed responses rather than the predicted values from the fitted model in the assessment. Since the same variable cannot be used in both the TARGET and VAR statements in PROC ASSESS, create a copy of TOTLOSS for use in the VAR statement and then compute lift, cumulative lift, and gain as above. Add these variables representing the best possible model to the data set of statistics created above. Finally, use PROC SGRENDER with the GainLiftInt template (below) to produce the panel of plots for the Tweedie model on the continuous TOTLOSS variable:
data sascas1.predloss;
set sascas1.predloss;
copy=totloss;
run;
proc assess data=sascas1.predloss method=exact
liftout=sascas1.bestlift;
var copy;
target totloss / level=interval;
run;
data bestlift; set sascas1.bestlift;
cumsum+_nobs_*_meant_;
cumn+_nobs_;
_liftbest_=_meant_/&mean;
if _depth_>0 then
_cumliftbest_=(cumsum/cumn)/&mean;
_gainbest_=cumsum/∑
keep _depth_ _liftbest_ _cumliftbest_ _gainbest_;
run;
data gldata;
merge modellift bestlift;
by _depth_;
run;
ods graphics on;
proc sgrender data=gldata template=GainLiftInt;
run;
The plots show that the Tweedie model performs close to the best possible model. The noncumulative lift plot indicates that the top 20% of predicted values have response mean exceeding the overall response mean. This suggests that any action to reduce loss is best focused on the policyholders in the top 20% of predicted response. In terms of total loss, the gain plot suggests that the top 20% account for about 80% of the total loss:
Before calling any of these in PROC SGRENDER, run its PROC TEMPLATE code one time in a SAS session to store it in your SASUSER.TEMPLAT template store. Click the links to download the template code: