Skip to content

Instantly share code, notes, and snippets.

@danielezonca
Last active October 26, 2020 19:43
Show Gist options
  • Save danielezonca/981f49c0c7663db7a24371c96cc83cbe to your computer and use it in GitHub Desktop.
Save danielezonca/981f49c0c7663db7a24371c96cc83cbe to your computer and use it in GitHub Desktop.

Use case: Card transaction dispute

End user can dispute a card transaction and the system has to decide if the dispute can be automatically processed (aka accept the dispute and refund the user) or if it requires to have manual verification

Prerequisitive:

NOTE: be sure PMML file is a valid XML

Steps:

  • Create project "Card Dispute"
  • Import Asset "dtree_risk_predictor.pmml" in package "com"
  • Create DMN Model "Dispute Transaction Check" in package "com"
  • Create "tTransaction" Data Type with transaction_amount (number) and cardholder_identifier (number) fields
  • Import Models, select PMML model and name it "Risk Predictor"
  • Create Node BKM with name "Risk Predictor" of type P (PMML), select "Risk Predictor" file and "DecisionTreeClassifier" as model
  • Create Input node with name "Transaction" and type "tTransaction"
  • Create Decision node "Transaction Dispute Risk" with "Transaction" node as input and "Risk Predictor" as function
  • Type of the decision "Invocation", specify as function name "Risk Predictor", "amount" parameter with Literal expression "Transaction.transaction_amount" and "holder_index" parameter with Literal expression "Transaction.cardholder_identifier"
  • Create Input node with name "Risk threshold" and type "number"
  • Create Decision node "Can be automatically processed?" that takes as inputs "Transaction Dispute Risk" and "Risk threshold"
  • Select Literal expression and use "Transaction Dispute Risk.predicted_dispute_risk < Risk threshold"
  • Save

NOTE: predicted_dispute_risk is the name of the target field specified in the PMML file

Test the model:

  • Create Test Scenario asset in package "com"
  • Provide name "Test Dispute Transaction Check"
  • Select DMN and "Dispute Transaction Check"
  • Remove column "Transaction Dispute Risk"
  • Specify values
Description Risk Threshold cardholder_identifier transaction_amount Can be automatically processed?
Risk threshold 5, automatically processed 5 1234 1000 true
Risk threshold 4, amount = 1000, not processed 4 1234 1000 false
Risk threshold 4, amount = 180, automatically processed 4 1234 180 true
Risk threshold 1, amount = 1, not processed 1 1234 1 false
  • Execute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment