Choosing the Best Algorithm: Decision Trees vs. Random Forest

This video compares decision trees and random forest on a loan approval dataset, covering attribute selection, encoding, and accuracy for each model.

5:00 video3 min readWatch on YouTube

Choosing between a decision tree and a random forest is not just a matter of picking the "better" algorithm, it depends on what tradeoffs a project can afford between interpretability and predictive power. This video works through both models side by side using a real loan prediction dataset, showing how each one splits data, how they're evaluated, and how their accuracy compares.

The problem: predicting loan approval

The example used throughout is a loan dataset, chosen because loan prediction is a common real-world problem for retail financial institutions. Getting it right matters for more than convenience: it increases customer satisfaction and reduces operational cost, but only if the underlying model is robust enough to accurately predict which loan applications should be approved and which should be rejected, minimizing the risk of default.

How decision trees split the data

The core idea behind a decision tree is selecting the best attribute using an attribute selection measure, or ASM, to split the data into decision nodes that break it into smaller subsets. This process repeats recursively for each child node until a stopping condition is met, such as all remaining records belonging to the same class, no remaining attributes to split on, or no more instances left to divide.

Defining the variables

The dataset separates variables into a target variable and independent variables. Here, loan status serves as the dependent (target) variable, while attributes like gender, marital status, dependents, education, and applicant income serve as independent variables. Loan status itself has two possible outcomes: reject, meaning the loan was denied, and accept, meaning the loan was approved.

The modeling workflow

The overall approach follows a standard sequence: split the data into training and test sets, select the best attribute using an ASM such as information gain, gini index, or gain ratio, break the dataset into smaller subsets based on that attribute, and then evaluate each resulting model on accuracy, precision, and recall.

Technical implementation

On the technical side, categorical fields are first converted into numerical form using one-hot encoding, since machine learning models need numerical input. After splitting the data into training and testing sets, a decision tree classifier is built. One version uses entropy to perform the split, since that is the metric that measures information gain, while the default configuration of the decision tree classifier function uses gini impurity to perform splits instead. Both versions are built and evaluated so their results can be compared directly.

Comparing the results

Once both models are trained, their performance is measured using accuracy, along with precision, recall, and F1 score. In this run, the random forest model achieved 79% accuracy, while the decision tree came in slightly higher at 80% accuracy. The video presents this comparison as a graphical representation, noting that a full practical walkthrough of both models follows in the demonstration.

Key takeaways

  • Decision trees split data by selecting the best attribute at each node using measures like information gain or gini index.
  • The loan status target variable is binary: accept or reject, based on independent variables like income, education, and marital status.
  • Categorical features are converted to numerical form with one-hot encoding before model training.
  • Entropy-based and gini-based decision tree classifiers were both tested and compared against a random forest model.
  • In this run, the decision tree reached about 80% accuracy, slightly ahead of the random forest's 79%.

Who this is for

This video is a solid starting point for learners comparing tree-based classification algorithms on a practical dataset. It fits into Humanitarians AI's broader set of applied machine learning walkthroughs for anyone building intuition around model selection and evaluation.

Full transcript(auto-generated, with timestamps)

[0:00]Today's video we'll learn about the study of decision Tre algorithm that is more focusing on both Information Gain and gain index for splitting up the data so let's start so very first thing is problem statement so for this particular problem I'm using a loan data set so loan prediction is very common in a real life problem problem that every retail sector is in their leading operations it also increases in a customer satiation and saving an operational cost that is more important but the benefit can only be read if the financial sector her robust model to accurately predict which customer loan it should approve or which to reject in

[0:54]Order to minimize the risk of the loan default so here in this the basic idea is to select the best attribute using ASM that is attribute selection measure to split up the rows or records also to make uh the attribute decision node that breaks the data into smaller subset also start re building by repeating this process recursively for each child until one of the condition will match those are all the tle belongs to the same attribute value there is no remaining attribute there is no more instances so defining the problem in this there are two type of variables that is Target and independent variable Target variables are those variable

[1:51]Which are dependent on the V which are dependent or independent those are not independent here I I'm using loan status as a dependent variable and other gender marit dependence education applicant in income etc those are independent variable so end loan status are of two type which is dependent variable that is reject and accept reject means that the loan was rejected and accept means the loan was approved approach to split our model is like first you need to split your data into training data and the test data then you need to select the best attribute using ASM such as Information Gain or in gine index or gain ratio then

[2:47]You breaks the data set into a smaller subset afterward you need to evaluate those models and at last you need to evaluate the performance for each model there you can check the accuracy precision and recall so what is the technical approach I'm using here so very first step is I performed this one hot encode for the categorial FI that means you need to convert your categorial data into a numerical one that is our one hot encoding then splitting up the training and the testing data then build a model using this decision Tre classifier function which uses anat tropy to perform split afterwards building a decision tree for the first time and

[3:40]Checking its accuracy then by default tree classifier function uses gain impurity to perform split afterwards build a model using decision tree classifier which uses an tropy to perform split so this is the result for the decision to and the random Forest ELO so is the graphical representation which we'll see in our practical afterward these all are the results based on the accuracy like the Precision recall EV score for both the algorithms as you see on this result like this is the 79 accuracies for your random forest and uh and the other one have this accuracy of 80 now we'll

[4:51]See some practical work based on these two model thank you

More videos

Humanitarians AI Lyrical Literacy Project