Ở phần trước, chúng ta đã làm quen với kỹ thuật Bagging. Phần này sẽ giới thiệu về Boosting, cũng giống như Bagging, Boosting là một kỹ thuật ensemble learning.
Nhắc lại về Ensemble learning: ensemble learning là kỹ thuật kết hợp nhiều mô hình khác nhau tạo thành một siêu mô hình có hiệu suất cao hơn từng mô hình đơn lẻ. Trong thực tế, khi giải quyết những vấn đề phức tạp thì ta thường tham khảo ý kiến của nhiều chuyên gia để đưa ra kết luận cuối cùng. Ensemble learning cũng hoạt động dựa trên ý tưởng đó.
Hiểu rõ hơn về Boosting thông qua Bagging:
Mô hình hóa Boosting:
Xuất phát từ ý tưởng của Boosting, tuy nhiên Adaboost khác với Boosting ở chổ nó sử dụng toàn bộ dữ liệu để huấn luyện từng mô hình con với trọng số được phân phối lại sau mỗi lần huấn luyện sao cho mô hình sau quan tâm nhiều hơn đến những lỗi sai của mô hình trước.
![]() |
|---|
| Mô tả thuật toán |
Giả định rằng thuật toán phân loại 2 lớp có giá trị 1 và -1:
![]() |
|---|
| Tổng lỗi - a |
So sánh sự khác nhau giữa cây quyết định với Adaboost 300 estimators:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import AdaBoostRegressor
rng = np.random.RandomState(1)
# Tạo tập dữ liệu X, y
X = np.linspace(0, 6, 100)[:, np.newaxis]
y = np.sin(X).ravel() + np.sin(6 * X).ravel() + rng.normal(0, 0.1, X.shape[0])
regr_1 = DecisionTreeRegressor(max_depth=4)
regr_2 = AdaBoostRegressor(DecisionTreeRegressor(max_depth=4),
n_estimators=300, random_state=rng)
regr_1.fit(X, y)
regr_2.fit(X, y)
y_1 = regr_1.predict(X)
y_2 = regr_2.predict(X)
plt.figure()
plt.scatter(X, y, c="k", label="training samples")
plt.plot(X, y_1, c="g", label="n_estimators=1", linewidth=2)
plt.plot(X, y_2, c="r", label="n_estimators=300", linewidth=2)
plt.xlabel("data")
plt.ylabel("target")
plt.title("Boosted Decision Tree Regression")
plt.legend()plt.figure()
plt.scatter(X, y, c="k", label="training samples")
plt.plot(X, y_1, c="g", label="n_estimators=1", linewidth=2)
plt.plot(X, y_2, c="r", label="n_estimators=300", linewidth=2)
plt.xlabel("data")
plt.ylabel("target")
plt.title("Boosted Decision Tree Regression")
plt.legend()
plt.show()
plt.show()