Adaboost, Gradient, XG boosting
Differences Between Boosting and Bagging
Boosting and bagging are both ensemble learning techniques used to improve the performance of machine learning models. They combine multiple models to produce a stronger, more accurate model. However, they differ significantly in their approach and implementation. Here’s a detailed comparison:
Bagging (Bootstrap Aggregating)
Bagging aims to reduce variance and prevent overfitting by creating multiple versions of a model and averaging their predictions.
Key Characteristics:
Training Method:
Bootstrap Sampling: Creates multiple subsets of the training data by sampling with replacement.
Independent Models: Each model is trained independently on a different bootstrap sample.
Model Combination:
Averaging: For regression, predictions are averaged.
Majority Voting: For classification, predictions are combined using majority voting.
Bias-Variance Tradeoff:
Reduces Variance: Helps reduce the variance of individual models by averaging their predictions.
Examples:
Random Forest: An ensemble of decision trees using bagging.
Boosting
Boosting aims to reduce bias and improve accuracy by combining multiple weak learners, where each subsequent model corrects the errors of the previous ones.
Key Characteristics:
Training Method:
Sequential Learning: Models are trained sequentially, with each model focusing on the errors of the previous ones.
Weighted Data: Data points that were misclassified or predicted poorly by previous models are given more weight.
Model Combination:
Weighted Sum: Predictions from all models are combined using a weighted sum, where more accurate models have higher weights.
Bias-Variance Tradeoff:
Reduces Bias: Focuses on reducing the bias of the model, aiming to improve predictive accuracy.
Examples:
AdaBoost: Adjusts weights of misclassified instances and combines weak learners.
Gradient Boosting: Sequentially fits new models to the residual errors of previous models.
Visual Summary
Here’s a visual summary of the differences:
| Aspect | Bagging | Boosting |
|---|---|---|
| Training Method | Parallel, independent models | Sequential, dependent models |
| Data Sampling | Bootstrap sampling with replacement | Weighted sampling based on previous errors |
| Model Combination | Averaging (regression) or majority voting (classification) | Weighted sum of predictions |
| Goal | Reduce variance, prevent overfitting | Reduce bias, improve accuracy |
| Examples | Random Forest | AdaBoost, Gradient Boosting |
Practical Implementation in Python
Bagging Example (Random Forest):
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
# Load the dataset
iris = load_iris()
X = iris.data
y = iris.target
# Split data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize and train the Random Forest classifier
rf = RandomForestClassifier(n_estimators=100, random_state=42)
rf.fit(X_train, y_train)
# Predict on the test set
y_pred = rf.predict(X_test)
print(f'Random Forest Accuracy: {accuracy_score(y_test, y_pred):.2f}')
Boosting Example (AdaBoost):
from sklearn.ensemble import AdaBoostClassifier
from sklearn.tree import DecisionTreeClassifier
# Initialize base model
base_model = DecisionTreeClassifier(max_depth=1)
# Initialize and train the AdaBoost classifier
adaboost = AdaBoostClassifier(base_estimator=base_model, n_estimators=100, random_state=42)
adaboost.fit(X_train, y_train)
# Predict on the test set
y_pred = adaboost.predict(X_test)
print(f'AdaBoost Accuracy: {accuracy_score(y_test, y_pred):.2f}')
Summary
Bagging: Aims to reduce variance by creating multiple subsets of data and training independent models in parallel.
Boosting: Aims to reduce bias by sequentially training models, with each one correcting the errors of the previous models.
Both techniques enhance model performance, but they do so in fundamentally different ways. Choosing between them depends on the specific needs of your task and the characteristics of your data.
Bagging is one such ensemble model which creates different training subsets from the training data with replacement. Then, an algorithm with the same set of hyperparameters is built on these different subsets of data.
Boosting is another popular approach to ensembling. This technique combines individual models into a strong learner by creating sequential models such that the final model has a higher accuracy than the individual models.
Building Blocks of Boosting
Boosting is a powerful ensemble technique that sequentially combines multiple weak learners to form a strong learner. Here are the fundamental building blocks of boosting:
1. Weak Learners
Definition: Simple models that perform slightly better than random guessing.
Examples: Decision stumps (shallow decision trees with a single split), linear classifiers.
Role: Each weak learner focuses on correcting the errors of the previous learners.
2. Sequential Learning
Training Process: Models are trained one after another in a sequence.
Focus on Errors: Each new model is trained to correct the errors made by the previous model, giving more weight to misclassified instances.
3. Weighted Data
Error Emphasis: Data points that are misclassified by previous models are given higher weights.
Adjusting Weights: The weights are adjusted iteratively so that the new model pays more attention to hard-to-classify instances.
4. Combination of Learners
Aggregating Predictions: The final prediction is made by combining the predictions of all the weak learners.
Weighted Sum: Each model's prediction is weighted by its performance, and the combined prediction is a weighted sum of the individual predictions.
Introduction to AdaBoost
AdaBoost, short for Adaptive Boosting, is an ensemble learning technique that combines multiple weak learners to create a strong classifier. It was introduced by Yoav Freund and Robert Schapire in 1996 and has since become one of the most popular boosting algorithms due to its simplicity and effectiveness.
How AdaBoost Works
Initialization:
Assign equal weights to all instances in the training set.
Training Weak Learners:
For each iteration, train a weak learner on the weighted training data.
Calculate the weighted error of the model.
Update the weights of the instances: Increase the weights of misclassified instances and decrease the weights of correctly classified instances.
Compute the model's contribution (weight) to the final prediction based on its accuracy.
Combining Predictions:
Aggregate the predictions of all the weak learners using their computed weights to form the final prediction.
Practical Example in Python
Here’s an example of how to implement AdaBoost using scikit-learn:
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import AdaBoostClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
# Load the dataset
iris = load_iris()
X = iris.data
y = iris.target
# Split data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize base model
base_model = DecisionTreeClassifier(max_depth=1)
# Initialize and train the AdaBoost classifier
adaboost = AdaBoostClassifier(base_estimator=base_model, n_estimators=100, random_state=42)
adaboost.fit(X_train, y_train)
# Predict on the test set
y_pred = adaboost.predict(X_test)
print(f'AdaBoost Accuracy: {accuracy_score(y_test, y_pred):.2f}')
Advantages of AdaBoost
High Accuracy: Often performs well with a relatively low number of weak learners.
Simplicity: Easy to implement and understand.
Versatility: Can be used with various types of weak learners.
Robustness: Less prone to overfitting compared to other models.
Before starting with a numerical example to understand AdaBoost, let’s see an overview of the steps that need to be taken in this boosting algorithm:
- AdaBoost starts with a uniform distribution of weights over training examples, i.e., it gives equal weights to all its observations. These weights tell the importance of each datapoint being considered.
- We start with a single weak learner to make the initial predictions.
- Once the initial predictions are made, patterns which were not captured by the previous weak learner are taken care of by the next weak learner by giving more weightage to the misclassified datapoints.
- Apart from giving weightage to each observation, the model also gives weightage to each weak learner. More the error in the weak learner, lesser is the weightage given to it. This helps when the ensembled model makes final predictions.
- After getting the two weights for the observations and the individual weak learners, the next weak learner in the sequence trains on the resampled data (data sampled according to the weights) to make the next prediction.
- The model will iteratively continue the steps mentioned above for a pre-specified number of weak learners.
- In the end, you need to take a weighted sum of the predictions from all these weak learners to get an overall strong learner.
- A strong learner is formed by combining multiple weak learners which are trained on the mistakes of the previous model.
To summarise, here are the major takeaways from this video:
In AdaBoost, we start with a base model with equal weights given to every observation. In the next step, the observations which are incorrectly classified will be given a higher weight so that when a new weak learner is trained, it will give more attention to these misclassified observations.
In the end, you get a series of models that have a different say according to the predictions each weak model has made. If the model performs poorly and makes many incorrect predictions, it is given less importance, whereas if the model performs well and makes correct predictions most of the time, it is given more importance in the overall model.
The say/importance each weak learner — in our case the decision tree stump — has in the final classification depends on the total error it made.
α = 0.5 ln( (1 − Total error)/Total error )
The value of the error rate lies between 0 and 1. So, let’s see how alpha and error is related.
- When the base model performs with less error overall, then, as you can see in the plot above, the α is a large positive value, which means that the weak learner will have a high say in the final model.
- If the error is 0.5, it means that it is not sure of the decision, then the α = 0, i.e., the weak learner will have no say or significance in the final model.
- If the model produces large errors (i.e., close to 1), then α is a large negative value, meaning that the predictions it makes are incorrect most of the time. Hence, this weak learner will have a very low say in the final model.
After calculating the say/importance of each weak learner, you must determine the new weights of each observation present in the training data set. Use the following formula to compute the new weight for each observation:
new sample weight for the incorrectly classified observation = original sample weight *
new sample weight for the correctly classified observation = original sample weight *
After calculating, we normalise these values to proceed further using the following formula:
Normalised weights = , where p(xi) is the weight of each observation.
The samples which the previous stump incorrectly classified will be given higher weights and the ones which the previous stump classified correctly will be given lower weights.
NOTE:
1. Whenever we start with a new model all the samples of the dataset need to have equal distribution (1/n) and of the same size.
2. Also, the new learner should focus more on the samples which are incorrectly classified at the previous iteration.
To handle both these bottlenecks, a new dataset will be created by randomly sampling the weighted observations.
We create a new and empty dataset that is the same size as the original one. Then we take the distribution of all the updated weights created by our first model
To fill our new empty dataset, we select numbers between 0 and 1 at random. The position where the random number falls determine which observation we place in our new dataset.
Due to the weights given to each observation, the new data set will have a tendency to contain multiple copies of the observation(s) that were misclassified by the previous tree and may not contain all observations which were correctly classified.
After doing this, the initial weights for each observation will be 1/n, thus we can continue the same process as learnt earlier to build the next weak learner.
This will help the next weak learner give more importance to the incorrectly classified sample so that it can correct the mistake and correctly classify it now. This process will be repeated till a pre-specified number of trees are built, i.e., the ensemble is built.
The AdaBoost model makes predictions by having each tree in the ensemble classify the sample. Then, the trees are split into groups according to their decisions. For each group, the significance of every tree inside the group is added up. The final prediction made by the ensemble as a whole is determined by the sign of the weighted sum.
The final model is a strong learner made by the weighted sum of all the individual weak learners.
Practical advice: Before you apply the AdaBoost algorithm, you should remove the Outliers. Since AdaBoost tends to boost up the probabilities of misclassified points and there is a high chance that outliers will be misclassified, it will keep increasing the probability associated with the outliers and make the progress difficult. Some of the ways to identify outliers are:
- Boxplots
- Cook's distance
- Z-score.
Here is the summary of the AdaBoost algorithm you have studied until now.
- Initialize the probabilities of the distribution as where n is the number of data points
- For t = 0 to T, repeat the following (T is the total number of trees):
- Fit a tree on the training data using the respective probabilities
- Compute
- Compute =
- Update where, =
- Final Model:
You can see here that with each new weak learner, the distribution of the data changes, i.e., the weight given to each observation changes.
Observe the factor:
If there is a misclassification done by the model, then the product of = -1
So, the power of the exponential will be positive (growing exponential weight). This indicates that the weight will increase for all misclassified points.
Otherwise, if it is correctly classified, then a product of = 1.
So, it will have a decaying weight because of the negative term in the power of the exponential term. This indicates that the weight will decrease for all correctly classified points.
The model continues adding weak learners till a pre-set number of weak learners have been added.
Then, make the final prediction by adding up the weighted prediction for every classifier.
Note: Summarizing the notations in the lecture, at an iteration , there is a distribution of the training data on which you can fit a model and then use the results to create a new distribution .
The final model we built is an ensemble of all the individual models with weights
- AdaBoost starts with a uniform distribution of weights over training examples.
- These weights give the importance of the datapoint being considered.
- You will first start with a weak learner h1(x) to create the initial prediction.
- Patterns which are not captured by previous models become the goal for the next model by giving more weightage.
- The next model (weak learner) trains on this resampled data to create the next prediction.
- This process will be repeated till a pre-specified number of trees/models are built.
- In the end, we take a weighted sum of all the weak classifiers to make a strong classifier.
Gradient Boosting
Gradient Boosting is a powerful ensemble technique that combines the strengths of multiple weak learners to create a strong predictive model. It is particularly effective for both regression and classification tasks, often outperforming traditional methods.
Key Concepts of Gradient Boosting
Sequential Learning:
Models are trained sequentially, with each new model improving upon the errors of the previous ones.
Residuals:
Each model tries to correct the residual errors (differences between actual and predicted values) of the combined previous models.
Gradient Descent:
The algorithm uses gradient descent to minimize a loss function, guiding the new model to reduce the residuals.
Weighted Sum:
The final model prediction is a weighted sum of the predictions from all the individual models.
How Gradient Boosting Works
Initialization:
Start with an initial prediction, often the mean of the target variable for regression or a constant probability for classification.
Sequential Training:
Train a new model on the residuals of the current combined model.
Update the combined model by adding the new model's predictions, scaled by a learning rate.
Loss Function:
Use a loss function (e.g., mean squared error for regression, log loss for classification) to measure the model's performance.
Minimize this loss function using gradient descent.
Practical Example in Python
Here’s how to implement Gradient Boosting using scikit-learn:
from sklearn.datasets import load_iris, load_boston
from sklearn.model_selection import train_test_split
from sklearn.ensemble import GradientBoostingClassifier, GradientBoostingRegressor
from sklearn.metrics import accuracy_score, mean_squared_error
# Classification Example
iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize and train the Gradient Boosting classifier
gb_clf = GradientBoostingClassifier(n_estimators=100, learning_rate=0.1, random_state=42)
gb_clf.fit(X_train, y_train)
# Predict and evaluate
y_pred_clf = gb_clf.predict(X_test)
print(f'Gradient Boosting Classifier Accuracy: {accuracy_score(y_test, y_pred_clf):.2f}')
# Regression Example
boston = load_boston()
X, y = boston.data, boston.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize and train the Gradient Boosting regressor
gb_reg = GradientBoostingRegressor(n_estimators=100, learning_rate=0.1, random_state=42)
gb_reg.fit(X_train, y_train)
# Predict and evaluate
y_pred_reg = gb_reg.predict(X_test)
print(f'Gradient Boosting Regressor MSE: {mean_squared_error(y_test, y_pred_reg):.2f}')
Advantages of Gradient Boosting
High Accuracy:
Often achieves high predictive accuracy by focusing on reducing residual errors.
Flexibility:
Can handle various types of data and loss functions, making it versatile for different applications.
Feature Importance:
Provides insights into which features are most important for predictions.
Control Overfitting:
Parameters like
n_estimators,learning_rate, andmax_depthcan be tuned to control overfitting and improve model performance.
To summarise, here are the broader points on how a GBM learns:
- Build the first weak learner using a sample from the training data; you can consider a decision tree as the weak learner or the base model. It may not necessarily be a stump, can grow a bigger tree but will still be weak, i.e., still not be fully grown.
- Then, predictions are made on the training data using the decision tree which was just built.
- The negative gradient, in our case the residuals, are computed and these residuals are the new response or target values for the next weak learner.
- A new weak learner is built with the residuals as the target values and a sample of observations from the original training data.
- Add the predictions obtained from the current weak learner to the predictions obtained from all the previous weak learners. The predictions obtained at each step are multiplied by the learning rate so that no single model makes a huge contribution to the ensemble thereby avoiding overfitting. Essentially, with the addition of each weak learner, the model takes a very small step in the right direction.
- The next weak learner fits on the residuals obtained till now and these steps are repeated, either for a pre-specified number of weak learners or if the model starts overfitting, i.e., it starts to capture the niche patterns of the training data.
- GBM makes the final prediction by simply adding up the predictions from all the weak learners (multiplied by the learning rate).
the broader points on how a GBM learns for a classification problem:
- Build the first weak learner using a sample from the training data. The initial prediction for every individual sample will be log(odds)(where odds = number of positive samples/number of negative samples).
- Convert the result obtained from log(odds) to a probabilty value by using the sigmoid function to transform it.
- Once the predictions are made, calculate the residuals, which will be the new response or target values for the next weak learner.
- A new weak learner is built with the residuals as the target values and a sample of observations from the original training data.
- Calculate the output of each leaf of the current weak learner to find the new predictions.

- The final prediction is adding the current predictions to the predictions obtained from all the previous weak learners. The predictions obtained at each step are multiplied by the learning rate so that no single model makes a huge contribution to the ensemble thereby avoiding overfitting. Essentially, with the addition of each weak learner, the model takes a very small step in the right direction.
- The next weak learner fits on the residuals obtained till now and these steps are repeated, either for a prespecified number of weak learners or if the model starts overfitting, i.e., it starts to capture the niche patterns of the training data.
- GBM makes the final prediction by simply adding up the predictions from all the weak learners (multiplied by the learning rate).
XGBoost (Extreme Gradient Boosting)
XGBoost is a highly efficient and scalable implementation of gradient boosting that has become one of the most popular machine learning algorithms due to its performance and speed. It was developed by Tianqi Chen and is known for winning numerous machine learning competitions.
Key Features of XGBoost
Speed and Performance:
Optimized: Uses advanced optimization techniques to make the training process faster and more efficient.
Parallelization: Supports parallel and distributed computing, allowing it to scale to large datasets.
Regularization:
L1 and L2 Regularization: Helps prevent overfitting by adding penalties to the model complexity.
Handling Missing Values:
Sparsity-Aware: Can handle sparse data and missing values by learning the best direction to take when it encounters a missing value.
Tree Pruning:
Max Depth: Uses a depth-wise approach to prune trees, preventing overfitting and enhancing model generalization.
Cross-Validation:
Built-In: Supports k-fold cross-validation, making it easier to evaluate the model's performance during training.
How XGBoost Works
XGBoost builds upon the principles of gradient boosting by introducing additional enhancements that improve speed, performance, and accuracy:
Initialization:
Start with an initial prediction, often the mean of the target variable for regression or a constant probability for classification.
Sequential Training:
Fit a new model to the residuals (errors) of the current combined model.
Update the combined model by adding the new model's predictions, scaled by a learning rate.
Regularization:
Apply L1 (Lasso) and L2 (Ridge) regularization to the model to prevent overfitting and improve generalization.
Tree Pruning:
Prune trees during training to control the maximum depth and prevent overfitting.
Practical Example in Python
Here’s how to implement XGBoost using the xgboost library in Python:
import xgboost as xgb
from sklearn.datasets import load_iris, load_boston
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, mean_squared_error
# Classification Example
iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize and train the XGBoost classifier
xgb_clf = xgb.XGBClassifier(n_estimators=100, learning_rate=0.1, max_depth=3, random_state=42)
xgb_clf.fit(X_train, y_train)
# Predict and evaluate
y_pred_clf = xgb_clf.predict(X_test)
print(f'XGBoost Classifier Accuracy: {accuracy_score(y_test, y_pred_clf):.2f}')
# Regression Example
boston = load_boston()
X, y = boston.data, boston.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize and train the XGBoost regressor
xgb_reg = xgb.XGBRegressor(n_estimators=100, learning_rate=0.1, max_depth=3, random_state=42)
xgb_reg.fit(X_train, y_train)
# Predict and evaluate
y_pred_reg = xgb_reg.predict(X_test)
print(f'XGBoost Regressor MSE: {mean_squared_error(y_test, y_pred_reg):.2f}')
Advantages of XGBoost
High Performance:
Achieves high predictive accuracy and efficiency, making it suitable for a wide range of applications.
Scalability:
Can handle large datasets and supports parallel and distributed computing.
Flexibility:
Works well for both classification and regression tasks.
Offers various hyperparameters to fine-tune the model.
Robustness:
Includes regularization techniques to prevent overfitting and handle missing values.
- AdaBoost is an iterative way of adding weak learners to form the final model. For this, each model is trained to correct the errors made by the previous one. The sequential model does this by adding more weight to cases with incorrect predictions. Using this approach, the ensemble model will correct itself while learning by focusing on cases/datapoints that are hard to predict correctly.
- Next, let’s discuss gradient boosting. You learnt about gradient descent in the previous module. The same principle applies here as well, where the newly added trees are trained to reduce the errors (loss function) of earlier models. So, in gradient boosting, you can optimise the performance of the boosted model by bringing down the loss one small step at a time.
- XGBoost is an extended version of gradient boosting, which uses more accurate approximations to tune the model and find the best fit.
Why is XGBoost so good?
Parallel Computing: When you run XGBoost, by default it would use all the cores of your laptop/machine enabling its capacity to do parallel computation.
Tree pruning using depth first approach: XGBoost uses ‘max_depth’ parameter as specified instead of criterion first, and starts pruning trees backward.
Missing Values: XGBoost is designed to handle missing values internally. The missing values are treated in such a manner that any trend in missing values (if it exists) is captured by the model.
Regularization: The biggest advantage of XGBoost is that it uses regularisation in its objective function which helps to controls the overfitting and simplicity of the model, leading to better performance.
To summarise, here are the broader points on how an XGBoost learns:
- Build the first weak learner which performs the initial prediction on the given dataset. The initial prediction will be 0.5 for both regression & classification tasks.
- The residuals are computed and they will be the new response or target values for the next weak learner.
- A new weak learner is built with the residuals as the target values and a sample of observations from the original training data.
- The new weak learner is created by calculating the similarity score and gain for all the constructed trees. The final tree is the one which has the optimal split i.e highest gain. The various trees are constructed by splitting the data into two partitions of various possible splits or thresholds. This threshold for root is calculated by taking an average of two close points among the split and the residuals go to the respective leaf.
Gain = Similarity score(Left leaf) + Similarity score(right leaf) – Similarity score(root node)
Using the tree with the highest gain, each node will split into further sub-nodes.
The nodes will stop splitting when it has only 1 residual left or based on the user-defined min number of sample data in each node, max iterations or tree depth. Tree pruning prevents overfitting with the help of threshold parameter γ. A branch containing the terminal node is pruned when the gain < γ (or gain-γ = negative).- Once the tree is built, calculate the output of each leaf to find the new prediction.
![]()
- Add the predictions obtained from the current weak learner to the predictions obtained from all the previous weak learners. The predictions obtained at each step are multiplied by the learning rate so that no single model makes a huge contribution to the ensemble thereby avoiding overfitting. Essentially, with the addition of each weak learner, the model takes a very small step in the right direction.
- The next weak learner fits on the residuals obtained till now and these steps are repeated, either for a prespecified number of weak learners or if the model starts overfitting, i.e., it starts to capture the niche patterns of the training data.
Hyperparameters in Gradient Boosting and XGBoost
Tuning hyperparameters is crucial for optimizing the performance of machine learning models, especially in gradient boosting and XGBoost. Here, we'll dive into three key hyperparameters: Learning Rate, Number of Trees, and Subsampling.
1. Learning Rate (η)
Definition: The learning rate, is also known as shrinkage. learning rate determines the step size at each iteration while moving toward a minimum of the loss function. It controls how much the model is adjusted with respect to the loss gradient.
Impact:
High Learning Rate: Faster convergence, but risks overshooting the optimal solution and may lead to suboptimal models.
Low Learning Rate: More precise convergence, but requires more iterations and increases computational cost.
Example in XGBoost:
import xgboost as xgb
xgb_model = xgb.XGBClassifier(learning_rate=0.1, n_estimators=100)
2. Number of Trees (n_estimators)
Definition: The number of trees in the ensemble. In gradient boosting, this represents the number of boosting rounds.
Impact:
More Trees: Potentially higher accuracy, but with a risk of overfitting and increased computation time.
Fewer Trees: Lower risk of overfitting, but may underfit if too few trees are used.
Example in XGBoost:
xgb_model = xgb.XGBClassifier(n_estimators=100, learning_rate=0.1)
3. Subsampling
Definition: The subsample ratio of the training instances. This parameter specifies the fraction of the training data to be used for training each tree.
Impact:
Subsampling: Reduces overfitting by introducing randomness. It can make the model more robust by preventing it from relying too heavily on any particular subset of the data.
Example in XGBoost:
xgb_model = xgb.XGBClassifier(subsample=0.8, n_estimators=100, learning_rate=0.1)
4. γ ,Gamma is a parameter used to control the pruning of the tree. A node is split only when the resulting split gives a positive reduction in the loss function. Gamma specifies the minimum loss reduction required to make a split and makes the algorithm conservative. The values can vary depending on the loss function and should be tuned.
Key Concepts and Takeaways
1. Ensemble Methods
Definition: Techniques that combine multiple models to improve overall performance and robustness.
Types:
Bagging: Reduces variance by averaging multiple models trained on different subsets of the data (e.g., Random Forest).
Boosting: Reduces bias by sequentially training models to correct errors of previous models (e.g., AdaBoost, Gradient Boosting).
2. Random Forest
Concept: An ensemble of decision trees using bagging.
Advantages: High accuracy, robustness against overfitting, feature importance insights, and ability to handle missing values.
Key Hyperparameters:
n_estimators,max_depth,min_samples_split,min_samples_leaf,max_features,oob_score.
3. AdaBoost
Concept: A boosting technique that combines multiple weak learners to create a strong classifier.
Advantages: High accuracy, simplicity, versatility, and robustness.
Process: Assign equal weights, train weak learners sequentially, update weights based on errors, aggregate predictions.
4. Gradient Boosting
Concept: A boosting technique that minimizes residual errors using gradient descent.
Advantages: High accuracy, flexibility, feature importance insights, control over overfitting.
Process: Start with initial prediction, train new models on residuals, update model by adding new predictions, minimize loss function.
5. XGBoost
Concept: An efficient and scalable implementation of gradient boosting.
Advantages: High performance, scalability, flexibility, robustness, ability to handle large datasets.
Key Hyperparameters:
learning_rate,n_estimators,subsample,max_depth,colsample_bytree.
6. Hyperparameters
Learning Rate (η): Controls the step size of model adjustments.
Number of Trees (n_estimators): Controls the number of boosting rounds.
Subsampling: Fraction of training data used to train each tree.
Comments
Post a Comment