Machine Learning & AI · Chapter 4.1 · Basic level

What is Machine Learning? (Features X & Labels y)

मशीन लर्निंग क्या है? (सुराग X और जवाब y)

Welcome to Artificial Intelligence & Machine Learning! What's the difference between normal coding and ML?
• In Normal Coding, humans write the rules.
• In Machine Learning, we show the computer past examples (Data) and the computer discovers the rule by itself!
Imagine teaching a child to tell an 🍎 Apple (~150g) from a 🍉 Watermelon (~4200g):
1. X (Features / Clues): Weights in grams [120, 150, 180, 3500, 4200, 5000]
2. y (Labels / Answers): Fruit names ["Apple", ..., "Watermelon"]
3. model.fit(X, y): AI studies the examples!
4. model.predict(160): AI predicts what a new 160g fruit is!

आर्टिफिशियल इंटेलिजेंस (AI) और मशीन लर्निंग में स्वागत है! नॉर्मल कोडिंग और मशीन लर्निंग में एक ही बड़ा अंतर है:
• नॉर्मल कोडिंग में इंसान कंप्यूटर को नियम बताता है।
• मशीन लर्निंग में हम कंप्यूटर को पुराने उदाहरण (Data) दिखाते हैं और कंप्यूटर खुद पैटर्न सीखकर भविष्यवाणी (Prediction) करता है!
सोचो छोटे बच्चे को वज़न से 🍎 सेब (150g) और 🍉 तरबूज़ (4200g) पहचानना सिखाना है:
1. X (Features / सुराग): फलों के वज़न [120, 150, 180, 3500, 4200, 5000]
2. y (Labels / सही जवाब): फलों के नाम ["Apple", ..., "Watermelon"]
3. model.fit(X, y): AI को उदाहरण पढ़ाकर तैयार करना (Training)!
4. model.predict(160): नए 160g फल के बारे में AI से पूछना!

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

# comment
Lines starting with # are human notes — Python ignores them.
# से शुरू होने वाली लाइन इंसानों के समझने का नोट है।
X_weight = [...]
Features (X) — input clues (weights of fruits in grams).
Features (X) — सवाल/सुराग (फलों का वज़न ग्राम में)।
y_fruit = [...]
Labels (y) — correct answers matching each weight in X.
Labels (y) — हर वज़न का सही जवाब ("Apple" या "Watermelon")।
model.fit(X, y)
Train — teaches our pre-built AI model using X and y.
पढ़ाई (Training) — AI मॉडल को X और y देखकर पैटर्न सिखाता है।
model.predict(160)
Predict — asks the trained AI what fruit weighs 160 grams!
भविष्यवाणी — सीखे हुए AI से पूछता है कि 160g वाला फल कौन सा है!

Ready example

# Step 1: Training Data (Clues X & Answers y)
X_weight = [120, 150, 180, 3500, 4200, 5000]
y_fruit  = ["Apple", "Apple", "Apple", "Watermelon", "Watermelon", "Watermelon"]

# Step 2: Train the AI Model
model.fit(X_weight, y_fruit)

# Step 3: Predict a new 160g fruit!
ans = model.predict(160)
print("AI Prediction:", ans)

What you will see: An animated Weight Scale (Tarazu) + a live 🧪 Test Your Trained AI box where you can enter ANY weight (200g, 4500g) and test your AI!

दाईं तरफ़ तराज़ू (Weight Scale) और 🧪 Test Your Trained AI बॉक्स खुलेगा जहाँ आप खुद कोई भी वज़न डालकर अपने AI की परीक्षा ले सकते हैं!

Line by line

X_weight = [120, 150, 180, 3500, 4200, 5000]
6 training weights: 3 light fruits and 3 heavy fruits.
6 फलों के वज़न (ग्राम में) की लिस्ट।
y_fruit = ["Apple", ..., "Watermelon"]
6 matching fruit labels (must have the exact same count as X_weight!).
उन्हीं 6 फलों के सही नाम (गिनती बराबर होनी चाहिए!)।
model.fit(X_weight, y_fruit)
AI learns that light (~150g) = Apple and heavy (~4233g) = Watermelon.
AI ने दोनों की तुलना करके खुद पहचानने का नियम सीख लिया।
ans = model.predict(160)
Predicts 'Apple' for 160g!
160 ग्राम के नए फल को तुरंत 'Apple' पहचान लिया!

Common mistake

✗ Wrong

ans = model.predict(160)
model.fit(X, y)

✓ Right

model.fit(X, y)
ans = model.predict(160)

Never call predict() before fit()! First teach the AI (fit), then test it (predict).

बिना सिखाए (fit) कभी परीक्षा (predict) मत लो! हमेशा पहले model.fit(X, y) और उसके बाद predict() चलाएँ।

Your task

Train model.fit(X_weight, y_fruit) and print model.predict(160) — then try testing custom weights in the Live AI Lab on the right!

model.fit(X_weight, y_fruit) से AI को सिखाओ और model.predict(160) प्रिंट करो — फिर दाईं ओर तराज़ू में अलग-अलग वज़न टेस्ट करो!

  1. Keep X_weight and y_fruit with matching item counts.
    X_weight और y_fruit लिस्ट बनाओ।
  2. Call model.fit(X_weight, y_fruit) to train the AI.
    model.fit(X_weight, y_fruit) चलाकर AI को ट्रेन करो।
  3. Call model.predict(160) and print the answer, then click ▶ Run & Preview!
    model.predict(160) को print करके ▶ Run & Preview दबाओ!
Starter code for the task
X_weight = [120, 150, 180, 3500, 4200, 5000]
y_fruit  = ["Apple", "Apple", "Apple", "Watermelon", "Watermelon", "Watermelon"]

# TODO 1: model.fit(X_weight, y_fruit) se AI ko padhao
# TODO 2: ans = model.predict(160) se naye 160g fruit ka jawab lo
# TODO 3: print("AI Prediction:", ans)

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

Recap

Quick quiz

In Supervised Learning, what do fit(X, y) and predict(new_x) do?

Machine Learning में fit(X, y) और predict(new_x) का क्या काम है?

  1. fit tests AI, predict deletes data
  2. fit trains AI from data, predict answers new unseen questions
  3. Both just print lists
  4. fit draws HTML tables
Show the answer

Answer: B (fit trains AI from data, predict answers new unseen questions)

fit() learns patterns from training data; predict() predicts answers for new inputs!

fit() डेटा से AI को सिखाता है और predict() नए सवाल की भविष्यवाणी करता है!

Practice problems for this chapter

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