Fundamental of tree, Random Forest, Gradient Boosting Tree & XGBoost, and so forth.
Earlier:
ในตอนที่แล้วเราได้พูดถึง Determination Tree ปกติไป คราวนี้เราจะมาพูดถึง Determination Tree ที่ถูกพัฒนาเพื่อแก้ไขปัญหาบางอย่าง
Determination Tree มีความ unstable สูงมาก ๆ การเปลี่ยนแปลงแค่นิดเดียว หรือเพียงแค่ข้อมูลเดียวเหมือนดังรูป อาจทำให้เราได้ Tree ที่มี construction เปลี่ยนไปโดยสิ้นเชิง
เราจึงจะแก้ไขปัญหานี้โดยการใช้ method — ensemble mannequin หรือ mannequin ที่เป็น mixture ของ mannequin หลาย ๆ อัน ซึ่งก็มีหลายวิธี เช่น
- Bagging ซึ่งเป็นการ practice mannequin หลาย ๆ ตัวแยกกันแบบ parallel แล้วเอาผลมา mix
- Boosting ซึ่งเป็นการ practice mannequin หลาย ๆ ตัวต่อกัน แบบ sequentially แล้วให้ mannequin ตัวหลังมาแก้ error ของ mannequin ตัวก่อนหน้า
กลายเป็น mannequin ที่ถูกพัฒนาต่อมา ไม่ว่าจะเป็น
ปัจจุบันไม่ค่อยนิยมแล้ว เพราะคนไปใช้ Random Forest ซึ่งเป็นเวอร์ชันที่ถูกพัฒนาจาก Bagging
Take Majority Vote(Common) of Prediction
enhanced Bagging, Bagging + random characteristic choice for every cut up. Enhance robustness and scale back overfitting
Many timber → Forest!
Forest takes bootstrap samples of the rows in coaching information (sampling with substitute; after chosen we put it again to the pool, so it may be chosen once more) then at every step, a set of variables (columns) is sampled.
โดยค่าของ max options หรือ max samples รวมถึง จำนวนต้นไม้ใน RF เราสามารถกำหนดได้
Execs: คำนวณง่าย คำนวณได้แบบ parallel เป็น robust baseline
Cons: ด้วยความที่ mannequin advanced ขึ้น เราอาจจะตีความผลจากต้นไม้ได้ยาก เพราะผลมาจากต้นไม้หลายต้นเฉลี่ยกัน
ปัจจุบันไม่ค่อยนิยมแล้ว เพราะคนไปใช้ Gradient Boosting ซึ่งเป็นเวอร์ชันที่ถูกพัฒนาจาก Boosting
- Focuses on re-weighting misclassified samples.
- Every weak learner is educated sequentially, with extra weight given to incorrectly categorised factors.
- The ultimate mannequin is a weighted sum of weak learners. Fashions that carry out higher get greater weight.
สังเกตได้ว่ากระบวนการแบบนี้จะทำให้ Outlier มีผลกับ mannequin มาก ๆ เพราะจะได้ weight ที่เพิ่มขึ้น
ใช้หลักการ Boosting เหมือนกัน แต่เป้าหมายของต้นไม้ตัวถัดไปคือ การทำนาย Error ไม่ใช่ Goal!
prediction outcome = summation of all timber (not common as RF any extra)
Preliminary Prediction
ค่า Preliminary Prediction มักจะเป็นค่าจากโมเดลง่าย ๆ เช่น:
- ค่าเฉลี่ย (Imply) ของ yy สำหรับปัญหาการพยากรณ์แบบ Regression
- ค่า Log-Odds ของ Class Prior สำหรับ Classification
- ตัวอย่างเช่น ในปัญหาการทำนายราคา ถ้าค่าเฉลี่ยของราคาบ้านคือ 3 ล้าน บาท ค่าเริ่มต้นของโมเดลก็จะเป็น 3 ล้านบาททุกตัวอย่าง
Prediction
- Residuals/Error เป็นค่าที่โมเดลถัดไปจะเรียนรู้
- เช่นค่า +0.95 หรือ -0.44 ในรูป
- เมื่อโมเดลแรกทำนายออกมา ค่า Residual (ri = yi — f0(xi)) จะกลายเป็น goal ใหม่ ที่โมเดลถัดไปต้องเรียนรู้
- ตัวอย่าง:
- ถ้าเราทำนายราคาบ้านได้ 2.5 ล้าน แต่ความจริงคือ 3 ล้าน, Residual คือ +0.5 ล้าน
- โมเดลต้นไม้ต้นต่อไปจะพยายามพยากรณ์ +0.5 ล้าน (ค่าความผิดพลาดที่เหลืออยู่)
การใช้ Gradient Descent Studying Fee (η) เพื่อป้องกัน Overfitting
- การเพิ่มผลรวมของต้นไม้แต่ละต้นไม่ได้เกิดขึ้นแบบ 100% แต่ถูกปรับด้วยค่าที่เรียกว่า Studying Fee (η) ของ GD
- ค่า η ควบคุมว่าโมเดลต้นไม้ใหม่จะมีอิทธิพลต่อผลลัพธ์สุดท้ายแค่ไหน
- ค่า η ต่ำ (เช่น 0.1) → โมเดลเรียนช้าลง แต่ลด Overfitting
- ค่า η สูง (เช่น 1.0) → โมเดลอัปเดตเร็วขึ้น แต่เสี่ยง Overfitting
Mannequin สุดท้ายเป็นการรวมค่าทั้งหมด (Ensemble Mannequin)
- ผลลัพธ์สุดท้ายไม่ได้มาจากต้นไม้ต้นเดียว แต่เป็น การรวมกันของต้นไม้หลายต้น
- สมการของโมเดลสุดท้ายคือ
- ซึ่งหมายความว่าแต่ละต้นไม้ช่วยกันลดข้อผิดพลาดทีละน้อย ทำให้ผลลัพธ์สุดท้ายแม่นยำขึ้น
เมื่อเราได้ Error แล้ว สังเกตได้ว่า Error แต่ละค่าจะมีค่า weight ที่คูณอยู่ ซึ่งนั่นคือการที่เราจะหา weight ที่ดีที่สุดโดยการใช้ GD Gradient Descent
“Optimize weight of leaf nodes by gradient descent Authentic Tree”
ทำให้บน mannequin สามารถปรับ studying charge สำหรับ GD ได้ด้วยนั่นเอง
Mannequin ที่ให้ผลใกล้เคียงกับ XGBoost แต่เร็วกว่ามาก
เป็นการปรับปรุง GBM โดยเพิ่ม
- Regularization (มี L1 (Lasso) และ L2 (Ridge) ทำให้ลด Overfitting ได้ดีขึ้น)
- Parallelization มีการคำนวณแบบ Parallel และ Optimized Reminiscence Utilization
- Pruning ใช้วิธี “Loss-based Pruning”
- จัดการ Lacking Values ได้อัตโนมัติ และอื่น ๆ
รวมถึงหนึ่งใน key สำคัญคือการใช้ Approximate Tree Studying
Approximate Tree Studying
ปัญหาของ Gradient Boosting ปกติคือ การแบ่งโหนด (Splitting) ของต้นไม้ต้อง Kind ค่า Characteristic ทุกครั้ง → ทำให้ใช้เวลานานมาก ส่งผลให้
- การหาจุดแบ่ง (Finest Break up) เป็นกระบวนการที่มีค่าใช้จ่ายสูง (Computational Value สูง)
XGBoost แก้ปัญหานี้ด้วย Approximate Splitting
- แทนที่จะ Kind ทุกค่า ในแต่ละรอบ XGBoost ใช้วิธี Approximate Algorithm ที่เป็น Grasping operate
- โดยการ แบ่ง Characteristic เป็น Quantile Sketch (Bucket-based) → ลดการคำนวณ
- ทำให้การตัดสินใจเลือก Break up Level เร็วขึ้น อาจมีการเลือก Break up Level ที่ไม่แม่นยำที่สุดในบางกรณี แต่โดยรวมแล้วยังได้ผลลัพธ์ที่ดีและเร็วขึ้นมาก
*XGBoost package deal ไม่อยู่ใน sklearn
Examples of Determination Tree Fashions, Their Capabilities, and Libraries
https://github.com/pvateekul/2110446_DSDE_2024s2 by รศ.ดร.พีรพล เวทีกูล (Assoc. Prof. Peerapon Vateekul, Ph.D.)