VOOZH about

URL: https://www.analyticsvidhya.com/blog/2021/02/how-to-split-decision-tree-the-pursuit-to-achieve-purity/

โ‡ฑ Decision Tree Split | How to Split Decision Tree and Get Ideal Split


India's Most Futuristic AI Conference Is Back โ€“ Bigger, Sharper, Bolder

  • d
  • :
  • h
  • :
  • m
  • :
  • s

Reading list

How to Split a Decision Tree โ€“ The Pursuit to Achieve Pure Nodes

Himanshi Singh Last Updated : 01 Mar, 2021
6 min read

Introduction

Decision Trees are probably one of the common machine learning algorithms and this is something every Data Science beginner should know before deep-diving into the advanced machine learning algorithms. And one of the important things is to understand the working of Decision Trees.

In this article, youโ€™ll understand the basics of Decision Trees such as splitting, ideal split, and pure nodes.

Note: If you are more interested in learning concepts in an Audio-Visual format, We have this entire article explained in the video below. If not, you may continue reading.

So letโ€™s begin! Weโ€™ll start off by using a very simple example.

Letโ€™s say we have data of 20 students, out of which 10 play cricket whereas 10 do not.  So the red plus sign here represents the student who does play cricket and the green negative ones represent who does not play cricket.

๐Ÿ‘ Decision tree example

Now we have the following features of the students

  • Height- The height of the students
  • Performance- Their performance in the class tells us how the students have been performing in the tests that are conducted in the class
  • Class- Finally, we have their class which basically defines the current class of the student

Using these features we want to train a model and predict whether they will play cricket or not. Now if we look at this data that is available to us, we have a total of 20 students out of which 10 play cricket and hence the percentage of students who do play cricket is 50%.  And we have attributes of students like height, performance in the class and from which class they belong.

๐Ÿ‘ Split figures

Now the teacher wants to identify the sub-groups. These sub-groups are very similar with respect to playing cricket or not based on the given attributes.

Decision Tree Split โ€“ Height

For example, letโ€™s say we are dividing the population into subgroups based on their height. We can choose a height value, letโ€™s say 5.5 feet, and split the entire population such that students below 5.5 feet are part of one sub-group and those above 5.5 feet will be in another subgroup. After splitting letโ€™s say we got this distribution-

๐Ÿ‘ Image

As you can see, there are 8 students who are below 5.5 feet and out of those 8 students, only 2 are actually playing Cricket. Hence the percentage of students below 5.5 feet in height and play cricket is 25% percent. And we can say that 75% time people who are below 5.5 feet do not play cricket. Whereas there 12 students above 5.5 feet and out of those 12 students 8 are playing cricket. And the percentage of playing Cricket, in this case, is somewhere around 67%.

At a broad level, the teacher would be more confident while selecting students from these two groups, compared to our original population.

What do you think, out of the given three variables height is the right one, and why 5.5 feet? Could it be 6 feet or something else as well?

Decision Tree Split โ€“ Performance

Letโ€™s first try with another variable. Letโ€™s split the population-based on performance. Here the performance is defined as either Above average or Below average. We will again divide the population based on these categories and letโ€™s say we got a  distribution like this-

๐Ÿ‘ Decision Tree Split - Performance

Here, 14 students are above average, and out of these 14 students 8 play cricket and the percentage will be somewhere around 57%. In the below-average category, we have a total of 6 students, out of which 2 play cricket and the percentage will be, you guessed it, around 33%.

Decision Tree Split โ€“ Class

Finally, we have one more variable, Class and hence we can split the entire data on the class as well. Letโ€™s say the students in this data are either from class 9 or class 10 and hence we can use them as categories to split the data. After the split, we get this distribution-

๐Ÿ‘ Decision Tree Split - Class

A lot of students in class 9 play cricket whereas the number becomes quite less if you look at class 10. Perhaps students in class 10 are busy with their board exams or there could be a lot of reasons. Letโ€™s look at the numbers and percentages, in our data, there are 10 students from class 9 and 10 from class 10. In class 9, 8 out of 10 are playing cricket which is exactly 80% whereas in class 10 only 2 are playing cricket which comes out to be 20%.

This is how we can split the data based on the features available to us. If you would have noticed we have created three different decision trees till now.  Every time we split the entire data into two subsets based on certain conditions or decisions and thatโ€™s how we got a decision tree.

As you have seen we have three decision trees so far, which of these three decision trees do you think is better? or we can say which is giving more confidence to the teacher while predicting the behavior of students whether they play cricket or not. In decision trees, what we want is to have a decision that can separate the classes, which in our case is- whether the student plays or does not play cricket. So we want all the positives to be on one side or one node and all the negatives on the other node.

Which of these three scenarios do you think is the best split, just think about it for a second before we move on. Okay, if you look at the split on class in the third decision tree, it has segregated 80% of students who play cricket which is more than any of the other two splits. So we can say that the split on class is better in the other splits as it has produced almost pure nodes.

What is an Ideal Split in Decision Trees?

Can you guess what would have been an ideal split?

An ideal split would be the one that can segregate the positives in this case completely from the negatives and that would have produced the purest nodes.

Considered one more feature of the students which tells whether the student played cricket last year or not. Letโ€™s say we split the entire data based on this feature. There will be two categories Yes and No. Generally, students who played cricket last year have higher chances of playing cricket this year as well, and hence after the split, we get this distribution-

๐Ÿ‘ Ideal Split

You can see it has separated all the positives from all the negatives and when you look at the percentages, there are 10 students who did not play cricket last year and out of those 10 none played cricket this year as well and hence the percentage there is 0%. Similarly out of 10 students who played cricket last year, all of them played cricket this year as well and that is why this percentage is a full 100%.

A 100% pure node is a node that contains the data from a single class only.

Remember this is the ideal case, in practical real-world scenarios we have very less likely to have such features that can give you the completely pure nodes after the split. So if we look at the objective of decision trees, it is essential to have pure nodes.

We saw that the split on class produced the purest nodes out of all the other splits and thatโ€™s why we chose it as the first split. But the decision tree doesnโ€™t stop there, we can have more splits as well. For example, we can split the class 9 node even further letโ€™s say based on their heights or we can split the class 10 node based on the performance of students in that particular node.

The idea here is that we can have multiple splits and multiple decisions in a decision tree.

End Notes

We covered the basics of how to split Decision Trees so far. But the questions which you might be having right now is how we decide which split is better or what should be the first split or second split and so on. And how do you decide that what should be the sequence in which the split should be made? These are excellent questions and there are techniques to decide the purity of nodes based on which we can decide the best splitting point.

To understand decision trees in more depth, you can read the following article-

Donโ€™t get confused, weโ€™ll cover all these questions in our next article.

Iโ€™m a data lover who enjoys finding hidden patterns and turning them into useful insights. As the Manager - Content and Growth at Analytics Vidhya, I help data enthusiasts learn, share, and grow together. 

Thanks for stopping by my profile - hope you found something you liked :)

Login to continue reading and enjoy expert-curated content.

Free Courses

Generative AI - A Way of Life

Explore Generative AI for beginners: create text and images, use top AI tools, learn practical skills, and ethics.

Getting Started with Large Language Models

Master Large Language Models (LLMs) with this course, offering clear guidance in NLP and model training made simple.

Building LLM Applications using Prompt Engineering

This free course guides you on building LLM apps, mastering prompt engineering, and developing chatbots with enterprise data.

Improving Real World RAG Systems: Key Challenges & Practical Solutions

Explore practical solutions, advanced retrieval strategies, and agentic RAG systems to improve context, relevance, and accuracy in AI-driven applications.

Microsoft Excel: Formulas & Functions

Master MS Excel for data analysis with key formulas, functions, and LookUp tools in this comprehensive course.

Responses From Readers

Flagship Programs

GenAI Pinnacle Program| GenAI Pinnacle Plus Program| AI/ML BlackBelt Program| Agentic AI Pioneer Program

Free Courses

Generative AI| DeepSeek| OpenAI Agent SDK| LLM Applications using Prompt Engineering| DeepSeek from Scratch| Stability.AI| SSM & MAMBA| RAG Systems using LlamaIndex| Building LLMs for Code| Python| Microsoft Excel| Machine Learning| Deep Learning| Mastering Multimodal RAG| Introduction to Transformer Model| Bagging & Boosting| Loan Prediction| Time Series Forecasting| Tableau| Business Analytics| Vibe Coding in Windsurf| Model Deployment using FastAPI| Building Data Analyst AI Agent| Getting started with OpenAI o3-mini| Introduction to Transformers and Attention Mechanisms

Popular Categories

AI Agents| Generative AI| Prompt Engineering| Generative AI Application| News| Technical Guides| AI Tools| Interview Preparation| Research Papers| Success Stories| Quiz| Use Cases| Listicles

Generative AI Tools and Techniques

GANs| VAEs| Transformers| StyleGAN| Pix2Pix| Autoencoders| GPT| BERT| Word2Vec| LSTM| Attention Mechanisms| Diffusion Models| LLMs| SLMs| Encoder Decoder Models| Prompt Engineering| LangChain| LlamaIndex| RAG| Fine-tuning| LangChain AI Agent| Multimodal Models| RNNs| DCGAN| ProGAN| Text-to-Image Models| DDPM| Document Question Answering| Imagen| T5 (Text-to-Text Transfer Transformer)| Seq2seq Models| WaveNet| Attention Is All You Need (Transformer Architecture) | WindSurf| Cursor

Popular GenAI Models

Llama 4| Llama 3.1| GPT 4.5| GPT 4.1| GPT 4o| o3-mini| Sora| DeepSeek R1| DeepSeek V3| Janus Pro| Veo 2| Gemini 2.5 Pro| Gemini 2.0| Gemma 3| Claude Sonnet 3.7| Claude 3.5 Sonnet| Phi 4| Phi 3.5| Mistral Small 3.1| Mistral NeMo| Mistral-7b| Bedrock| Vertex AI| Qwen QwQ 32B| Qwen 2| Qwen 2.5 VL| Qwen Chat| Grok 3

AI Development Frameworks

n8n| LangChain| Agent SDK| A2A by Google| SmolAgents| LangGraph| CrewAI| Agno| LangFlow| AutoGen| LlamaIndex| Swarm| AutoGPT

Data Science Tools and Techniques

Python| R| SQL| Jupyter Notebooks| TensorFlow| Scikit-learn| PyTorch| Tableau| Apache Spark| Matplotlib| Seaborn| Pandas| Hadoop| Docker| Git| Keras| Apache Kafka| AWS| NLP| Random Forest| Computer Vision| Data Visualization| Data Exploration| Big Data| Common Machine Learning Algorithms| Machine Learning| Google Data Science Agent
๐Ÿ‘ Av Logo White

Continue your learning for FREE

Forgot your password?
๐Ÿ‘ Av Logo White

Enter OTP sent to

Edit

Wrong OTP.

Enter the OTP

Resend OTP

Resend OTP in 45s

๐Ÿ‘ Popup Banner
๐Ÿ‘ AI Popup Banner