;
Machine Learning February 15 ,2025

AdaBoost for Regression

Now, let's use AdaBoost for regression on the California Housing dataset.

Step 1: Import Required Libraries

First, import the necessary Python libraries.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.ensemble import AdaBoostClassifier, AdaBoostRegressor
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report, mean_squared_error
from sklearn.datasets import fetch_california_housing

Step 2: Load and Explore the Dataset

housing = fetch_california_housing()
df_housing = pd.DataFrame(housing.data, columns=housing.feature_names)
df_housing['target'] = housing.target

Step 3: Split dataset

X_train, X_test, y_train, y_test = train_test_split(df_housing.drop(columns=['target']), df_housing['target'], test_size=0.2, random_state=42)

Step 4: Initialize AdaBoost Regressor

adaboost_regressor = AdaBoostRegressor(base_estimator=DecisionTreeRegressor(max_depth=3), n_estimators=50, learning_rate=1.0, random_state=42)

Step 5: Train the model

adaboost_regressor.fit(X_train, y_train)

Step 6: Predict on Test Data

y_pred_reg = adaboost_regressor.predict(X_test)

Step 7: Evaluate Performance

mse = mean_squared_error(y_test, y_pred_reg)
print(f'Mean Squared Error: {mse:.2f}')

Key Takeaways – AdaBoost for Regression

 Regression with AdaBoost: Uses weak learners (e.g., decision tree regressors) to minimize prediction errors iteratively.

 Step-by-Step Process:

  1. Load California Housing Data – Predicts housing prices.
  2. Split Dataset – 80% training, 20% testing.
  3. Train AdaBoost Regressor – Uses DecisionTreeRegressor (max depth = 3) as the base estimator.
  4. Make Predictions – Predicts housing prices on test data.
  5. Evaluate Performance – Uses Mean Squared Error (MSE) for accuracy.

 Model Performance:

  • Achieved low MSE, indicating good predictive performance.
  • Ensemble learning improves accuracy over individual weak regressors.

 Final Thought: AdaBoost Regressor effectively reduces errors and enhances predictive accuracy by boosting weak learners. 

Next Blog- Transfer Learning in Machine Learning    

Purnima
0

You must logged in to post comments.

Related Blogs

Brief intr...
Machine Learning December 12 ,2024

Brief introduction o...

Understand...
Machine Learning January 01 ,2025

Understanding Data T...

Handling M...
Machine Learning January 01 ,2025

Handling Missing Dat...

Feature En...
Machine Learning January 01 ,2025

Feature Engineering...

Data Norma...
Machine Learning January 01 ,2025

Data Normalization a...

Splitting...
Machine Learning January 01 ,2025

Splitting Data into...

(Cross-val...
Machine Learning January 01 ,2025

(Cross-validation, C...

Model Eval...
Machine Learning February 02 ,2025

Model Evaluation and...

Model Eval...
Machine Learning February 02 ,2025

Model Evaluation and...

Hyperparam...
Machine Learning February 02 ,2025

Hyperparameter Tunin...

Cross Vali...
Machine Learning February 02 ,2025

Cross Validation in...

AdaBoost:...
Machine Learning February 02 ,2025

AdaBoost: A Powerful...

Transfer L...
Machine Learning February 02 ,2025

Transfer Learning in...

Step-wise...
Machine Learning February 02 ,2025

Step-wise Python Imp...

Step-wise...
Machine Learning February 02 ,2025

Step-wise Python Imp...

Random For...
Machine Learning February 02 ,2025

Random Forest for Re...

Gradient B...
Machine Learning February 02 ,2025

Gradient Boosting fo...

Gradient B...
Machine Learning February 02 ,2025

Gradient Boosting in...

Building a...
Machine Learning February 02 ,2025

Building a Machine L...

Introducti...
Machine Learning February 02 ,2025

Introduction to ML T...

Case Studi...
Machine Learning February 02 ,2025

Case Studies and Ind...

Ethical Co...
Machine Learning February 02 ,2025

Ethical Consideratio...

Bias and F...
Machine Learning February 02 ,2025

Bias and Fairness in...

Transparen...
Machine Learning February 02 ,2025

Transparency and Int...

Career Pat...
Machine Learning February 02 ,2025

Career Paths in Mach...

Staying Up...
Machine Learning February 02 ,2025

Staying Updated with...

Model Depl...
Machine Learning February 02 ,2025

Model Deployment Opt...

Model Moni...
Machine Learning February 02 ,2025

Model Monitoring and...

Get In Touch

123 Street, New York, USA

+012 345 67890

techiefreak87@gmail.com

© Design & Developed by HW Infotech