Comprehensive Study Notes on Decision Trees: Classification, Regression, and Implementation Tuning
Decision Tree Fundamentals and Node Selection
Feature Splitting Sequence:
The initial attribute chosen for splitting a decision tree (such as evaluating income prior to age) directly determines the hierarchical structure and downstream performance of the model.
The primary rule or question positioned at the top of the tree dictates the initial separation criteria for the entire dataset.
Root Node Selection Risks:
Selecting a sub-optimal feature like attendance as the root node can introduce redundant or duplicated data across sub-branches.
Algorithms evaluate all available features to identify questions that separate classes with maximum distinctness.
Example: Splitting on a condition like effectively filters student populations into distinct groups.
Pure vs. Mixed Data Split Evaluation
Data Purity Metaphor:
Pure Set: Analogous to a box containing exclusively apples, representing a single class with zero impurity.
Mixed Set: Analogous to a box containing a mixture of apples and oranges, representing non-distinct data distribution.
Quantitative Split Quality Metrics:
The quality of splits (categorized as split, better split, or good split) is evaluated using two explicit algorithms in code:
Gini Impurity
Entropy
These metrics calculate the degree of statistical impurity or randomness at any given decision node.
Decision Tree Applications: Classification and Regression
Task Versatility: Decision trees can be constructed for both classification (categorical targets) and regression (continuous numerical targets) tasks.
Classification Logic Rules:
Applied to target problems such as predicting spam versus not spam (or purchase decision vs. non-purchase).
Example rule evaluation hierarchy:
Step 1: Check previous purchase history. If
Yes, the purchase probability (buy) is evaluated as high.Step 2: If
incomeis not greater than (i.e. ), the tree evaluates secondary features such aswebsite visits.
Feature Engineering and Scaling Characteristics
Input Feature Arrays: Decision trees can incorporate heterogeneous collections of features, including
income,previous purchasestatus, andwebsite visitsto determine purchase likelihood.Feature Scaling Exemption:
Unlike linear models, decision trees do not require feature standardization or normalization (no feature scaling is required).
Primary Vulnerability: The central algorithmic risk inherent to decision trees is overfitting.
Overfitting and Tree Depth Constraints
Overfitting Mechanism: Overfitting occurs when a tree becomes overly complex and memorizes individual training samples rather than extracting generalized pattern boundaries.
Impact of High Feature Dimensionality:
In datasets with high feature counts (e.g., columns), allowing every feature to serve as an unconstrained decision node creates excessively deep trees.
Depth Hyperparameter Control (
max_depth):Tree expansion must be constrained by setting explicit depth limits, such as setting
max_depth = 5ormax_depth = 10during model initialization.Example Depth Constraint: Restricting the architecture to exactly decision nodes ().
Model Implementation and Data Preprocessing Pipeline
Environment & Preprocessing Rules:
Library requirements include
pandasfor data manipulation.Missing dataset values are imputed by replacing them with the attribute mean.
Data Partitioning:
Baseline data division uses an train-test split ( training set, testing set).
Classifier Setup & Passenger Prediction Target:
Model initialization uses a decision tree classifier (
DecisionTreeClassifier) configured withmax_depth = 3.Objective: Predict binary survival outcomes on passenger data (
survivedvs.not survived).Binary Encoding: Output label represents passenger survival (
survived), whereas represents non-survival.
Model Evaluation, Precision, and Recall
Baseline Classification Accuracy:
The decision tree model with
max_depth = 3achieves a baseline classification accuracy of ().
Model Comparison:
A previously tested logistic regression model achieved higher accuracy on the identical passenger prediction dataset.
Evaluation Metrics:
Performance must be tracked across hyperparameter changes using precision and recall metrics alongside raw accuracy.
Experimental Modifications and Parameter Tuning
Feature Matrix () Expansion:
Students are directed to expand input feature vector by selecting features out of total available columns, while keeping target vector fixed.
Candidate features for feature matrix expansion include
cabin,sets(orsex),age, andSABSP(SibSp).
Hyperparameter Scaling Experiments:
Adjust maximum tree depth (
max_depth) up to (or matchmax_depthdirectly to the total count of selected features).Modify test split proportions (
test_size) to0.3( test set) or0.1( test set).Measure and report the resulting variations in precision and recall.
Academic Guidelines, Collaboration Policies, and Q&A
In-Class Requirements:
For the upcoming Thursday session, students must bring a printed paper copy of their code or have the code readily accessible on their laptops.
Strict AI Policy:
Use of GitHub Copilot, AI generation tools, or automated assistants is strictly prohibited.
Questions & Discussion on Group Collaboration:
Student Prompt: Inquiries regarding working together or asking peers for assistance during code execution.
Policy Resolution: Joint completion of individual laboratory assignments is prohibited, as individual submissions cannot be jointly graded ("give a degree for all of you together"). Collaborative work is reserved exclusively for a dedicated final group project to be assigned later.