Scénario de test & Cas d'usage
Creates a customer dataset with demographic info, campaign exposure, and a purchase flag. Then, trains a BART model on this data to predict the purchase outcome.
| 1 | DATA mycas.customer_campaign; |
| 2 | call streaminit(456); |
| 3 | DO i = 1 to 5000; |
| 4 | age = 20 + floor(rand('UNIFORM') * 45); |
| 5 | income = 40000 + floor(rand('UNIFORM') * 80000); |
| 6 | IF rand('UNIFORM') < 0.5 THEN channel = 'Email'; ELSE channel = 'SMS'; |
| 7 | IF rand('UNIFORM') < 0.4 THEN discount_offered = 1; ELSE discount_offered = 0; |
| 8 | /* Interaction effect */ |
| 9 | p = 1 / (1 + exp(-( -2 + 0.01*age + 0.00001*income + 1.5*discount_offered + (ifc(channel='SMS', 0.5, 0))) )); |
| 10 | purchased = rand('BERNOULLI', p); |
| 11 | OUTPUT; |
| 12 | END; |
| 13 | RUN; |
| 14 | |
| 15 | PROC CAS; |
| 16 | bart.bartProbit TABLE={name='customer_campaign'}, |
| 17 | model={depVars={{name='purchased', levelType='BINARY'}}, |
| 18 | effects={{vars={'age', 'income', 'channel', 'discount_offered'}}}}, |
| 19 | store={name='campaign_model', replace=true}; |
| 20 | QUIT; |
| 1 | PROC CAS; |
| 2 | bart.bartScoreMargin |
| 3 | TABLE='customer_campaign', |
| 4 | model='campaign_model', |
| 5 | seed=123, |
| 6 | margins={{ |
| 7 | name='margin_discount_15pct', |
| 8 | label='Margin with 15% Discount', |
| 9 | at={{var='discount_offered', value=1}} |
| 10 | }, |
| 11 | { |
| 12 | name='margin_no_discount', |
| 13 | label='Margin with No Discount', |
| 14 | at={{var='discount_offered', value=0}} |
| 15 | }}; |
| 16 | QUIT; |
| 1 | PROC CAS; |
| 2 | bart.bartScoreMargin |
| 3 | TABLE='customer_campaign', |
| 4 | model='campaign_model', |
| 5 | seed=456, |
| 6 | margins={{ |
| 7 | name='margin_discount_15pct', |
| 8 | at={{var='discount_offered', value=1}} |
| 9 | }, |
| 10 | { |
| 11 | name='margin_no_discount', |
| 12 | at={{var='discount_offered', value=0}} |
| 13 | }}, |
| 14 | differences={{ |
| 15 | name='diff_discount_effect', |
| 16 | label='Effect of 15% Discount', |
| 17 | refMargin='margin_no_discount', |
| 18 | evtMargin='margin_discount_15pct' |
| 19 | }}, |
| 20 | marginInfo=true, |
| 21 | casOut={name='campaign_margin_results', replace=true}; |
| 22 | QUIT; |
The action should produce 'Margins' and 'MarginDifferences' tables. The business analyst can use the 'diff_discount_effect' result to state, with a credible interval, the average increase in purchase probability directly attributable to the discount offer, across the entire customer base.