Machine Learning Introduction

Machine Learning Beginner 3 min read Published
In this lesson

Normal programming: you write the rules. “If marks ≥ 40, print Pass.”

Machine learning: you give the computer examples with answers, and it finds the rules itself. Show it 10,000 emails labelled “spam” or “not spam”, and it learns which words and patterns mean spam, including ones you’d never think to write down.

Traditional programmingMachine learning
Inputdata + rulesdata + answers
Outputanswersrules (a model)

Where you already use it#

  • YouTube and Netflix recommendations
  • Google Maps arrival times
  • UPI and bank fraud alerts
  • Face unlock on your phone
  • ChatGPT, Claude and Gemini (a very large kind of model called an LLM)

Three kinds of learning#

1. Supervised learning: every example has the right answer (a label). The model learns to predict that label for new data.

  • Regression predicts a number: house price, temperature, delivery time.
  • Classification predicts a category: spam or not, pass or fail, which disease.

2. Unsupervised learning: no labels. The model finds structure on its own, for example grouping customers with similar shopping habits (clustering).

3. Reinforcement learning: the model learns by trial and error with rewards, like a game-playing AI or a robot learning to walk.

This course focuses on supervised learning, which covers most real jobs.

Features and labels#

Every dataset for supervised learning has two parts:

area_sqftroomsage_yearsprice_lakh
12002568
180031295
90022041
  • Features (called X): the inputs the model looks at: area, rooms, age.
  • Label or target (called y): the answer to predict: price.
import pandas as pd

homes = pd.DataFrame({
    "area_sqft": [1200, 1800, 900],
    "rooms": [2, 3, 2],
    "age_years": [5, 12, 20],
    "price_lakh": [68, 95, 41],
})
X = homes[["area_sqft", "rooms", "age_years"]]
y = homes["price_lakh"]
print(X.shape, y.shape)

Output:

(3, 3) (3,)

By convention X is capital (a table) and y is lower-case (one column).

The workflow#

Every model, from a tiny one to ChatGPT, follows the same steps. Play through them:

  1. Collect and clean data (your Pandas skills).
  2. Split it into a training set and a test set.
  3. Train (fit): the model learns from the training set.
  4. Predict on the test set, which it has never seen.
  5. Evaluate: compare predictions with the real answers.
  6. Improve and repeat.

The test set is like a surprise exam. If you let the model see it while studying, a high score means nothing. Always keep it separate.

The tool: scikit-learn#

scikit-learn (imported as sklearn) is Python’s standard machine learning library. Every model in it has the same three methods, which makes it easy to try many:

model.fit(X_train, y_train)     # learn
model.predict(X_new)            # predict
model.score(X_test, y_test)     # evaluate
pip install scikit-learn
Quick check

Predicting whether a customer will cancel their subscription (yes/no): regression or classification? Classification, because the answer is a category, not a number.

Summary#

  • Machine learning finds rules from examples instead of you writing them.
  • Supervised = learning from labelled examples: regression (numbers) or classification (categories).
  • Features X are the inputs; the label y is the answer.
  • Workflow: clean → split → fit → predict → evaluate.

Quick quiz

3 questions. Check what stuck and earn 2 XP for each right answer.

1In supervised learning, what is the label?
2Predicting a house price is…
3Why keep a separate test set?

Progress is saved in this browser. Create a free account to keep it on every device.