2.3.13 · HinglishTree-Based & Instance Methods

XGBoost fundamentals and tuning

2,042 words9 min readRead in English

2.3.13 · AI-ML › Tree-Based & Instance Methods


XGBoost exist kyun karta hai?

Random Forest se compare karo (jo independent trees ko parallel mein average karta hai), boosting trees ko sequentially aur dependently banata hai — har ek is baat par depend karta hai ki pehle kya aaya tha.


MODEL kya hai? (Additive form)

Hum trees greedily add karte hain: round par prediction hai Hume (naya tree) chunna hai jo objective ko sabse zyada reduce kare.


Objective — regularization andar kyun built-in hai

Kyun: ordinary gradient boosting sirf loss minimize karta hai; XGBoost ko optimization ke andar add karta hai taaki trees prune hon aur leaf weights shrink hon — automatically, afterthought ki tarah nahi.


KAISE: Leaf weights ko first principles se derive karna

Additive step ko round par objective mein daalo (pehle ke trees ke constants drop karo):

Step 1 — Loss ko ke around 2nd order tak Taylor-expand karo. Yeh step kyun? Hum ek arbitrary loss ko seedha tree structures par optimize nahi kar sakte, isliye hum ise ek quadratic se approximate karte hain — jise hum closed form mein solve kar sakte hain.

Har example ke liye gradient aur Hessian define karo: Tab

Step 2 — Examples ko leaf ke anusaar group karo. Ek tree har ko exactly ek leaf mein bhejta hai. Maano aur wo leaf constant output karta hai. Kyunki : Maano aur .

Yeh step kyun? Ab objective har mein independent quadratics ka sum hai — minimize karna trivial hai.

Step 3 — ke upar minimize karo. Derivative zero set karo:

Step 4 — Wapas substitute karo aur ek fixed tree structure ke liye best achievable objective nikalo:


Split kaise chuna jaata hai — Gain formula

Hum har tree try nahi kar sakte. Isliye greedy tarike se grow karte hain: ek node par, uske data ko Left () aur Right () mein split karne ki koshish karo. Improvement hai (score pehle) (score baad mein):

kyun? Split karne se ek leaf add hoti hai, jiska cost hai. Agar Gain ho, split mat karo — yahi built-in pruning hai.

Figure — XGBoost fundamentals and tuning

Worked Example 1 — Leaf weight (regression, squared error)

Squared error ke liye: (negative residual), .

Maano ek leaf mein 3 examples hain jinka residual hai, toh . lo.

  • , .
  • .

Yeh step kyun? Leaf output karta hai — mean residual ke paas hai lekin ki wajah se 0 ki taraf shrunk hai. Bada ⇒ zyada shrinkage ⇒ kam overfit.

Worked Example 2 — Kya split karna chahiye?

Node ka hai. Proposed split: Left , Right . . Gain split reject karo. Kyun: loss mein reduction complexity cost ko beat nahi karti.

Worked Example 3 — Log-loss gradients

Binary classification, , loss . Tab aur . Agar aur current hai: (bada push upar), . Kyun: confident-wrong points ko bade gradients milte hain ⇒ agla tree unpar focus karta hai.


Key Hyperparameters (jo 80/20 matter karta hai)

Param Controls Direction
eta / learning_rate har tree ka contribution shrink karta hai: ↓ = zyada robust, zyada trees chahiye
n_estimators trees ki sankhya eta ke saath pair karo; early stopping use karo
max_depth tree complexity ↓ overfit se ladne ke liye
min_child_weight leaf mein min ↑ overfit se ladne ke liye
gamma split ke liye min gain () ↑ = zyada pruning
lambda, alpha leaf weights par L2 / L1 ↑ = zyada regularization
subsample tree ke liye row sampling <1 randomness add karta hai
colsample_bytree feature sampling <1 trees ko decorrelate karta hai


Recall Feynman: ek 12-saal ke bachche ko samjhao

Socho tum ek tasveer bana rahe ho aur ek dost tumhari galtiyan dikhata hai. Tum thoda theek karte ho. Phir ek aur dost batata hai ki kya abhi bhi galat hai, aur tum woh thoda theek karte ho. Har dost sirf ek chhoti si correction karta hai (yahi learning rate hai), aur tum ek dost ki nahi sunते agar unka "fix" matter karne ke liye bahut chhota ho (yahi gamma pruning hai). Bahut saare doston ke baad, tumhari tasveer shandar hoti hai — lekin agar tum hamesha ke liye doston ko bulate raho, toh woh un chezon ko "fix" karne lagte hain jo pehle se theek theen aur kharab kar dete hain. Isliye tum sahi waqt par ruk jaate ho (early stopping). XGBoost aaise vinammra doston ki team hai jo gradient (which way fix karna hai) aur Hessian (how carefully fix karna hai) dono use karke jawab ko paas la dete hain.


Recall — khud ko test karo

Flashcards

XGBoost ka additive model form kya hai?
, regression trees ka sum jo sequentially add hote hain, har ek residual errors fit karta hai.
XGBoost loss ka 2nd-order Taylor expansion kyun use karta hai?
Kisi bhi differentiable loss ko tree output mein ek quadratic mein convert karne ke liye, jise har leaf ke liye closed form mein minimize kiya ja sake (Newton-style), gradient aur Hessian use karke.
Optimal leaf weight ka formula?
jahan , .
Split Gain ka formula?
.
kya karta hai?
Split karne ke liye minimum loss reduction required; har leaf ke liye complexity penalty ki tarah kaam karta hai, automatic pruning enable karta hai (split reject karo agar Gain ≤ 0).
kya karta hai?
Leaf weights par L2 regularization; ko 0 ki taraf shrink karta hai, overfit kam karta hai.
Squared error ke liye aur kya hain?
(negative residual), .
Log-loss ke liye aur kya hain?
, , jahan .
XGBoost mein Random Forest ki tarah unlimited trees kyun nahi add kar sakte?
Trees dependent hain aur residuals fit karte hain, isliye extra trees noise overfit karte hain; averaging ki jagah early stopping use karo.
Learning rate (eta) ka kya role hai?
Har tree ka contribution scale karta hai: ; chhota eta = slower, zyada robust learning jisme zyada trees chahiye.
Sabse high-leverage tuning pair kaunse do hyperparameters hain?
Chhota learning_rate + n_estimators jo validation set par early stopping se control hota hai.
XGBoost structurally Random Forest se kaise alag hai?
RF independent parallel trees average karta hai (variance reduction); XGBoost dependent sequential trees ka sum karta hai jo residuals fit karte hain (boosting se bias reduction).

Connections

  • Gradient Boosting — XGBoost ek regularized, 2nd-order implementation hai.
  • Decision Trees — base learner ().
  • Random Forests — contrast: bagging/parallel vs boosting/sequential.
  • Regularization (L1 L2) leaf weights par kaam karte hain.
  • Bias-Variance Tradeoff — boosting bias reduce karta hai; regularization variance control karta hai.
  • Taylor Series — gradient+Hessian approximation ka basis.
  • Newton's Method ek damped Newton step hai.

Concept Map

motivates

fast regularized impl

contrast: parallel independent

model form

trained sequentially

includes

penalizes leaves and weights

approximated by

uses

grouped via

solve quadratic

Single tree overfits or underfits

Boosting

XGBoost

Random Forest

Additive tree ensemble

Regularized objective

Regularization Omega

2nd-order Taylor expansion

Gradient g and Hessian h

Group examples by leaf

Closed-form leaf weights