Machine Learning & AI · Chapter 4.3 · Basic level

Decision Trees (Cricket Match Win Predictor! )

Decision Trees (क्रिकेट मैच जीत/हार भविष्यवाणी! )

When AI chooses between categories (Win vs Lose, Spam vs Not Spam, Pass vs Fail), it's called Classification! A Decision Tree thinks just like a cricket captain asking step-by-step questions: Did our team score enough Runs? → Did we save our Wickets? → 🏆 WIN! Notice each match in X_match has 2 clues: [Runs, Wickets]!

जब AI को संख्या नहीं बल्कि हाँ/ना या श्रेणी (Win या Lose, Pass या Fail) में फ़ैसला लेना हो, तो उसे Classification कहते हैं! Decision Tree पेड़ की शाखाओं की तरह सवाल पूछकर नतीजे पर पहुँचता है: क्या टीम के Runs काफ़ी हैं? → क्या Wickets बचे हैं? → 🏆 जीत (Win)! यहाँ हर मैच में 2 सुराग हैं: [Runs, Wickets]!

In the classroom you can run and edit this code in your browser, get hints and mark the chapter as done. क्लास में यह code ब्राउज़र में चलाकर बदल सकते हो।

Words and symbols in this chapter

from sklearn.tree import DecisionTreeClassifier
Imports the Decision Tree classifier from sklearn.tree.
sklearn.tree से Decision Tree क्लासिफ़ायर लाता है।
[[120, 9], [210, 2], ...]
2D list — each inner [Runs, Wickets] is one past cricket match.
हर छोटे [Runs, Wickets] में एक पुराने मैच के रन और गिरे विकेट हैं।
y_result = ["Lose", ..., "Win"]
Outcome of each past match.
हर पुराने मैच का नतीजा ("Lose" या "Win")।
tree.fit(X_match, y_result)
Builds the decision tree rules from match history.
पुराने मैचों के डेटा से निर्णय लेने वाला पेड़ (Tree) तैयार करता है।
tree.predict([220, 3])
Predicts whether 220 Runs & 3 Wickets will Win or Lose!
नए स्कोर 220 रन, 3 विकेट पर जीत होगी या हार, यह बताता है!

Ready example

from sklearn.tree import DecisionTreeClassifier

# [Team Runs, Wickets Lost]
X_match = [[120, 9], [140, 8], [210, 2], [240, 1]]
y_result = ["Lose", "Lose", "Win", "Win"]

tree = DecisionTreeClassifier()
tree.fit(X_match, y_result)

print("Match Result:", tree.predict([220, 3]))

What you will see: Interactive Visual Decision Tree Diagram + live Runs & Wickets Sliders so you can test any cricket score!

प्रिव्यू में चमकता हुआ Decision Tree डायग्राम और Runs व Wickets स्लाइडर मिलेंगे जिनसे आप किसी भी स्कोर पर जीत/हार टेस्ट कर सकेंगे!

Line by line

X_match = [[120, 9], [140, 8], [210, 2], [240, 1]]
Low runs + high wickets lost (120/9, 140/8) vs high runs (210/2, 240/1).
कम रन वाले 2 मैच और ज़्यादा रन वाले 2 मैचों का डेटा।
tree.fit(X_match, y_result)
AI automatically discovers the winning score split (Runs >= 175)!
AI खुद जीत और हार की सीमा (Runs >= 175) खोज लेता है!
print("Match Result:", tree.predict([220, 3]))
Predicts 'Win' for 220/3!
220/3 के स्कोर पर 'Win' की भविष्यवाणी करता है!

Common mistake

✗ Wrong

tree.predict(210, 3)

✓ Right

tree.predict([210, 3])

When a model expects 2 features [Runs, Wickets], pass them together inside a list [210, 3]!

जब मॉडल ने 2 चीज़ें [Runs, Wickets] सीखी हों, तो predict([210, 3]) में भी लिस्ट [ ] के अंदर भेजें!

Your task

Train DecisionTreeClassifier() on X_match & y_result and print tree.predict([220, 3])!

DecisionTreeClassifier() को X_match व y_result पर ट्रेन करो और tree.predict([220, 3]) प्रिंट करो!

  1. Create tree = DecisionTreeClassifier().
    tree = DecisionTreeClassifier() लिखो।
  2. Train with tree.fit(X_match, y_result).
    tree.fit(X_match, y_result) से ट्रेन करो।
  3. Print tree.predict([220, 3]) and click ▶ Run & Preview!
    tree.predict([220, 3]) प्रिंट करके ▶ Run & Preview दबाओ!
Starter code for the task
from sklearn.tree import DecisionTreeClassifier

# [Runs, Wickets Lost]
X_match = [[120, 9], [140, 8], [210, 2], [240, 1]]
y_result = ["Lose", "Lose", "Win", "Win"]

# TODO 1: tree = DecisionTreeClassifier() banao
# TODO 2: tree.fit(X_match, y_result) se train karo
# TODO 3: print("Match Result:", tree.predict([220, 3]))

Do this task in the classroom: your code is checked automatically and you get hints if something is missing.

Recap

Quick quiz

Predicting categories like Win or Lose is called what in ML?

Win या Lose जैसी श्रेणी (Category) चुनना ML में क्या कहलाता है?

  1. Regression
  2. Classification
  3. Compilation
  4. Styling
Show the answer

Answer: B (Classification)

Choosing discrete classes/categories (Win/Lose, Spam/Safe) is Classification!

जब जवाब किसी तय श्रेणी (Win/Lose) में हो, तो उसे Classification कहते हैं!

Practice problems for this chapter

Solve them in the Practice Zone, where each answer is checked automatically and two hints are available.