10.3.2 Decision Trees, Random Forests
10.3.2 Decision Trees, Random Forests
These algorithms are powerful and intuitive, often used for both classification and regression tasks. They mimic human-like decision-making processes.
Decision Trees
Imagine you're trying to decide what to wear based on the weather. You might follow a mental flowchart: "Is it raining? If yes, wear a raincoat. If no, is it cold? If yes, wear a jacket. If no, wear a t-shirt." A Decision Tree works exactly like this, creating a flowchart of questions to arrive at a decision.
- What it does: Creates a tree-like model of decisions and their possible consequences. Each "node" in the tree represents a test on an attribute (e.g., "Is temperature > 20?"), each "branch" represents the outcome of the test, and each "leaf" node represents the final decision or prediction.
- Think of it like: A flowchart for making decisions.
- How it works: The algorithm recursively splits the data based on the features that best separate the data into distinct groups, aiming to create "pure" leaf nodes (where all data points in that leaf belong to the same class or have similar values).
- Use Cases:
- Predicting whether a customer will click on an ad.
- Diagnosing medical conditions based on symptoms.
- Deciding on credit risk for loan applications.
Bibliography:
- IBM - What is a decision tree?: https://www.ibm.com/topics/decision-tree
- GeeksforGeeks - Decision Tree in Machine Learning: https://www.geeksforgeeks.org/decision-tree-in-machine-learning/
- Wikipedia - Decision tree learning: https://en.wikipedia.org/wiki/Decision_tree_learning
Random Forests
Now, imagine instead of just one friend giving you weather advice, you ask many friends, each with their own slightly different flowchart (decision tree). Then, you take a vote among all your friends to decide what to wear. If most of them say "raincoat," you wear a raincoat. That's the idea behind a Random Forest.
- What it does: An ensemble learning method that constructs a large number of individual Decision Trees during training. For classification tasks, the output is the class selected by most trees. For regression tasks, the output is the mean or average prediction of the individual trees.
- Think of it like: A "wisdom of the crowd" approach, combining many individual decision trees to make a more robust and accurate prediction.
- How it works: It builds multiple decision trees, each trained on a random subset of the data and a random subset of the features. This "randomness" helps to reduce overfitting (where a model learns the training data too well and performs poorly on new data) and improve generalization.
- Use Cases:
- Predicting stock prices.
- Image classification (e.g., identifying objects in photos).
- Medical diagnosis (often more accurate than a single decision tree).
- Fraud detection.
Bibliography:
- IBM - What is a random forest?: https://www.ibm.com/topics/random-forest
- GeeksforGeeks - Random Forest in Machine Learning: https://www.geeksforgeeks.org/machine-learning/random-forest-algorithm-in-machine-learning/
- Wikipedia - Random forest: https://en.wikipedia.org/wiki/Random_forest