# Interpretation

[Code Implementation here](https://drive.google.com/file/d/1EgUVNDVlV0Htcjyd9j201S0sa600V_7h/view?usp=sharing)

<div align="center"><img src="https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MDrEt2n061xV1B0tS5Z%2F-MDrHSnFKO5goILIWquT%2Fimage.png?alt=media&#x26;token=619cf0a6-ce4d-43f9-b5b0-36b7e45f298a" alt="Decision Tree Visualization"></div>

Above is the Decision Tree classifier we have made for predicting churn. Can you interpret the tree from the first look?

Although Decision Trees look easy to interpret, being able to understand the interpretations fully, is a tough task. In the above picture, we have a tree with three levels. Every level consists of a feature with a threshold value, entropy value for that node, count of samples included under that node, and the predicted values.&#x20;

To be able to explain the tree visualizations, we will only explain the leftmost nodes on every level.&#x20;

At the top of the tree, as a root node, we have "Contract <= 0.5". This means that Contract is the most important feature of our model. Note that all categorical columns have been coded to numeric values using Label Encoding. So a "0" in Contract means Month-to-month, a "1" means One-year, and a "2" means Two-year.&#x20;

![](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MEkKwDL1FRReXo9iCJq%2F-MEkNHXJ3GyDNLPTQAfX%2Fimage.png?alt=media\&token=b7f72c12-acd6-49ae-b40a-f4a607c7a0af)

Since Contract is a categorical column, it can only be "0" or "1", and not any value in between. From the root node, we can see that there are 5247 samples in our training set. The "class" and "value" in the root node are related wherein the former refers to the prediction and the latter shows the distribution of samples that in turn impact the prediction.&#x20;

The first element in "value" represents churn class "Yes" and the second element represents class "No". Whichever class has a higher number of samples in the value, is the predicted class for that node.&#x20;

![Root Node](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MDvQ_xldFeXIg-sJhEl%2F-MDvQp-g3Ccxz1ZwuGY-%2Fimage.png?alt=media\&token=8a8c89ac-0b6d-4c23-835f-d7e510678bac)

So in the root node, we have 3869 samples for churn class "Yes" and 1378 for churn class "No". Hence, the prediction class of this node is "Yes".  The entropy value is 0.831 which means it is not a pure node and has mixed samples.&#x20;

In the next level, we have two decision nodes based on whether Contract <=0.5.

![Root Node and Level 1 of Decision Tree](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MDv2SpFwJyxnvs7CJci%2F-MDvJyz_FYZ1bIrvq9ey%2Fimage.png?alt=media\&token=8162ed5e-5360-4a1e-9243-37681a26d33d)

We can see that of the 5247 samples in the root node, 2862 have Contract = 0 (Month-to-Month) and 2385 have Contract = 1 & 2(One-year & Two-year). In the first level after the root node, we have two decision nodes that show that "Monthly Charges" is the most important feature for that level. On the left, the decision threshold is "Monthly Charges <= 68.975" and on the right, the decision threshold is "Monthly Charges <=93.675". Remember that the primary separator of data before this node was Contract.&#x20;

In the left decision node, with 2862 samples, we have an entropy value of 0.985. Again, we can interpret that we have an impure node with mixed samples. Of the 2862 samples, 1637 have a prediction value of churn to be "Yes" and 1225 have a prediction value of churn to be "No". Since the majority are "Yes", the class associated with this node is Yes.&#x20;

In the right decision node, with 2385 samples, we have an entropy value of 0.344. This is very low compared to the previous entropy values. We can interpret that this is a more pure set than the ones before since the entropy value is close to 0. In support of this theory, we can see that 2232 points have churn "Yes" and only 153 have churn "No". Given the majority, the class associated with this node is "Yes" and the imbalance in values justifies the low entropy value.

A similar interpretation can be done for every level and overall we can obtain an explanation with the decisions our model makes to generate a prediction.&#x20;

Note here that our tree has only 3 levels. This was because it had the best accuracy on the test set from all the other hyperparameter values. In essence, a tree with low levels will do well on the test set but a tree with a high number of levels tends to overfit the training set and perform badly on the test.
