Hello Devz,

Sometimes it is hard to take a decision. And to represent the possibilities of complex decisions, it is usefull to use a Decision Tree. Instead of having all the parameters at once, you can simply take small decision at a time and then go further. In this simple tutorial we will show an example of a decision tree that will check if a client can receive a loan from a bank.

Let’s first have a look at our client to evaluate:

Based on our Client model:

Now, the goal is to take a decision. So let’s create some Decision classes:

Our Decision class will have to evaluate a Client. This evaluation will be based on a DecisionQuery (the question) and a DecisionResult (the response).

The Test Func will simply verify if the condition is met (for example: is our client earning enough money to be able to refund his loan). Depending on the result of this Test, we will take an orientation: Positive or Negative. Both of them are Decisions as well.

Here is the DecisionResult class, which will contain the final result of our decision tree:

Now, let’s create our tree! We will start with one simple question… Does our client need a loan? If yes, then check if our client have a criminal record. If no, then check how much money he earns. If he earns enough money to refund the loan, then check if he have enough exeprience in his job (not a newbie that will maybe lose his job tomorrow). If yes, then check if he uses his creditcard (why not…).

By this unreadable text, you will understand the real value of a decision tree.

Last but not least, our Main method. It will receive the decision tree built just above, create our client, and then evaluate it.

And here is the final result:

C# - decision tree - simple example

C# – decision tree – simple example

Our dear mister John Doe will receive his loan.

Happy decisions!  😉