Skip to content
Last updated

Next Best Action

This notebook uses Q-learning to predict the next best action for each session in a particular state.

A Q-table (state → action) is trained and optimized on the train dataset and outputs predictions for Next Best Action for each user_id based on their latest state. This notebook takes an input table. An example input table is as follows:

user_idtstampstateactionreward (optional)
2a644f3f-ad33-48b3-b837-96c1e194dc172021-06-14 08:58:59/custom-demo/client_domain_organic_visit0.0
1740eb3c-03de-4856-891e-8f8bcffbfd6b2021-06-14 08:58:25/customers/lion/client_domain_organic_visit0.0
bd378622-0905-44d4-a950-53adcdfc26112021-06-14 08:25:57/learn/cdp-vs-dmp/client_domain_organic_visit0.0

And, the notebook results a next action for each user based on the last state. An example output table is as follows:

user_id...next_action
2a644f3f-ad33-48b3-b837-96c1e194dc17...cpc
1740eb3c-03de-4856-891e-8f8bcffbfd6b...social
bd378622-0905-44d4-a950-53adcdfc2611...display

Optionally, a holdout test is conducted for the test dataset and calculates Spend and Revenue on actual actions (randomly sampled) and recommended actions. By providing average Cost Per Action (CPA) and total budget, you can show CPA, Increase in Conversions, and Revenue/Return On Investment (ROI) gain.

Learn more about NBA through this TD Blog Post.

Workflow Example

Find a sample workflow here in Treasure Boxes.

+run_nba
  ipynb>:
    notebook: NBA
    train_table: ml_datasets.nba_train
    test_table: ml_datasets.nba_test
    budget: 10000
    value_per_cv: 100

Parameters

Parameter nameParameter on ConsoleDescriptionDefault Value
docker.task_memDocker Task MemTask memory size. Available values are 64g, 128g (default), 256g, 384g, or 512g depending on your contracted tiers128g
train_tableTrain Tablespecify a TD table used for trainingNone
test_tableTest Tablespecify a TD table used for testing and evaluationNone
user_columnUser Columnuser column nameuser_id
tstamp_columnTstamp Columntimestamp column nametstamp
state_columnState Columnstate column namestate
action_columnAction Columnaction column nameaction
reward_columnReward Columnreward column namereward
budgetBudgettotal budgetNone
value_per_cvValue Per Cvaverage value per conversionNone
neg_rewardNeg Rewardnegative reward-10.0
stepsStepstotal steps used in Q learning100000
gammaGammadiscount factor used in Q-learning0.6
lrLrlearning rate used in Q-learning0.05
ignore_actionsIgnore Actionsaction to ignoreNone
currencyCurrencycurrency symbol$
default_action_costDefault Action Costdefault action cost1.0
action_costAction Costuser-defined action costs{}
export_q_tableExport Q TableTD table name to export Q tableNone
export_state_actionExport State ActionTD table name to export recommended action for each stateNone
export_channel_ratioExport Channel RatioTD table name to export comparison results between actual and recommended actionsNone
export_predictionsExport PredictionsTD table name to export predicted results on the test datasetNone
export_model_performanceExport Model PerformanceTD table name to export model performanceNone
audience_nameAudience NameAudience parent (master) segment name to merge an attribute table

join_key| Join Key| join key column name in a master segment used for Audience integration. If not configured, user_column value is used.| None