{"id":81856,"date":"2025-07-19T17:48:27","date_gmt":"2025-07-19T12:18:27","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=81856"},"modified":"2026-10-01T10:19:33","modified_gmt":"2026-10-01T04:49:33","slug":"tutorial-on-decision-tree-in-data-science","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/tutorial-on-decision-tree-in-data-science\/","title":{"rendered":"Decision Tree in Data Science: Working, Algorithms, Python, and Applications"},"content":{"rendered":"\n<p>Decision Trees are among the most interpretable supervised machine learning algorithms used in Data Science. They convert a prediction problem into a sequence of feature-based rules, making it possible to trace exactly how the model reaches a classification or regression output.<\/p>\n\n\n\n<p>A Decision Tree repeatedly splits a dataset into smaller subsets using conditions such as Age &lt;= 30 or Income &gt; 50000. The algorithm selects each split by measuring how effectively it separates the target variable.<\/p>\n\n\n\n<p>Decision Trees are useful not only as standalone models but also as the foundation of powerful ensemble algorithms such as Random Forest and Gradient Boosting.<\/p>\n\n\n\n<p>This guide explains how Decision Trees work in Data Science, how split criteria such as Gini Impurity and Entropy are calculated, how pruning controls overfitting, how important hyperparameters affect model behaviour, and how to build and evaluate a Decision Tree using Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Quick Answer<\/strong><\/h2>\n\n\n\n<p>A <strong>Decision Tree in Data Science<\/strong> is a supervised machine learning algorithm that recursively divides data using feature-based conditions until it reaches a prediction at a leaf node.<\/p>\n\n\n\n<ul>\n<li><strong>Classification:<\/strong> Predicts categories such as fraud vs legitimate or churn vs retained.<\/li>\n\n\n\n<li><strong>Regression:<\/strong> Predicts continuous values such as sales, demand, or house prices.<\/li>\n\n\n\n<li><strong>Split Criteria:<\/strong> Classification commonly uses Gini Impurity or Entropy, while regression can use squared error.<\/li>\n\n\n\n<li><strong>Main Strength:<\/strong> Produces human-readable decision rules without requiring feature scaling.<\/li>\n\n\n\n<li><strong>Main Limitation:<\/strong> Deep trees can overfit training data and become unstable.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What Is a Decision Tree in Data Science?<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-38-1200x630.png\" alt=\"\" class=\"wp-image-141759\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-38-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-38-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-38-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-38-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-38-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-38-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>A Decision Tree is a <a href=\"https:\/\/www.guvi.in\/blog\/supervised-and-unsupervised-learning\/\">supervised learning<\/a> model that maps input features to an output through a hierarchy of conditional decisions. Its structure resembles a flowchart. A typical tree contains:<\/p>\n\n\n\n<ul>\n<li><strong>Root Node:<\/strong> Contains the complete training dataset before any split occurs.<\/li>\n\n\n\n<li><strong>Internal Nodes:<\/strong> Represent conditions applied to individual features.<\/li>\n\n\n\n<li><strong>Branches:<\/strong> Represent the possible outcomes of those conditions.<\/li>\n\n\n\n<li><strong>Leaf Nodes:<\/strong> Contain the final class prediction or regression value.<\/li>\n<\/ul>\n\n\n\n<p>Consider a simple credit-risk model.<\/p>\n\n\n\n<p>The first split might be:<\/p>\n\n\n\n<p><strong>Credit Score &lt;= 650?<\/strong><\/p>\n\n\n\n<p>If yes, the model may next evaluate income.<\/p>\n\n\n\n<p>If no, it may evaluate debt-to-income ratio.<\/p>\n\n\n\n<p>Each observation follows one path from the root to a leaf.<\/p>\n\n\n\n<p>The final leaf determines the model prediction.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Decision Tree Classification vs Regression<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-37-1200x630.png\" alt=\"\" class=\"wp-image-141758\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-37-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-37-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-37-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-37-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-37-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-37-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Decision Trees can solve both classification and regression problems, but the target and splitting objective differ.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Aspect<\/strong><\/td><td><strong>Classification Tree<\/strong><\/td><td><strong>Regression Tree<\/strong><\/td><\/tr><tr><td>Target<\/td><td>Categorical<\/td><td>Continuous<\/td><\/tr><tr><td>Example<\/td><td>Fraud \/ Legitimate<\/td><td>House Price<\/td><\/tr><tr><td>Output<\/td><td>Class label or probability<\/td><td>Numerical value<\/td><\/tr><tr><td>Common Split Criteria<\/td><td>Gini, Entropy, Log Loss<\/td><td>Squared Error, Absolute Error, Poisson Deviance<\/td><\/tr><tr><td>Leaf Prediction<\/td><td>Majority class \/ class probabilities<\/td><td>Mean or median depending on criterion<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Scikit-learn currently supports gini, entropy, and log_loss for DecisionTreeClassifier. DecisionTreeRegressor supports criteria including squared_error, absolute_error, and poisson.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Key Features of Decision Trees in Data Science<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-36-1200x630.png\" alt=\"\" class=\"wp-image-141757\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-36-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-36-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-36-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-36-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-36-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/image-36-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<ul>\n<li><strong>Hierarchical Rule-Based Structure:<\/strong> A Decision Tree represents predictions as a sequence of conditional rules. The <strong>root node<\/strong> contains the complete dataset, <strong>internal nodes<\/strong> evaluate feature-based conditions, <strong>branches<\/strong> represent the outcome of each condition, and <strong>leaf nodes<\/strong> return the final class label or numerical prediction.<\/li>\n\n\n\n<li><strong>Supports Classification and Regression:<\/strong> Decision Trees can solve both major supervised learning tasks. A <code>DecisionTreeClassifier<\/code> predicts discrete classes, while a <code>DecisionTreeRegressor<\/code> predicts continuous values. Classification trees typically optimise impurity measures, while regression trees minimise prediction error within child nodes.<\/li>\n\n\n\n<li><strong>Recursive Feature Splitting:<\/strong> The algorithm repeatedly searches for a feature and threshold that produce the strongest separation of training samples. A numerical feature may create a rule such as <code>Income &lt;= 50,000<\/code>, dividing the parent node into child nodes. This recursive partitioning continues until a stopping condition is reached.<\/li>\n\n\n\n<li><strong>Multiple Split Criteria:<\/strong> Classification trees can evaluate candidate splits using measures such as <strong>Gini Impurity, Entropy, and Log Loss<\/strong>. Regression trees can use criteria such as <strong>squared error, absolute error, Friedman MSE, or Poisson deviance<\/strong>, depending on the implementation. The selected split aims to create child nodes that are more homogeneous than the parent node.<\/li>\n\n\n\n<li><strong>Captures Nonlinear Relationships and Feature Interactions:<\/strong> Decision Trees do not assume a linear relationship between input variables and the target. Successive splits can model thresholds and interactions automatically. For example, credit risk may depend on income only when debt exceeds a particular threshold.<\/li>\n\n\n\n<li><strong>Does Not Require Feature Scaling:<\/strong> Tree-based models compare feature values against thresholds rather than calculating distance between observations. Standardisation or normalization is therefore generally unnecessary, unlike algorithms such as <a href=\"https:\/\/www.guvi.in\/blog\/knn-algorithm-in-machine-learning\/\">KNN<\/a>, K-Means, or many SVM configurations.<\/li>\n\n\n\n<li><strong>Provides Interpretable Decision Paths:<\/strong> Every prediction can be traced from the root node to a leaf. This allows developers to inspect which conditions influenced an individual prediction and makes Decision Trees useful when model behaviour needs to be explained.<\/li>\n\n\n\n<li><strong>Built-In Feature Importance Estimation:<\/strong> Decision Tree implementations can estimate how much each feature contributes to reducing impurity across the tree. In Scikit-learn, this information is available through <code>feature_importances_<\/code>. However, impurity-based importance should not be interpreted as causal importance and can favour certain high-cardinality features.<\/li>\n\n\n\n<li><strong>Controlled Through Regularisation Parameters:<\/strong> Tree growth can be restricted using parameters such as <code>max_depth<\/code>, <code>min_samples_split<\/code>, <code>min_samples_leaf<\/code>, <code>max_leaf_nodes<\/code>, and <code>ccp_alpha<\/code>. These controls reduce unnecessary branching and help prevent the model from memorising training data.<\/li>\n\n\n\n<li><strong>Pruning Helps Control Overfitting:<\/strong> Fully grown Decision Trees can become deep and highly specific to the training dataset. <strong>Pre-pruning<\/strong> limits tree growth during training, while <strong>post-pruning<\/strong>, such as cost-complexity pruning, removes branches that provide limited predictive benefit. This can improve generalisation on unseen data.<\/li>\n<\/ul>\n\n\n\n<p><em>Build practical machine learning skills and understand how Decision Trees work with HCL GUVI\u2019s <\/em><a href=\"https:\/\/www.guvi.in\/courses\/machine-learning-and-ai\/scikit-learn-for-machine-learning-part-1\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=decision-tree-in-data-science-working-algorithms-python-and-applications\"><em>Scikit-Learn for Machine Learning Course<\/em><\/a><em>. Learn model building, classification, regression, Scikit-Learn workflows, and Python-based machine learning through structured hands-on training.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How Decision Trees Choose the Best Split<\/strong><\/h2>\n\n\n\n<p>Choosing the correct split is central to Decision Tree learning.<\/p>\n\n\n\n<p>The exact criterion depends on whether the problem involves classification or regression.<\/p>\n\n\n\n<ol>\n<li><strong>Gini Impurity<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Gini Impurity measures how mixed the classes are inside a node.<\/p>\n\n\n\n<p>It can be represented as:<\/p>\n\n\n\n<p><strong>Gini = 1 &#8211; \u03a3p\u1d62\u00b2<\/strong><\/p>\n\n\n\n<p>where p\u1d62 is the proportion of observations belonging to class i.<\/p>\n\n\n\n<p>Suppose a node contains:<\/p>\n\n\n\n<ul>\n<li>80 fraud transactions<\/li>\n\n\n\n<li>20 legitimate transactions<\/li>\n<\/ul>\n\n\n\n<p>The probabilities are:<\/p>\n\n\n\n<p><strong>P(Fraud) = 0.8<\/strong><\/p>\n\n\n\n<p><strong>P(Legitimate) = 0.2<\/strong><\/p>\n\n\n\n<p>Therefore:<\/p>\n\n\n\n<p><strong>Gini = 1 &#8211; (0.8\u00b2 + 0.2\u00b2)<\/strong><\/p>\n\n\n\n<p><strong>Gini = 0.32<\/strong><\/p>\n\n\n\n<p>A completely pure node containing only one class has Gini Impurity equal to 0.<\/p>\n\n\n\n<p>The algorithm generally prefers splits that produce lower weighted impurity in the child nodes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Entropy and Information Gain<\/strong><\/h3>\n\n\n\n<p>Entropy also measures uncertainty or disorder inside a node.<\/p>\n\n\n\n<p>The formula is:<\/p>\n\n\n\n<p><strong>Entropy = -\u03a3p\u1d62 log\u2082(p\u1d62)<\/strong><\/p>\n\n\n\n<p>A pure node has an entropy of 0.<\/p>\n\n\n\n<p>The Decision Tree calculates how much entropy decreases after a split.<\/p>\n\n\n\n<p>This reduction is called <strong>Information Gain<\/strong>:<\/p>\n\n\n\n<p><strong>Information Gain = Parent Entropy &#8211; Weighted Child Entropy<\/strong><\/p>\n\n\n\n<p>A split producing greater Information Gain separates the classes more effectively.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Gini Impurity vs Entropy<\/strong><\/h2>\n\n\n\n<p>Both criteria usually produce similar trees, but they calculate node quality differently.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Factor<\/strong><\/td><td><strong>Gini Impurity<\/strong><\/td><td><strong>Entropy<\/strong><\/td><\/tr><tr><td>Measures<\/td><td>Class impurity<\/td><td>Information uncertainty<\/td><\/tr><tr><td>Formula<\/td><td>1 &#8211; \u03a3p\u00b2<\/td><td>-\u03a3p log\u2082p<\/td><\/tr><tr><td>Pure Node<\/td><td>0<\/td><td>0<\/td><\/tr><tr><td>Common Use<\/td><td>CART-style classification<\/td><td>Information Gain-based splitting<\/td><\/tr><tr><td>Computation<\/td><td>Slightly simpler<\/td><td>Uses logarithms<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>In practical model development, the difference between the two is often smaller than the effect of parameters such as tree depth and minimum leaf size.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How Regression Trees Select Splits<\/strong><\/h2>\n\n\n\n<p>Regression Trees do not measure class purity because their targets are numerical.<\/p>\n\n\n\n<p>Instead, they attempt to create child nodes containing similar target values.<\/p>\n\n\n\n<p>With squared error, the algorithm searches for splits that reduce variation around the leaf mean.<\/p>\n\n\n\n<p>Suppose a house-price dataset contains:<\/p>\n\n\n\n<ul>\n<li>Area<\/li>\n\n\n\n<li>Number of bedrooms<\/li>\n\n\n\n<li>Location score<\/li>\n\n\n\n<li>Property age<\/li>\n\n\n\n<li>Sale price<\/li>\n<\/ul>\n\n\n\n<p>The tree may split first on:<\/p>\n\n\n\n<p><strong>Area &lt;= 1500 sq. ft.<\/strong><\/p>\n\n\n\n<p>Each resulting group is then evaluated for another split that further reduces prediction error.<\/p>\n\n\n\n<p>Scikit-learn&#8217;s current DecisionTreeRegressor uses squared_error by default.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Key Applications of Decision Trees in Data Science<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Key-Applications-of-Decision-Tree-in-Data-Science@2x-1200x630.png\" alt=\"Key Applications of Decision Tree in Data Science\" class=\"wp-image-83507\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Key-Applications-of-Decision-Tree-in-Data-Science@2x-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Key-Applications-of-Decision-Tree-in-Data-Science@2x-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Key-Applications-of-Decision-Tree-in-Data-Science@2x-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Key-Applications-of-Decision-Tree-in-Data-Science@2x-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Key-Applications-of-Decision-Tree-in-Data-Science@2x-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Key-Applications-of-Decision-Tree-in-Data-Science@2x-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p><a href=\"https:\/\/www.guvi.in\/hub\/house-price-prediction-using-machine-learning-xgboost\/understanding-decision-trees\/\">Decision Trees<\/a> are especially useful when relationships between features and outcomes can be represented through interpretable rules.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Fraud Detection<\/strong><\/h3>\n\n\n\n<p>A fraud model may consider:<\/p>\n\n\n\n<ul>\n<li>Transaction amount<\/li>\n\n\n\n<li>Login location<\/li>\n\n\n\n<li>Transaction frequency<\/li>\n\n\n\n<li>Device type<\/li>\n\n\n\n<li>Account age<\/li>\n<\/ul>\n\n\n\n<p>The resulting tree may identify combinations of features associated with suspicious activity.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Customer Churn Prediction<\/strong><\/h3>\n\n\n\n<p>Decision Trees can classify customers as likely or unlikely to churn using:<\/p>\n\n\n\n<ul>\n<li>Subscription duration<\/li>\n\n\n\n<li>Monthly spending<\/li>\n\n\n\n<li>Support requests<\/li>\n\n\n\n<li>Product usage<\/li>\n\n\n\n<li>Renewal history<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Credit Risk Assessment<\/strong><\/h3>\n\n\n\n<p>Financial models may use:<\/p>\n\n\n\n<ul>\n<li>Income<\/li>\n\n\n\n<li>Credit score<\/li>\n\n\n\n<li>Existing debt<\/li>\n\n\n\n<li>Repayment history<\/li>\n\n\n\n<li>Loan amount<\/li>\n<\/ul>\n\n\n\n<p>to estimate whether an applicant belongs to a higher-risk category.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Sales and Demand Prediction<\/strong><\/h3>\n\n\n\n<p><a href=\"https:\/\/www.guvi.in\/blog\/linear-regression-in-data-science\/\">Regression Trees<\/a> can estimate:<\/p>\n\n\n\n<ul>\n<li>Product demand<\/li>\n\n\n\n<li>Revenue<\/li>\n\n\n\n<li>Customer spending<\/li>\n\n\n\n<li>Inventory requirements<\/li>\n<\/ul>\n\n\n\n<p>using historical business features.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Customer Segmentation Rules<\/strong><\/h3>\n\n\n\n<p>Although Decision Trees are supervised rather than clustering algorithms, they can help translate known customer segments into interpretable classification rules.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Operational Risk and Predictive Maintenance<\/strong><\/h3>\n\n\n\n<p>Sensor measurements, equipment age, temperature, pressure, and maintenance history can be used to classify equipment failure risk.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Advantages of Decision Trees in Data Science<\/strong><\/h2>\n\n\n\n<p>Decision Trees offer several practical advantages.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Highly Interpretable<\/strong><\/h3>\n\n\n\n<p>A prediction can be traced through explicit conditions.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<p><strong>Age &lt;= 30 \u2192 Income &gt; 40000 \u2192 High Purchase Probability<\/strong><\/p>\n\n\n\n<p>This makes Decision Trees useful when stakeholders need understandable decision logic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Handles Nonlinear Relationships<\/strong><\/h3>\n\n\n\n<p>Decision Trees do not assume a linear relationship between features and the target.<\/p>\n\n\n\n<p>They can model threshold effects and feature interactions naturally.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Does Not Require Feature Scaling<\/strong><\/h3>\n\n\n\n<p>Algorithms such as K-Nearest Neighbours and Support Vector Machines can be sensitive to feature scales.<\/p>\n\n\n\n<p>Decision Trees select thresholds on individual features, so standardization or normalization is usually unnecessary.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Supports Classification and Regression<\/strong><\/h3>\n\n\n\n<p>The same tree-based framework can solve categorical and continuous prediction problems.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Captures Feature Interactions<\/strong><\/h3>\n\n\n\n<p>The effect of one feature can depend on conditions established earlier in the tree.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<p><strong>If Age &lt; 30, then evaluate Income<\/strong><\/p>\n\n\n\n<p>but:<\/p>\n\n\n\n<p><strong>If Age &gt;= 30, then evaluate Credit Score<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Can Provide Feature Importance<\/strong><\/h3>\n\n\n\n<p>Tree models can calculate impurity-based feature importance.<\/p>\n\n\n\n<p>However, this importance should be interpreted carefully because features with many possible split points can receive misleadingly high importance. Permutation importance can provide an alternative assessment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Decision Trees Work<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-1200x630.png\" alt=\"How Decision Tree Works\" class=\"wp-image-83504\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>A Decision Tree works by <strong>recursively partitioning a dataset into smaller and more homogeneous subsets<\/strong>. At each stage, the algorithm selects a feature and split point that best separates the target variable. This process creates a hierarchy of <strong>root nodes, internal decision nodes, branches, and leaf nodes<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Root Node Starts With the Complete Dataset<\/strong><\/h3>\n\n\n\n<p>The <strong>root node<\/strong> is the first node in the tree and contains all training samples.<\/p>\n\n\n\n<p>The algorithm evaluates candidate features and thresholds to determine which split produces the greatest improvement in target separation.<\/p>\n\n\n\n<p>For example, a credit-risk tree may begin with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Annual Income &lt;= \u20b98,00,000?<\/code><\/pre>\n\n\n\n<p>The dataset is then divided into two child groups depending on whether the condition is true or false.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. The Algorithm Evaluates Candidate Splits<\/strong><\/h3>\n\n\n\n<p>For numerical features, the tree tests different threshold values.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Age &lt;= 35\nIncome &lt;= 600000\nCredit Score &lt;= 720<\/code><\/pre>\n\n\n\n<p>For each candidate split, the algorithm measures how much the resulting child nodes improve purity or reduce prediction error.<\/p>\n\n\n\n<p>In classification problems, commonly used criteria include:<\/p>\n\n\n\n<ul>\n<li><strong>Gini Impurity<\/strong><\/li>\n\n\n\n<li><strong>Entropy<\/strong><\/li>\n\n\n\n<li><strong>Log Loss<\/strong><\/li>\n<\/ul>\n\n\n\n<p>Gini impurity is calculated as:\\[ Gini = 1 &#8211; \\sum_{i=1}^{C} p_i^2 \\]<\/p>\n\n\n\n<p>where <code>p\u1d62<\/code> is the proportion of samples belonging to class <code>i<\/code>.<\/p>\n\n\n\n<p>A node containing mostly one class has lower impurity than a node containing a balanced mixture of classes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. The Best Split Becomes an Internal Node<\/strong><\/h3>\n\n\n\n<p>An <strong>internal node<\/strong>, also called a decision node, contains a condition that divides samples into child nodes.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Credit Score &lt;= 650?<\/code><\/pre>\n\n\n\n<p>Samples satisfying the condition follow one branch, while the remaining samples follow another.<\/p>\n\n\n\n<p>In Scikit-learn, Decision Trees typically create <strong>binary splits<\/strong>, meaning each internal node produces two child nodes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Branches Represent Split Outcomes<\/strong><\/h3>\n\n\n\n<p>Branches connect one decision node to the next.<\/p>\n\n\n\n<p>For a condition such as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Age &lt;= 30<\/code><\/pre>\n\n\n\n<p>the branches may represent:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>True  -&gt; Left Child\nFalse -&gt; Right Child<\/code><\/pre>\n\n\n\n<p>As samples move through successive branches, the feature space is divided into increasingly smaller regions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Recursive Partitioning Continues<\/strong><\/h3>\n\n\n\n<p>The algorithm repeats the same process independently for each child node:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Choose Feature\n      \u2193\nChoose Threshold\n      \u2193\nMeasure Split Quality\n      \u2193\nSelect Best Split\n      \u2193\nCreate Child Nodes\n      \u2193\nRepeat<\/code><\/pre>\n\n\n\n<p>This recursive process allows the tree to capture <strong>nonlinear relationships and interactions between features<\/strong>.<\/p>\n\n\n\n<p>For example, loan approval may depend on income only when the applicant&#8217;s existing debt is above a particular level. A Decision Tree can represent this interaction naturally through successive splits.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Leaf Nodes Produce Final Predictions<\/strong><\/h3>\n\n\n\n<p>A <strong>leaf node<\/strong> is a terminal node where no additional split is performed.<\/p>\n\n\n\n<p>For classification, the prediction is typically based on the class distribution of training samples reaching that leaf.<\/p>\n\n\n\n<p>Suppose a leaf contains:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Approved: 42\nRejected: 8<\/code><\/pre>\n\n\n\n<p>The predicted class would generally be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Approved<\/code><\/pre>\n\n\n\n<p>The estimated class probability would be approximately:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>P(Approved) = 42 \/ 50 = 0.84<\/code><\/pre>\n\n\n\n<p>For regression, the leaf returns a numerical value derived from the target values of samples in that region, commonly their mean when squared error is used.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. Tree Growth Stops Based on Defined Conditions<\/strong><\/h3>\n\n\n\n<p>A Decision Tree should not split indefinitely.<\/p>\n\n\n\n<p>Growth may stop when:<\/p>\n\n\n\n<ul>\n<li>A node reaches the maximum allowed depth.<\/li>\n\n\n\n<li>Too few samples remain to create another split.<\/li>\n\n\n\n<li>A leaf reaches the minimum sample requirement.<\/li>\n\n\n\n<li>No candidate split provides sufficient improvement.<\/li>\n\n\n\n<li>The maximum number of leaf nodes is reached.<\/li>\n\n\n\n<li>A pruning rule removes unnecessary branches.<\/li>\n<\/ul>\n\n\n\n<p>Important Scikit-learn controls include:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>max_depth\nmin_samples_split\nmin_samples_leaf\nmax_leaf_nodes\nmin_impurity_decrease\nccp_alpha<\/code><\/pre>\n\n\n\n<p>These parameters help control model complexity.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>8. Prediction Follows One Root-to-Leaf Path<\/strong><\/h3>\n\n\n\n<p>Once the tree is trained, a new observation passes through only one path.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Root:\nIncome &lt;= 700000?\n        |\n       Yes\n        \u2193\nCredit Score &lt;= 680?\n        |\n        No\n        \u2193\nDebt Ratio &lt;= 0.35?\n        |\n       Yes\n        \u2193\nLeaf: Approve Loan<\/code><\/pre>\n\n\n\n<p>Each prediction can therefore be traced through a sequence of explicit rules.<\/p>\n\n\n\n<p>This makes Decision Trees easier to interpret than many black-box machine learning models.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>9. Classification and Regression Trees Use Different Split Objectives<\/strong><\/h3>\n\n\n\n<p>The tree structure is similar for both tasks, but the optimization objective changes.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><strong>Task<\/strong><\/th><th><strong>Typical Split Criteria<\/strong><\/th><th><strong>Leaf Output<\/strong><\/th><\/tr><\/thead><tbody><tr><td>Classification<\/td><td>Gini, Entropy, Log Loss<\/td><td>Class or class probability<\/td><\/tr><tr><td>Regression<\/td><td>Squared Error, Friedman MSE, Absolute Error, Poisson<\/td><td>Numerical prediction<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>A classification tree tries to create <strong>purer class distributions<\/strong>, while a regression tree attempts to reduce the variation of continuous target values within each child node.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>10. Pruning Controls Overfitting<\/strong><\/h3>\n\n\n\n<p>A fully grown tree may create highly specific rules that fit noise in the training data.<\/p>\n\n\n\n<p>This causes <strong>overfitting<\/strong>.<\/p>\n\n\n\n<p>Two approaches help control it:<\/p>\n\n\n\n<ul>\n<li><strong>Pre-pruning:<\/strong> Restricts tree growth using parameters such as <code>max_depth<\/code>, <code>min_samples_split<\/code>, or <code>min_samples_leaf<\/code>.<\/li>\n\n\n\n<li><strong>Post-pruning:<\/strong> Grows a larger tree and later removes branches that contribute little predictive value.<\/li>\n<\/ul>\n\n\n\n<p>Scikit-learn supports <strong>cost-complexity pruning<\/strong> through <code>ccp_alpha<\/code>.<\/p>\n\n\n\n<p>The objective is not to create the deepest possible tree, but to find a tree that captures useful patterns while still generalizing to unseen data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Decision Tree Example: How a Prediction Is Made<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-1-1200x630.png\" alt=\"How Decision Tree Works\" class=\"wp-image-83505\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-1-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-1-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-1-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-1-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-1-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/How-Decision-Tree-Works@2x-1-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<ul>\n<li>The first condition for a fit person is, they should be below 30 years old.<\/li>\n\n\n\n<li>The second condition is to check whether the person eats a lot of pizzas or exercises in the morning.<\/li>\n\n\n\n<li>Based on the two conditions, the decision tree will predict whether the person is fit or unfit.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example 1:<\/strong> <\/p>\n\n\n\n<p>Suppose a person is <strong>35 years old and exercises in the morning<\/strong>.<\/p>\n\n\n\n<p>The prediction path is:<\/p>\n\n\n\n<p><strong>Age &lt; 30? \u2192 No \u2192 Exercises in the morning? \u2192 Yes \u2192 Fit<\/strong><\/p>\n\n\n\n<p>Because the first condition is false, the observation moves to the right child node. The second condition evaluates exercise behaviour. Since the person exercises in the morning, the sample reaches the <strong>Fit<\/strong> leaf node.<\/p>\n\n\n\n<p>Technically, the model does not calculate the prediction using all features simultaneously. It evaluates only the features encountered along that specific <strong>root-to-leaf decision path<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-1@2x-1200x630.png\" alt=\"Example 1\" class=\"wp-image-83502\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-1@2x-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-1@2x-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-1@2x-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-1@2x-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-1@2x-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-1@2x-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p><strong>Example 2:<\/strong> <\/p>\n\n\n\n<p>Now consider a person who is <strong>28 years old and eats a lot of pizza<\/strong>.<\/p>\n\n\n\n<p>The prediction path becomes:<\/p>\n\n\n\n<p><strong>Age &lt; 30? \u2192 Yes \u2192 Eats a lot of pizza? \u2192 Yes \u2192 Unfit<\/strong><\/p>\n\n\n\n<p>The first split routes the observation to the left subtree because the age condition is satisfied. The second internal node evaluates eating behaviour, after which the sample reaches the <strong>Unfit<\/strong> leaf.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-2@2x-1200x630.png\" alt=\"Example 2\" class=\"wp-image-83503\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-2@2x-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-2@2x-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-2@2x-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-2@2x-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-2@2x-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Example-2@2x-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Implementing Decision Trees in Data Science: Step-by-Step<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Implementing-Decision-Tree-in-Data-Science@2x-1200x630.png\" alt=\"Implementing Decision Tree in Data Science\" class=\"wp-image-83506\" style=\"aspect-ratio:1.9047619047619047;width:840px;height:auto\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Implementing-Decision-Tree-in-Data-Science@2x-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Implementing-Decision-Tree-in-Data-Science@2x-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Implementing-Decision-Tree-in-Data-Science@2x-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Implementing-Decision-Tree-in-Data-Science@2x-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Implementing-Decision-Tree-in-Data-Science@2x-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/07\/Implementing-Decision-Tree-in-Data-Science@2x-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Implementing a Decision Tree involves more than fitting a model to a dataset. A reliable workflow includes data preparation, train-test splitting, model configuration, training, prediction, evaluation, interpretation, and hyperparameter tuning.<\/p>\n\n\n\n<p>The following example uses <strong><a href=\"https:\/\/www.guvi.in\/blog\/text-classification-with-scikit-learn\/\" data-type=\"post\" data-id=\"117423\">Scikit-learn<\/a><\/strong> to build a Decision Tree classification model in Python.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Import the Required Libraries<\/strong><\/h3>\n\n\n\n<p>Start by importing the dataset, preprocessing utilities, Decision Tree model, and evaluation metrics.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.datasets import load_irisfrom sklearn.model_selection import train_test_splitfrom sklearn.tree import DecisionTreeClassifier, plot_treefrom sklearn.metrics import (    accuracy_score,    classification_report,    confusion_matrix)import matplotlib.pyplot as plt<\/code><\/pre>\n\n\n\n<p>The main components are:<\/p>\n\n\n\n<ul>\n<li><code>train_test_split<\/code> separates training data from unseen test data.<\/li>\n\n\n\n<li><code>DecisionTreeClassifier<\/code> builds the classification tree.<\/li>\n\n\n\n<li><code>plot_tree<\/code> visualizes learned decision rules.<\/li>\n\n\n\n<li><code>accuracy_score<\/code> measures overall prediction accuracy.<\/li>\n\n\n\n<li><code>classification_report<\/code> provides precision, recall, and F1-score.<\/li>\n\n\n\n<li><code>confusion_matrix<\/code> shows how predicted classes compare with actual classes.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Load and Inspect the Dataset<\/strong><\/h3>\n\n\n\n<p>For this example, use the Iris dataset.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>iris = load_iris()X = iris.datay = iris.targetprint(X.shape)print(iris.feature_names)print(iris.target_names)<\/code><\/pre>\n\n\n\n<p>The dataset contains <strong>150 observations<\/strong>, four numerical input features, and three target classes.<\/p>\n\n\n\n<p>The input features are:<\/p>\n\n\n\n<ul>\n<li>Sepal length<\/li>\n\n\n\n<li>Sepal width<\/li>\n\n\n\n<li>Petal length<\/li>\n\n\n\n<li>Petal width<\/li>\n<\/ul>\n\n\n\n<p>The target variable identifies the Iris species.<\/p>\n\n\n\n<p>Before training any Decision Tree, developers should inspect:<\/p>\n\n\n\n<ul>\n<li>Number of samples<\/li>\n\n\n\n<li>Feature data types<\/li>\n\n\n\n<li>Missing values<\/li>\n\n\n\n<li>Class distribution<\/li>\n\n\n\n<li>Potential outliers<\/li>\n\n\n\n<li>Target variable structure<\/li>\n<\/ul>\n\n\n\n<p>Decision Trees do not require feature standardization because they split observations using thresholds instead of distance calculations.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3: Split the Data Into Training and Test Sets<\/strong><\/h3>\n\n\n\n<p>The model should be trained and evaluated on separate data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>X_train, X_test, y_train, y_test = train_test_split(    X,    y,    test_size=0.20,    random_state=42,    stratify=y)<\/code><\/pre>\n\n\n\n<p>Here:<\/p>\n\n\n\n<ul>\n<li><code>test_size=0.20<\/code> reserves 20% of the data for testing.<\/li>\n\n\n\n<li><code>random_state=42<\/code> makes the split reproducible.<\/li>\n\n\n\n<li><code>stratify=y<\/code> preserves approximately the same class distribution in both subsets.<\/li>\n<\/ul>\n\n\n\n<p>The model learns decision rules using <code>X_train<\/code> and <code>y_train<\/code>. The test set remains unseen until evaluation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 4: Configure the Decision Tree Model<\/strong><\/h3>\n\n\n\n<p>Create the classifier with selected hyperparameters.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>model = DecisionTreeClassifier(    criterion=\"gini\",    max_depth=4,    min_samples_split=2,    min_samples_leaf=1,    random_state=42)<\/code><\/pre>\n\n\n\n<p>Important parameters include:<\/p>\n\n\n\n<ul>\n<li><strong><code>criterion<\/code>:<\/strong> Determines how split quality is measured. Common options include <code>gini<\/code>, <code>entropy<\/code>, and <code>log_loss<\/code>.<\/li>\n\n\n\n<li><strong><code>max_depth<\/code>:<\/strong> Limits how many levels the tree can grow.<\/li>\n\n\n\n<li><strong><code>min_samples_split<\/code>:<\/strong> Defines the minimum number of samples required before an internal node can split.<\/li>\n\n\n\n<li><strong><code>min_samples_leaf<\/code>:<\/strong> Defines the minimum number of samples allowed in a leaf node.<\/li>\n\n\n\n<li><strong><code>max_features<\/code>:<\/strong> Limits how many features are considered when searching for each split.<\/li>\n\n\n\n<li><strong><code>ccp_alpha<\/code>:<\/strong> Controls cost-complexity pruning.<\/li>\n<\/ul>\n\n\n\n<p>Without restrictions, a tree may continue splitting until leaves become extremely specific to the training data, increasing the risk of overfitting.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 5: Train the Decision Tree<\/strong><\/h3>\n\n\n\n<p>Fit the model using the training data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>model.fit(X_train, y_train)<\/code><\/pre>\n\n\n\n<p>During training, the algorithm evaluates possible feature thresholds.<\/p>\n\n\n\n<p>For example, it may test conditions such as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>petal width &lt;= 0.8\npetal length &lt;= 4.75\nsepal length &lt;= 5.9<\/code><\/pre>\n\n\n\n<p>For every candidate split, the algorithm measures how much the split reduces impurity.<\/p>\n\n\n\n<p>If Gini impurity is used:\\[ Gini = 1 &#8211; \\sum_{i=1}^{C} p_i^2 \\]<\/p>\n\n\n\n<p>where <code>p\u1d62<\/code> represents the proportion of samples belonging to class <code>i<\/code>.<\/p>\n\n\n\n<p>A lower Gini value indicates a purer node.<\/p>\n\n\n\n<p>The algorithm recursively repeats this process until a stopping rule is reached.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 6: Generate Predictions<\/strong><\/h3>\n\n\n\n<p>After training, use the model to predict classes for unseen observations.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>y_pred = model.predict(X_test)<\/code><\/pre>\n\n\n\n<p>You can also retrieve estimated class probabilities:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>y_prob = model.predict_proba(X_test)print(y_prob&#91;:3])<\/code><\/pre>\n\n\n\n<p>For each observation, <code>predict_proba()<\/code> returns the proportion of training samples from each class contained in the reached leaf.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;0.00, 0.95, 0.05]<\/code><\/pre>\n\n\n\n<p>indicates that the corresponding leaf strongly favours the second class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 7: Evaluate Model Performance<\/strong><\/h3>\n\n\n\n<p>Accuracy alone may not provide enough information.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>accuracy = accuracy_score(y_test, y_pred)print(\"Accuracy:\", accuracy)print(classification_report(y_test, y_pred))print(confusion_matrix(y_test, y_pred))<\/code><\/pre>\n\n\n\n<p>Important classification metrics include:<\/p>\n\n\n\n<ul>\n<li><strong>Accuracy:<\/strong> Percentage of all predictions that are correct.<\/li>\n\n\n\n<li><strong>Precision:<\/strong> Percentage of predicted positives that are actually positive.<\/li>\n\n\n\n<li><strong>Recall:<\/strong> Percentage of actual positives correctly identified.<\/li>\n\n\n\n<li><strong>F1-Score:<\/strong> Harmonic mean of precision and recall.<\/li>\n\n\n\n<li><strong>Confusion Matrix:<\/strong> Shows true and false predictions for every class.<\/li>\n<\/ul>\n\n\n\n<p>For imbalanced datasets, precision, recall, F1-score, ROC-AUC, or PR-AUC may provide more useful information than accuracy alone.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 8: Visualize the Decision Tree<\/strong><\/h3>\n\n\n\n<p>One major advantage of Decision Trees is that their learned rules can be inspected visually.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>plt.figure(figsize=(16, 8))plot_tree(    model,    feature_names=iris.feature_names,    class_names=iris.target_names,    filled=True,    rounded=True)plt.show()<\/code><\/pre>\n\n\n\n<p>Each node typically displays information such as:<\/p>\n\n\n\n<ul>\n<li>Split condition<\/li>\n\n\n\n<li>Impurity value<\/li>\n\n\n\n<li>Number of samples<\/li>\n\n\n\n<li>Class distribution<\/li>\n\n\n\n<li>Predicted class<\/li>\n<\/ul>\n\n\n\n<p>A path through the tree can therefore be interpreted as a sequence of decision rules.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Petal length &lt;= 2.45\n        |\n       Yes\n        |\nPredict Setosa<\/code><\/pre>\n\n\n\n<p>This interpretability is one reason Decision Trees are useful in applications where prediction logic needs to be inspected.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 9: Examine Feature Importance<\/strong><\/h3>\n\n\n\n<p>Scikit-learn provides impurity-based feature importance scores.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for feature, importance in zip(    iris.feature_names,    model.feature_importances_):    print(feature, importance)<\/code><\/pre>\n\n\n\n<p>A higher value indicates that the feature contributed more to impurity reduction across the trained tree.<\/p>\n\n\n\n<p>However, these values should be interpreted carefully. Impurity-based importance can favour variables with many possible split points and does not establish causal relationships.<\/p>\n\n\n\n<p>Permutation importance or SHAP-based analysis can provide additional insight when feature interpretation is important.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 10: Tune the Decision Tree<\/strong><\/h3>\n\n\n\n<p>A Decision Tree that performs extremely well on training data but poorly on test data is probably overfitting.<\/p>\n\n\n\n<p>Common parameters to tune include:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>max_depth\nmin_samples_split\nmin_samples_leaf\nmax_features\nmax_leaf_nodes\ncriterion\nccp_alpha<\/code><\/pre>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>model = DecisionTreeClassifier(    max_depth=5,    min_samples_split=10,    min_samples_leaf=5,    ccp_alpha=0.001,    random_state=42)<\/code><\/pre>\n\n\n\n<p>Hyperparameters should ideally be selected using cross-validation rather than repeatedly checking performance on the final test set.<\/p>\n\n\n\n<p>Tools such as <code>GridSearchCV<\/code> and <code>RandomizedSearchCV<\/code> can systematically evaluate parameter combinations.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 11: Use Decision Trees for Regression<\/strong><\/h3>\n\n\n\n<p>The same basic workflow applies to regression problems.<\/p>\n\n\n\n<p>Instead of:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DecisionTreeClassifier<\/code><\/pre>\n\n\n\n<p>use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.tree import DecisionTreeRegressorregressor = DecisionTreeRegressor(    criterion=\"squared_error\",    max_depth=5,    random_state=42)regressor.fit(X_train, y_train)<\/code><\/pre>\n\n\n\n<p><code>DecisionTreeRegressor<\/code> supports criteria such as:<\/p>\n\n\n\n<ul>\n<li><code>squared_error<\/code><\/li>\n\n\n\n<li><code>friedman_mse<\/code><\/li>\n\n\n\n<li><code>absolute_error<\/code><\/li>\n\n\n\n<li><code>poisson<\/code><\/li>\n<\/ul>\n\n\n\n<p>Instead of predicting classes, regression trees place observations into regions and return numerical predictions based on the target values of training samples within each leaf.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Complete Decision Tree Workflow<\/strong><\/h3>\n\n\n\n<p>A practical Decision Tree pipeline can therefore be summarized as:<\/p>\n\n\n\n<p><strong>Collect Data \u2192 Inspect Features \u2192 Split Dataset \u2192 Configure Tree \u2192 Train Model \u2192 Predict \u2192 Evaluate \u2192 Visualize \u2192 Tune Hyperparameters \u2192 Validate on Unseen Data<\/strong><\/p>\n\n\n\n<p>Following this workflow helps ensure that the Decision Tree is not only accurate on training data but also interpretable, controlled for overfitting, and suitable for real-world prediction tasks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Decision Tree vs Random Forest vs <a href=\"https:\/\/www.guvi.in\/hub\/house-price-prediction-using-machine-learning-xgboost\/understanding-gradient-boosting\/\">Gradient Boosting<\/a><\/strong><\/h2>\n\n\n\n<p>A single Decision Tree prioritizes interpretability, while ensemble methods combine multiple trees to improve predictive performance.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Factor<\/strong><\/td><td><strong>Decision Tree<\/strong><\/td><td><strong>Random Forest<\/strong><\/td><td><strong>Gradient Boosting<\/strong><\/td><\/tr><tr><td>Number of Trees<\/td><td>One<\/td><td>Many<\/td><td>Many sequential trees<\/td><\/tr><tr><td>Interpretability<\/td><td>High<\/td><td>Moderate to low<\/td><td>Low<\/td><\/tr><tr><td>Overfitting Risk<\/td><td>High if unrestricted<\/td><td>Lower than one tree<\/td><td>Controlled through tuning<\/td><\/tr><tr><td>Training Method<\/td><td>Recursive splitting<\/td><td>Bagging + random feature subsets<\/td><td>Sequential error correction<\/td><\/tr><tr><td>Prediction Power<\/td><td>Good baseline<\/td><td>Usually stronger<\/td><td>Often very strong<\/td><\/tr><tr><td>Parallel Training<\/td><td>Single model<\/td><td>Highly parallelizable<\/td><td>More sequential<\/td><\/tr><tr><td>Best Use<\/td><td>Explainable baseline<\/td><td>Robust general-purpose prediction<\/td><td>High-performance tabular modelling<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>A Decision Tree is often the best place to learn tree-based modelling because Random Forest and boosting methods build on the same fundamental idea of recursive partitioning.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Mistakes When Building Decision Trees<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Training and Testing on the Same Dataset<\/strong><\/h3>\n\n\n\n<p>Evaluating a model on its training data produces an unrealistically optimistic estimate.<\/p>\n\n\n\n<p>Always preserve unseen validation or test data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Allowing Unlimited Tree Growth<\/strong><\/h3>\n\n\n\n<p>An unrestricted tree can memorize individual training observations.<\/p>\n\n\n\n<p>Control complexity using depth, leaf-size, impurity, or pruning parameters.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Evaluating Only Accuracy<\/strong><\/h3>\n\n\n\n<p>For imbalanced classification, a model can achieve high accuracy by repeatedly predicting the majority class.<\/p>\n\n\n\n<p>Also examine:<\/p>\n\n\n\n<ul>\n<li>Precision<\/li>\n\n\n\n<li>Recall<\/li>\n\n\n\n<li>F1-score<\/li>\n\n\n\n<li>Confusion matrix<\/li>\n\n\n\n<li>ROC-AUC or PR-AUC where appropriate<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Treating Feature Importance as Causality<\/strong><\/h3>\n\n\n\n<p>A high importance score means a feature contributed strongly to the tree&#8217;s splits.<\/p>\n\n\n\n<p>It does not prove that changing the feature would cause the target outcome to change.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Ignoring Class Imbalance<\/strong><\/h3>\n\n\n\n<p>For highly imbalanced targets, consider:<\/p>\n\n\n\n<p>DecisionTreeClassifier(<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;class_weight=&#8221;balanced&#8221;<\/p>\n\n\n\n<p>)<\/p>\n\n\n\n<p>Scikit-learn can automatically assign class weights inversely related to class frequencies when class_weight=&#8221;balanced&#8221; is used.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Using a Very Small Toy Dataset as Proof of Performance<\/strong><\/h3>\n\n\n\n<p>A model trained on six or ten manually created observations cannot demonstrate realistic predictive performance.<\/p>\n\n\n\n<p>Use sufficiently representative datasets and proper validation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Improve Decision Tree Performance<\/strong><\/h2>\n\n\n\n<p>A stronger Decision Tree workflow usually includes:<\/p>\n\n\n\n<ol>\n<li>Clean and validate the dataset.<\/li>\n\n\n\n<li>Separate training, validation, and test data where appropriate.<\/li>\n\n\n\n<li>Establish an unrestricted or lightly constrained baseline.<\/li>\n\n\n\n<li>Inspect tree depth and leaf counts.<\/li>\n\n\n\n<li>Tune max_depth.<\/li>\n\n\n\n<li>Tune min_samples_split.<\/li>\n\n\n\n<li>Tune min_samples_leaf.<\/li>\n\n\n\n<li>Evaluate cost-complexity pruning.<\/li>\n\n\n\n<li>Use cross-validation.<\/li>\n\n\n\n<li>Compare against ensemble baselines.<\/li>\n<\/ol>\n\n\n\n<p>The objective is not to build the deepest possible tree.<\/p>\n\n\n\n<p>It is to find the smallest tree that generalizes well enough for the problem.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>When Should You Use a Decision Tree?<\/strong><\/h2>\n\n\n\n<p>Decision Trees are particularly useful when:<\/p>\n\n\n\n<ul>\n<li>Interpretability is important.<\/li>\n\n\n\n<li>Feature interactions are expected.<\/li>\n\n\n\n<li>Relationships are nonlinear.<\/li>\n\n\n\n<li>Data is primarily tabular.<\/li>\n\n\n\n<li>A transparent baseline model is required.<\/li>\n\n\n\n<li>Feature scaling should be avoided.<\/li>\n\n\n\n<li>Business rules need to be extracted from model behaviour.<\/li>\n<\/ul>\n\n\n\n<p>A different model may be preferable when:<\/p>\n\n\n\n<ul>\n<li>Very high predictive accuracy is more important than interpretability.<\/li>\n\n\n\n<li>Small data changes make the tree unstable.<\/li>\n\n\n\n<li>Raw images, audio, or text embeddings dominate the input.<\/li>\n\n\n\n<li>Smooth extrapolation is required.<\/li>\n\n\n\n<li>The relationship is better captured by another model family.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Decision Trees in Modern Data Science<\/strong><\/h2>\n\n\n\n<p>Decision Trees remain highly relevant because tree-based models dominate many structured and tabular machine learning problems.<\/p>\n\n\n\n<p>Their importance extends beyond standalone Decision Trees.<\/p>\n\n\n\n<p>The same recursive splitting concept appears in:<\/p>\n\n\n\n<ul>\n<li><a href=\"https:\/\/www.guvi.in\/blog\/random-forest-classifier\/\">Random Forest<\/a><\/li>\n\n\n\n<li>Extra Trees<\/li>\n\n\n\n<li>AdaBoost<\/li>\n\n\n\n<li>Gradient Boosting<\/li>\n\n\n\n<li>XGBoost<\/li>\n\n\n\n<li>LightGBM<\/li>\n\n\n\n<li>CatBoost<\/li>\n<\/ul>\n\n\n\n<p>Learning how a single tree chooses splits, creates leaves, overfits, and gets pruned makes these more advanced algorithms easier to understand.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Limitations of Decision Trees<\/strong><\/h2>\n\n\n\n<p><a href=\"https:\/\/www.guvi.in\/blog\/decision-tree-in-machine-learning\/\">Decision Trees in machine learning<\/a> are simple to understand but can develop several modelling problems.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Overfitting<\/strong><\/h3>\n\n\n\n<p>An unrestricted tree may continue splitting until it captures noise and individual training examples.<\/p>\n\n\n\n<p>This produces excellent training performance but weak generalization.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Model Instability<\/strong><\/h3>\n\n\n\n<p>Small changes in the training dataset can produce different split points and a significantly different tree.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Greedy Split Selection<\/strong><\/h3>\n\n\n\n<p>A Decision Tree chooses the best split available at the current node.<\/p>\n\n\n\n<p>It does not search every possible future tree structure for a globally optimal solution.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Poor Extrapolation in Regression<\/strong><\/h3>\n\n\n\n<p>Regression Trees create piecewise constant predictions.<\/p>\n\n\n\n<p>They generally cannot extrapolate smoothly beyond patterns represented in the training data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Deep Trees Lose Interpretability<\/strong><\/h3>\n\n\n\n<p>A tree with three levels may be easy to explain.<\/p>\n\n\n\n<p>A tree containing hundreds of nodes is technically interpretable but difficult for a human to understand.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Impurity-Based Feature Importance Can Mislead<\/strong><\/h3>\n\n\n\n<p>Features with many unique values may appear artificially important.<\/p>\n\n\n\n<p>Feature importance should therefore be validated using techniques such as permutation importance or SHAP when interpretation matters.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Decision Trees provide one of the clearest ways to understand how supervised machine learning converts features into predictions. They recursively divide data using criteria such as Gini Impurity, Entropy, or regression error until observations reach terminal leaves containing the final output.<\/p>\n\n\n\n<p>Their interpretability makes them valuable for explainable tabular modelling, but unrestricted trees can overfit and become unstable. Parameters such as max_depth, min_samples_split, min_samples_leaf, and ccp_alpha help control complexity and improve generalization.<\/p>\n\n\n\n<p>Understanding Decision Trees also creates a strong foundation for Random Forest, Gradient Boosting, and other advanced tree-based models widely used across modern Data Science.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1750324588793\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Q1. Do I need coding for data science?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes, coding is an essential skill for data science. Being comfortable with coding is crucial for tasks like data manipulation, building machine learning models, and automating processes. <strong>Python<\/strong> and <strong>R<\/strong> are the most commonly used programming languages in data science, and they have extensive libraries to make your job easier.\u00a0<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1750324593188\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Q2. Is DSA required for data science?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes, Data Structures and Algorithms (DSA) are important for data science, especially for machine learning and data engineering. DSA helps with data management, analysis, and problem solving. It can also help you write efficient code. You can expect DSA-based coding challenges during the interview.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1750324603690\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Q3. Which language is best for data science?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The most popular and widely used language for data science is <strong>Python<\/strong>. It\u2019s beginner-friendly, has a rich ecosystem of libraries (like Pandas, NumPy), and is great for tasks like data cleaning, analysis, and machine learning. For those working on large-scale systems, <strong><a href=\"https:\/\/www.scala-lang.org\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Scala<\/a><\/strong> and <strong><a href=\"https:\/\/julialang.org\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Julia<\/a><\/strong> are gaining popularity as well, especially for machine learning and high-performance tasks.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1750324613974\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Q4. What industries hire data scientists?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Data scientists are in demand everywhere, from tech giants like Google and Amazon to healthcare, finance, retail, and entertainment. Almost every industry is tapping into data to drive smarter decisions.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1750324626029\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Q5. Is data science a good career for freshers<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Absolutely! With the booming demand for data-driven insights, freshers with strong analytical skills and a passion for learning can easily find opportunities and grow rapidly in the field.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Decision Trees are among the most interpretable supervised machine learning algorithms used in Data Science. They convert a prediction problem into a sequence of feature-based rules, making it possible to trace exactly how the model reaches a classification or regression output. A Decision Tree repeatedly splits a dataset into smaller subsets using conditions such as [&hellip;]<\/p>\n","protected":false},"author":60,"featured_media":141756,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"views":"4687","authorinfo":{"name":"Vaishali","url":"https:\/\/www.guvi.in\/blog\/author\/vaishali\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/10\/IMG_5133-300x116.png","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/81856"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/60"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=81856"}],"version-history":[{"count":17,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/81856\/revisions"}],"predecessor-version":[{"id":141761,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/81856\/revisions\/141761"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/141756"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=81856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=81856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=81856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}