Bootstrap Aggregating

IT 위키
Prairie (토론 | 기여)님의 2024년 12월 1일 (일) 03:53 판 (Created page with "'''Bootstrap Aggregating''', commonly known as '''Bagging''', is an ensemble learning method designed to improve the stability and accuracy of machine learning models. It works by combining the predictions of multiple base models, each trained on different subsets of the data created through the bootstrap sampling technique. Bagging reduces variance, mitigates overfitting, and improves model robustness. == Overview == Bootstrap aggregating is built on two fundamental co...")
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

Bootstrap Aggregating, commonly known as Bagging, is an ensemble learning method designed to improve the stability and accuracy of machine learning models. It works by combining the predictions of multiple base models, each trained on different subsets of the data created through the bootstrap sampling technique. Bagging reduces variance, mitigates overfitting, and improves model robustness.

Overview

Bootstrap aggregating is built on two fundamental concepts:

  • Bootstrap Sampling:
    • A statistical technique where random samples are drawn with replacement from the original dataset to create multiple subsets (bootstrap samples). Each sample has the same size as the original dataset but may contain duplicate entries.
  • Aggregation:
    • The predictions from each model trained on different bootstrap samples are combined to produce the final output. For classification, majority voting is used, and for regression, averaging is applied.

Key Steps in Bagging

  1. Generate multiple bootstrap samples from the original dataset.
  2. Train a base model (e.g., decision trees) on each bootstrap sample.
  3. Combine the predictions from all base models:
    • For classification tasks, use majority voting.
    • For regression tasks, calculate the average of all predictions.

Advantages of Bootstrap Aggregating

  • Reduces Variance: Combines multiple models to stabilize predictions, making the ensemble less sensitive to noise.
  • Mitigates Overfitting: Helps prevent overfitting by training models on different subsets of data, ensuring diversity in predictions.
  • Improves Robustness: Reduces the risk of over-reliance on any single feature or observation.
  • Parallelizable: Training individual models on bootstrap samples can be done independently, improving computational efficiency.

Limitations of Bagging

  • Does Not Reduce Bias: If the base model has high bias, bagging will not significantly improve performance.
  • Computational Cost: Training multiple models can be resource-intensive, especially for large datasets or complex models.
  • Performance Depends on Base Model: Bagging works best with high-variance models, such as decision trees, but may not benefit low-variance models.

Applications

Bagging is particularly effective for high-variance models and is used in various fields:

  • Classification: Email spam detection, fraud detection, and medical diagnosis.
  • Regression: Predicting housing prices, stock market trends, and weather forecasting.
  • Anomaly Detection: Identifying outliers in industrial or financial datasets.

Bagging vs. Boosting

Bootstrap Aggregating and Boosting are both ensemble learning techniques but differ fundamentally:

  • Bagging:
    • Focuses on reducing variance.
    • Models are trained independently on bootstrap samples.
    • Predictions are aggregated using averaging (regression) or voting (classification).
  • Boosting:
    • Focuses on reducing bias.
    • Models are trained sequentially, with each model correcting the errors of the previous one.
    • Predictions are aggregated using weighted combinations.

Random Forest: An Extension of Bagging

Random Forest is a specific implementation of bagging where decision trees are used as the base models. It introduces additional randomness by selecting a random subset of features at each split, further decorrelating the individual trees and improving ensemble performance.

Python Code Example

from sklearn.ensemble import BaggingRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split

# Generate example dataset
X, y = make_regression(n_samples=1000, n_features=10, noise=0.1, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# Create a Bagging Regressor
bagging = BaggingRegressor(
    base_estimator=DecisionTreeRegressor(),
    n_estimators=10,
    random_state=42
)

# Train the model
bagging.fit(X_train, y_train)

# Evaluate the model
score = bagging.score(X_test, y_test)
print(f"R^2 Score: {score:.2f}")

See Also