Docsity

Mastering Decision Trees: Handwritten Notes + Code (Beginner to Advanced), Study notes of Technology

Partial preview of the text

Download Mastering Decision Trees: Handwritten Notes + Code (Beginner to Advanced) and more Study notes Technology in PDF only on Docsity!

DECISION TREES i Decision Tree is a supervised machine learnine abgorithm = that models decisions using a tree-like Structure. = " Each intemal node represents a condition on a feoture, | = branches represent decision outcomes, and leaf nodes i a: give the final prediction, bs ii It works for beth classification and Regression tasks. i Decision trees are easy to interpret but can overfit ai if not properly constrained. =F * Entropy ¢ Impurity metric) i ( — Geant ais) reemeartane Boaarse eta seeteras ta 8: CF Meesures the Impurity , alisordler, or Uncertainty. i a tn a dataset. C— Smaller the entropy, better the model. ai) a id 4 E(S) =-> Pr log, Pe ee z=1 a Pi = Probability of Class i ai E(S)= ~Py log, Py ~ Pr logaPr ~ Py = Probability of Yes ai Pa = Probability of No i ag = Eee ia Pay = EOD; Fa = aoe C— E=-05 log, 0.5 -0.5 log,0.5 = ( = —> Impure a. 7 ll « — GINI IMPURITY x Gin? Impurity: develo bu Conxado Gint fod t : » Gini Impurity measures how mixed the classes are ot a node Ty in a decision tree. + Tt tells gous the probability of incorrectly. Classifying. a randomly sample from that node. © Lower Gini means the node is more pure (more focused on one class) Q During splitting, ctecision trees choose the Future thet reduces Gini peti the most. Gl 4= = (Pt ie S 3p: oy | x a ce eee eel are to) (e5r Sale (Py+ Pn?) i GI= 4f14+0) =4- ee Opes Lg ey =0.5 L * Information Gain Exam ple + Pruning * B Deciston Tree Split Example Gender 24:4) A Entropy Calculations . ” F - Paren} entropy: s: [2y:1n} [ey ,3n] H(S) = aa eae -¢ log, = H(Sm)= - 3 log, 3 = logo = AW Gm)= 3 09, Se le 2a. i H(s,)=0 Wie )y=0 1) (because it's pure > only one class) sk IG = H(S)- (2x0.918 +3x0) = 0.918 - 0.459 = 0.459 a. Pruning : © Pruning means cutting off unnecessary branches of a decision tree : 2 Make it simpler ° Prevent overfitting e Remove splits that don't improve accuracy on unseen data Basically eS trimming the tree so tt doesn't grou wild: 3x Common Pruning Rules: ° max—depth - Stop splitting when the tree reaches max depth. @ min_samples_split — Node must contain ot least N samples to be split. © min_somples_leaf — Leaf must contain ot least N Samples. 2 mox_leaf_nodes — Limit total number of leaf hedes- . min_impurit _decrease — Only split rs Tenpurity reduction exceeds, a thresnold - Se Decision Tree as Regressor A Decision Tree Regressor fsa Supervised learning model that predicts continuous numeric values by. 2 Splitting data into smaller regions based on = Feature conditions. ° At each leaf node > it outputs the aie value. of the samples in that region. 4 Variance Reduction: Variance reduction is used fn decision tree regression to choose splits that make the target volue. tn each region more. consistent. It hetps create cleaner, more accurate predictions by realucing randomness within the groups. = Ve — fISelVi+ ISRi.VR VR = Vs (‘S L =