Ravindra BagaleCourses & study guides English Track your progress

35. Decision Trees आणि Random Forests — Python मध्ये

Data Science

35.1 Decision Tree मधून वाचता येणारे Rules

का गरजेचे आहे. Managers वाचता येणारे rules आवडतात: “if complaints ≥ 2 and orders_last_30d < 3 → high churn risk.” Trees ही भाषा बोलतात.

हे काय आहे. Decision tree features वर yes/no प्रश्न विचारते आणि leaf prediction (class किंवा number) वर थांबते. Rules print करता येतात — शिकवताना coefs च्या ढिगाऱ्यापेक्षा सोपी.

कसे करायचे.

if/else मध्ये विचार करा

  1. वरून सुरू करा (root).
  2. Row ला जुळणारी शाखा फॉलो करा.
  3. Leaf वर थांबा — तेच prediction.
# Story tree (not fitted yet)
# if complaints >= 2:
# predict churn = 1
# else:
# if orders_last_30d < 3: predict 1
# else: predict 0
print("Trees = stacked if/else on features.")

Ravindra Bagale's Tip

A very deep tree can memorise the training data instead of learning general rules. This problem is called overfitting, and you will study it in Chapter 38. So learn how to control the depth of a tree, for example with the max_depth setting.