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 studies>5\text{studies} > 5 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 income is not greater than 50,00050,000 (i.e. income≤50,000\text{income} \le 50,000), the tree evaluates secondary features such as website visits.

Feature Engineering and Scaling Characteristics

  • Input Feature Arrays: Decision trees can incorporate heterogeneous collections of features, including income, previous purchase status, and website visits to 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., 5050 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 = 5 or max_depth = 10 during model initialization.

    • Example Depth Constraint: Restricting the architecture to exactly 33 decision nodes (depth=3\text{depth} = 3).

Model Implementation and Data Preprocessing Pipeline

  • Environment & Preprocessing Rules:

    • Library requirements include pandas for data manipulation.

    • Missing dataset values are imputed by replacing them with the attribute mean.

  • Data Partitioning:

    • Baseline data division uses an 80/2080/20 train-test split (80%80\% training set, 20%20\% testing set).

  • Classifier Setup & Passenger Prediction Target:

    • Model initialization uses a decision tree classifier (DecisionTreeClassifier) configured with max_depth = 3.

    • Objective: Predict binary survival outcomes on passenger data (survived vs. not survived).

    • Binary Encoding: Output label 11 represents passenger survival (survived), whereas 00 represents non-survival.

Model Evaluation, Precision, and Recall

  • Baseline Classification Accuracy:

    • The decision tree model with max_depth = 3 achieves a baseline classification accuracy of 70%70\% (0.700.70).

  • 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 (XX) Expansion:

    • Students are directed to expand input feature vector XX by selecting 1010 features out of 1212 total available columns, while keeping target vector yy fixed.

    • Candidate features for feature matrix expansion include cabin, sets (or sex), age, and SABSP (SibSp).

  • Hyperparameter Scaling Experiments:

    • Adjust maximum tree depth (max_depth) up to 1010 (or match max_depth directly to the total count of selected features).

    • Modify test split proportions (test_size) to 0.3 (30%30\% test set) or 0.1 (10%10\% 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.