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 से पूछना!
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 inX. - Labels (
y) — हर वज़न का सही जवाब ("Apple"या"Watermelon")। model.fit(X, y)- Train — teaches our pre-built AI
modelusingXandy. - पढ़ाई (Training) — AI मॉडल को
Xऔरyदेखकर पैटर्न सिखाता है। model.predict(160)- Predict — asks the trained AI what fruit weighs
160grams! - भविष्यवाणी — सीखे हुए 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) प्रिंट करो — फिर दाईं ओर तराज़ू में अलग-अलग वज़न टेस्ट करो!
- Keep
X_weightandy_fruitwith matching item counts.X_weightऔरy_fruitलिस्ट बनाओ। - Call
model.fit(X_weight, y_fruit)to train the AI.model.fit(X_weight, y_fruit)चलाकर AI को ट्रेन करो। - 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
- ML = the computer learns the rule from examples instead of us writing it.
X= features (clues like weight),y= labels (answers like the fruit name).- Train first with
model.fit(X, y), thenmodel.predict(...)answers new cases (modelis a helper of this lab).
- ML = नियम हम नहीं लिखते, कंप्यूटर उदाहरणों से ख़ुद सीखता है।
X= features (सुराग, जैसे वज़न),y= labels (जवाब, जैसे फल का नाम)।- पहले
model.fit(X, y)से training, फिरmodel.predict(...)नए सवाल का जवाब देता है (modelइस लैब का helper है)।
Quick quiz
In Supervised Learning, what do fit(X, y) and predict(new_x) do?
Machine Learning में fit(X, y) और predict(new_x) का क्या काम है?
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
- Lemon or Coconut? Train Your First AI
नींबू या नारियल? अपना पहला AI सिखाओ
Solve them in the Practice Zone, where each answer is checked automatically and two hints are available.