Stochastic Gradient Boosting (SGB)

Machine Learning with Tree-Based Models in Python

Elie Kawerk

Data Scientist

Gradient Boosting: ข้อเสีย

  • GB ใช้กระบวนการค้นหาแบบครอบคลุมทุกกรณี

  • CART แต่ละต้นถูกฝึกเพื่อหาจุดแบ่งและฟีเจอร์ที่ดีที่สุด

  • อาจทำให้ CART หลายต้นใช้จุดแบ่งและฟีเจอร์เดิมซ้ำกัน

Machine Learning with Tree-Based Models in Python

Stochastic Gradient Boosting

  • แต่ละต้นไม้ถูกฝึกบนชุดย่อยของข้อมูลฝึกที่สุ่มมา

  • ตัวอย่างที่ถูกสุ่ม (40%–80% ของชุดฝึก) ถูกสุ่มแบบไม่ใส่คืน

  • ฟีเจอร์ถูกสุ่ม (แบบไม่ใส่คืน) เมื่อเลือกจุดแบ่ง

  • ผลลัพธ์: เพิ่มความหลากหลายของ ensemble

  • ผล: เพิ่ม variance ให้กับ ensemble ของต้นไม้

Machine Learning with Tree-Based Models in Python

Stochastic Gradient Boosting: การฝึกโมเดล

SGB

Machine Learning with Tree-Based Models in Python

Stochastic Gradient Boosting ใน sklearn (ชุดข้อมูล auto)

# Import models and utility functions
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error as MSE

# Set seed for reproducibility
SEED = 1

# Split dataset into 70% train and 30% test
X_train, X_test, y_train, y_test = train_test_split(X,y, 
                                                    test_size=0.3, 
                                                    random_state=SEED)
Machine Learning with Tree-Based Models in Python

Stochastic Gradient Boosting ใน sklearn (ชุดข้อมูล auto)

# Instantiate a stochastic GradientBoostingRegressor 'sgbt'
sgbt = GradientBoostingRegressor(max_depth=1, 
                                 subsample=0.8,
                                 max_features=0.2,
                                 n_estimators=300,             
                                 random_state=SEED)

# Fit 'sgbt' to the training set sgbt.fit(X_train, y_train) # Predict the test set labels y_pred = sgbt.predict(X_test)
Machine Learning with Tree-Based Models in Python

Stochastic Gradient Boosting ใน sklearn (ชุดข้อมูล auto)

# Evaluate test set RMSE 'rmse_test'
rmse_test = MSE(y_test, y_pred)**(1/2)

# Print 'rmse_test'
print('Test set RMSE: {:.2f}'.format(rmse_test))
Test set RMSE: 3.95
Machine Learning with Tree-Based Models in Python

มาฝึกกันเถอะ!

Machine Learning with Tree-Based Models in Python

Preparing Video For Download...