Untitled
CS722/822: Intro to Machine Learning
- Instructor: Pratip Rana
- Department: Computer Science
Decision Trees
- Overview: Learn a hierarchy of if/else questions.
- Example: Questions to differentiate four animals: hawk, penguin, dolphin, and bear.
Building a Decision Tree
- Process:
- Identify a sequence of questions (tests) to get to the answer quickly.
- Tests Example: "Is feature π larger than value π?"
- Binary Partitioning:
- Performing any test leads to a binary partition of the training data.
- Tests are recursively performed until the resultant subset of data is pure:
- Pure Definition:
- In classification: Only one target class in the subset.
- In regression: Only one target value in the subset.
Example of Decision Tree Construction
- Visualization: Uses two-moon dataset.
- Depth Levels:
- Depth = 1:
- Condition: X[1] <= 0.0596
- Counts: [50, 50]
- Depth = 2:
- Condition: X[0] <= -0.4177
- Counts: [2, 32]
- Further breakdowns provide counts detailing splits at depths 2 and 9.
Predictions from Decision Trees
- Process:
- Traverse the decision tree from root to leaf node according to feature values of new data point.
- Prediction Methods:
- For classification: Prediction is the majority target class in the leaf node.
- For regression: Prediction is the mean target in the leaf node.
- Import Notes:
- No predictions outside of the range of training data are possible.
Controlling Complexity in Trees
- Problem: Trees with all pure leaves lead to overfitting in models.
- Strategies for Control:
- Pre-pruning:
- Stop early during the creation of the tree.
- Limit the maximum number of leaves.
- Limit the maximum depth of the tree.
- Require a minimum number of points in a node.
- Post-pruning:
- Remove or collapse nodes containing little information.
Decision Tree Implementations in scikit-learn
- Models:
- DecisionTreeRegressor: For regression tasks.
- DecisionTreeClassifier: For classification tasks.
- Features:
- Includes only implementation of pre-pruning.
- Visualization via the
export_graphvis function.
Feature Importance in Decision Trees
- Definition: Measure importance of features with a number between 0 and 1.
- Range: 0 = not used at all; 1 = perfectly predicts targets.
- Feature importances always sum to 1.
- Access via
feature_importances_ of the tree.
- Characteristics:
- Low feature importance does not necessarily imply uninformative.
- Feature importances are always positive.
- Not indicative of how a feature affects the target distributions.
Strengths and Weaknesses of Decision Trees
- Strengths:
- Easily visualized and understood.
- Invariant to data scaling; normalization not needed.
- Capable of capturing nonlinear relationships.
- Weaknesses:
- Prone to overfitting.
- Involves multiple hyperparameters in pre-pruning.
- For regression, cannot predict outside the training set.
Ensemble Learning
- Concept: Combining multiple base learners results in a stronger overall model H(x).
- Intuition:
- Diverse committees and elections improve reliability.
- If model errors are uncorrelated, the variance (Var(h)) reduces when averaged:
Var(h)=MVar(h)β - Requirements:
- Diversity among models (different mistakes).
- An aggregation rule such as averaging or voting.
- Caution: Identical learners provide no improvements.
Bagging and Boosting
- Bagging:
- Trains multiple weak learners in parallel using random subsets of data (bootstrapping).
- Learner performance is uncontrolled; diversity is through chance, not design.
- Boosting:
- Trains weak learners sequentially; each learner focuses on correcting previous errors.
- Learners become complementary.
- Improves accuracy through targeted collaboration.
Random Forest
- Definition: A collection of decision trees designed to counteract overfitting.
- Functionality:
- Classes predicted through majority voting, or the average for regression outcomes.
- Building Process:
- Create m trees (hyperparameter m).
- Introduce randomness:
- Randomly choose data points to build the tree (bootstrapping using N samples).
- Randomly select features for splitting the tree.
- Implementation in scikit-learn:
- RandomForestClassifier for classification.
- RandomForestRegressor for regression.
- Hyperparameters:
n_estimators: number of trees to build.max_features: number of features in the random subset.- Uses a "soft voting" strategy during prediction for classifications.
Gradient Boosted Regression Trees (GBRT)
- Overview:
- Trees are built serially, with each subsequent tree correcting previous mistakes.
- No randomization; incorporates strong pre-pruning by using shallow trees.
- Trees are weak learners; hence, many trees are required to create a robust model.
- Implementation in scikit-learn:
- GradientBoostingClassifier available in the ensemble module.
- Tune hyperparameters like
learning_rate to control complexity and n_estimators for tree count.
Bagging vs. Boosting
- Comparison:
- Training:
- Bagging: Parallel
- Boosting: Sequential
- Sampling:
- Bagging: Random
- Boosting: Bootstrap with weighted preferences to correct past errors.
- Weights:
- Bagging: Equal for all learners
- Boosting: Higher for better learners, leading to a reduction in bias.
- Goals:
- Bagging aims to reduce variance, while Boosting aims to reduce bias.
Practical Considerations in Model Selection
- Tips:
- Initially use Random Forest and then apply Gradient Boosting for additional performance improvements as needed.
Strengths and Weaknesses of Gradient Boosting
- Strengths:
- Invariant to scaling of the data; no normalization is required.
- Effectively captures nonlinear relationships without requiring extensive tuning.
- Weaknesses:
- Cannot predict outside of the training set (regression-oriented).
- Interpretation can be difficult.
- May struggle with high-dimensional, sparse data.
- Sensitive to hyperparameters, necessitating careful tuning.
- Sequential tree building may lead to longer training times.