Data Algorithms and Models

Learning Objective 3 Explain the elements of a decision tree model

In the last several years, data scientists have developed myriad models to analyze vast quantities of data. These range from simple regression techniques to sophisticated neural networks. The hallmark of most of these models is that they are extremely flexible in fitting to the data and rely heavily on computational power. This flexibility, however, comes with its own problems that the management accountant’s skills can help address. In this section, we examine functional versus flexible relationships and introduce a specific model: the decision tree.

Step 4: Build a Model

In this step, the management accountant works with the data scientists to build models. They must decide what kinds of models to build and how to validate them.

Functional Relationship Model

Paige and the data science team recognize that the target (dependent variable) is binary: 1 if the loan defaults and 0 if the loan repays. As we saw in Chapter 10, the team could use logistic regression to estimate the relationship between independent feature variables (such as [annual] income, credit score, and amount of the loan) and the target variable. This approach assumes a particular functional form of the relationship between feature variables and the target variable to fit the curve shown in Exhibit 10-10. The data scientists on the team suggest that they could get better predictions of default if they fit more flexible models that do not assume a particular functional relationship between feature variables and the target variable. They propose to use a very popular data science technique called decision trees.

THE DECISION TREE: A PREDICTIVE MODELING TECHNIQUE The decision tree is a technique for segmenting the target variable into different regions based on a set of rules. These rules make the model easier to interpret than some other models. Industry analyst Dean Abbot writes, “All trees can be read as a series of ‘if-then-else’ rules that ultimately generate a predicted value . . . [They are] much more accessible to decision makers than mathematical formulas.” They are also easy to build and perform better with more data.

Paige is eager to learn why more flexible models yield better default predictions. She is also keen to understand the problems and challenges of the decision tree technique. This seems very difficult to do in the context of thousands of variables and hundreds of features. She asks the data science team whether it is possible to describe the approach in a simple visual way. She would then be able to use the output of the model to guide managers in their decision making.

To explain the technique, the team starts with a simple example that links directly to Sierra Investments’ objective. They select a dataset of 24 loans containing 12 default loans (labeled as 1) and 12 repay loans (labeled as 0). Two features, income and credit score, describe each data point. Exhibit 11-4 presents the default loans in columns 1 through 3 and the repay loans in columns 4 through 6.

EXHIBIT 11-4

Default and Repay Loan Data for 24 Loans

<p>A table shows default and repay loan data for 24 loans</p>

The table depicts income, credit score, and loan status for 24 loans. The details of the table are as follows:

  1. Loan status: Default

    • Income 50,000 dollars and credit score 530
    • Income 62,000 dollars and credit score 552
    • Income 57,000 dollars and credit score 594
    • Income 45,000 dollars and credit score 604
    • Income 64,000 dollars and credit score 627
    • Income 84,000 dollars and credit score 637
    • Income 49,000 dollars and credit score 638
    • Income 66,000 dollars and credit score 667
    • Income 33,000 dollars and credit score 674
    • Income 75,000 dollars and credit score 708
    • Income 43,000 dollars and credit score 730
    • Income 53,000 dollars and credit score 748
  2. Loan Status: Repay

    • Income 86,000 dollars and credit score 620
    • Income 108,000 dollars and credit score 648
    • Income 59,000 dollars and credit score 676
    • Income 110,000 dollars and credit score 701
    • Income 69,000 dollars and credit score 731
    • Income 81,000 dollars and credit score 716
    • Income 95,000 dollars and credit score 747
    • Income 61,000 dollars and credit score 752
    • Income 65,000 dollars and credit score 767
    • Income 52,000 dollars and credit score 788
    • Income 82,000 dollars and credit score 802
    • Income 87,000 dollars and credit score 840

Exhibit 11-5 plots the data in Exhibit 11-4. The x-axis represents the income level. The y-axis represents credit score. Each default loan from Exhibit 11-4, column 3 is represented as a red dot. Each repay loan from Exhibit 11-4, column 6 is represented as a blue dot. For example, the red dot at an income level of $50,000 and credit score of 530 represents the first default loan (from columns 1, 2, and 3 in Exhibit 11-4). In this initial plot the 12 repay loans and 12 default loans sit within one rectangle. If Paige selects one dot at random from this pool, it is equally likely to be a blue dot as a red dot.

Exhibit 11-5

Loan Data: 12 Default Loans and 12 Repay Loans

A scatter plot shows the decision tree algorithm of loan data.
The x-axis shows x subscript income (dollar 000s) from 30 to 110 in increments of 10. The y-axis shows x subscript 2 credit score from 500 to 850 in increments of 50. A series of 24 dots comprising of 12 each of red and blue color represents default and y: repay respectively are scattered across the grid. The repay dots are scattered on the top part of the grid, while the default dots are scattered on the bottom part of the grid.

THE DECISION TREE ALGORITHM An algorithm is a set of instructions. The decision tree emerges from an algorithmic process of subdividing the data along the two possible features, income or credit score. The decision tree algorithm instructs Paige to divide the data with a cut or line parallel to the x-axis (income) or y-axis (credit score) such that each of the two smaller rectangles contains a mix of dots that are purer than the original rectangle; that is, one rectangle contains more repay loans than default loans and the other rectangle contains more default loans than repay loans. For example, in the scatter plot on the left side of Exhibit 11-6, Paige places a cut at credit score of 675 (a horizontal line parallel to the x-axis).* This creates rectangle R1 above the line and rectangle R2 below the line. All borrowers in R1 have a credit score greater than 675 and there are more repay loans (10 blue dots) than default loans (3 red dots). All borrowers in R2 have credit scores less than 675 and there are fewer repay loans (2 blue dots) than default loans (9 red dots). Therefore, the mix of dots in rectangles R1 and R2 are each purer than the mix in the original rectangle, which had an equal number of red and blue dots. However, the mix in each is still impure: Rectangle R1 contains mostly repay loans, but also a few default loans, and rectangle R2 contains mostly default loans, but also a few repay loans. The table in Exhibit 11-6 shows the tally of default and repay loans across each of the two new rectangles.

Exhibit 11-6

First Cut of Decision Tree (with income shown in $000s)

A scatter plot shows the first cut decision tree with income shown in 000s dollar.
NOTE: 1. DECISION NODES: These are indicated by circles. The label beneath is the feature on which the split was made. The number inside the circle indicates the value at which the rectangle was split. 2. CONNECTING LINES: These lines connect nodes at various levels of the tree. The path to the right of the node represents observations greater than the cut-off value and the path to the left of the node represents observations less than the cut-off value. The number below indicates the number of observations that were directed down that path. 3. TERMINAL NODES: These are indicated by rectangles and they are groupings that are pure (no further classification can be done). They have no successors, hence the name “terminal.” Because R1 and R2 are impure (they each contain repayers and defaulters), they end in decision nodes (circles) rather than terminal nodes.

The x-axis shows x subscript income (dollar 000s) from 30 to 110 in increments of 10. The y-axis shows x subscript 2 credit score from 500 to 850 in increments of 50. A series of 24 dots comprising of 12 each of red and blue color represents default and y: repay respectively are scattered across the grid. The repay dots are scattered on the top part of the grid, while the default dots are scattered on the bottom part of the grid. A horizontal line is marked from 675 of credit score cutting the grid into two rectangular segments. The rectangle above the line is labeled as R1 and the rectangle below the line is labeled as R2.

A table below the plot shows the tally of default and repay loans across each of the two rectangles. The details of loan status, R1, R2, and total respectively are as follows: Repay (blue): 10, 2, 12; Default (red): 3, 9, 12; Total: 13, 11, 24.

A visualization of the decision tree is shown on the right side of the plot. The credit score with a value of 675 is at the first decision node. The 13 dots with credit scores higher than 675 are on the right, to R1, while the 11 dots with credit scores less than 675 are on the left, to R2.

At the top right of Exhibit 11-6 is a visualization of a decision tree as a series of decision nodes and connecting lines. In this example, the feature credit score with a value of 675 is the first decision node. The 13 borrowers with credit scores higher than 675 go to the right, to R1, while the 11 borrowers with credit scores less than 675 go to the left, to R2.

The process of subdividing the data into smaller subsets that get purer with each subdivision is the essence of the decision tree. The algorithm uses a measure of impurity, the focus of the following section, to calculate precisely how pure the resulting subsets will be at any specific cut.

MEASURING IMPURITY Gini impurity is a way to measure the purity of a collection of observations in a rectangle (set). If a rectangle is very mixed it is “impure” and the Gini impurity is high. As a rectangle becomes more pure, that is, it contains more members of one class than another, the Gini impurity decreases. Gini impurity can be calculated for any number of classes; in the Sierra Investments example, there are two classes: repay and default. The reduction in the Gini impurity from the level in the original rectangle to the levels in the new rectangles created by the cut (in our example R1 and R2) is called information gain. Information gain and Gini impurity are inversely related.

To place the first cut, as it did at credit score 675, the algorithm tests all possible values for vertical and horizontal cuts. It calculates the Gini impurity measure for each pair of rectangles that result from that cut and then compares the Gini impurity of the rectangles after the cut is made to the impurity of the rectangle(s) before the cut is made. The algorithm selects the value that reduces Gini impurity the most.

The equation for calculating Gini impurity for any point on the credit score or income axis is

probability of picking a repayer (blue)×(1−probability of picking a repayer)                                                                      + probability of picking a defaulter (red)×(1−probability of picking a defaulter)

The process for calculating Gini impurity is shown below:

  1. ESTABLISH THE BASELINE GINI IMPURITY. This calculation is based on the number of classes in the population. In this example there are two classes comprising 12 repay loans and 12 default loans. The initial calculation of the Gini impurity for the original rectangle is

probability of picking a repay loan [blue]×(1−probability of picking a repay loan)       + probability of picking a default loan (red)×(1−probability of picking a default loan)=1224×(1−1224)+1224×(1−1224)=(12×12)+(12×12)=14+14=12

The Gini impurity is 12, which in fact is the maximum value for the measure, given two classes.*

  1. COMPARE NEW GINI IMPURITIES FOR ANY POSSIBLE CUT. With the baseline established, a software program then (a) tests each possible placement of a cut (at every value on either the credit score or income axis), (b) calculates the new Gini impurity values for each possible partition, R1 and R2, (c) calculates the difference between baseline and new values, and then (d) places the cut to maximize reduction in the Gini impurity. Note the very large number of calculations that need to be done to determine the optimal way to partition the data compared to the formulae used when doing multiple regressions in Chapter 10. These calculations would not be possible without access to cheap computing power. Note also the extreme flexibility of the techniques to separate default loans from repay loans. The partitions are based on the actual sample data without assuming any functional form (such as the linear relationship assumed in Chapter 10).

Exhibit 11-7 shows the distribution of classes (repay and default loans) in the original scatter plot and in the rectangles R1 and R2 that the first cut creates.

Exhibit 11-7

Distribution of Repay Loans and Default Loans Before and After Cut of 675

<p>A table shows distribution of repay loans and default loans before and after cut of 675.</p>

The table depicts the original rectangle and the rectangles after first cut R1, R2, and total for repay and default loans, as well as totals. The details of the table are as follows:

  1. Repay loan status
    • Original rectangle: 12
    • Rectangle after first cut, R1: 10
    • Rectangle after first cut, R2: 2
  2. Default loan status
    • Original rectangle: 12
    • Rectangle after first cut, R1: 3
    • Rectangle after first cut, R2: 9
    • Rectangle after first cut, total: 12
  3. Total
    • Original rectangle: 24
    • Rectangle after first cut, R1: 13
    • Rectangle after first cut, R2: 11
    • Rectangle after first cut, total: 24

For this cut at a credit score equal to 675, the Gini impurity calculations for R1 and R2 are as follows:

R1: 1013×(1−1013)+313×(1−313)=1013×313+313×1013=60169=0.355R2: 211×(1−211)+911×(1−911)=211×911+911×211=36121=0.298  

Weighted average Gini impurity for R1 and R2 =

proportion of observations in R1×Gini impurity for R1                             + proportion of observations in R2×Gini impurity for R2=1324×0.355+1124×0.298=0.329

By placing the first cut at credit score 675, the decision tree algorithm reduces the Gini impurity from 0.500 to 0.329.

Why did the algorithm choose to make the first cut at a credit score of 675? Return to Exhibit 11-6 and lay a ruler along this line, then pull it down so that it sits at a credit score of 600. Count and record the number of red and blue dots in the new R1 and the new R2. We can use these counts to calculate the reduction in Gini impurity if the algorithm had made the first cut at 600.

At credit score equals 600, the Gini impurity calculations for R1 and R2 are

R1: 1221×(1−1221)+921×(1−921)=1221×921+921×1221=0.490R2: 03×(1−03)+33×(1−33)=03×33+33×03=0  

Weighted average Gini impurity for R1 and R2 =

proportion of observations in R1×Gini impurity for R1+ proportion of observations in R2×Gini impurity for R2     2124×0.490+03×0=0.429  

By placing the first cut at credit score 600, the decision tree algorithm reduces the Gini impurity from 0.500 to 0.429. Exhibit 11-8 shows the counts and the Gini impurity values if the first cut had been made at several different values of credit score. It also shows counts and the Gini impurity values if the first cut had been made at several different values of income. A first cut at credit score 675 reduces the Gini impurity the most.

Exhibit 11-8

Gini Impurity for Different Cuts Based on Credit Score and Income

<p>A table shows Gini impurity for different cuts based on credit score and income</p>

The table depicts the original rectangle and the rectangles after first cut R1, R2, and total for repay and default loans, as well as totals. The details of the table are as follows:

1. R1 repay

2. R1 default

3. R1 total

4. R2 repay

5. R2 default

6. R2 total

7. Gini impurity