Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Machine Learning Notes
Topic #102

How Machine Learning Works

Every ML system, regardless of algorithm, follows the same underlying loop: represent data as numbers, define a way to measure error, and adjust the model to reduce that error — repeated until predictions are good enough.

The Four-Step Loop

StepWhat Happens
1. RepresentConvert raw data (numbers, text, categories) into a numeric feature vector the algorithm can use.
2. PredictThe model, using its current parameters, produces an output for each input.
3. Measure errorA loss function compares the prediction to the true answer and produces a single number — how wrong the model was.
4. ImproveAn optimization algorithm (usually gradient descent) adjusts the model's internal parameters to reduce that error, then the loop repeats.

A Concrete Walkthrough

from sklearn.linear_model import LinearRegression
import numpy as np

X = np.array([[1], [2], [3], [4]])   # study hours
y = np.array([2, 4, 6, 8])           # marks scored (toy, perfectly linear)

model = LinearRegression()
model.fit(X, y)  # internally: finds slope & intercept that minimize squared error

print(model.coef_, model.intercept_)   # learned parameters
print(model.predict([[5]]))            # prediction for 5 study hours

Expected output: coef_ ≈ [2.0], intercept_ ≈ 0.0, and a prediction of [10.0] for 5 hours — the model learned the rule marks = 2 × hours purely from 4 examples.

What Actually Gets "Learned"

Training doesn't produce new code — it produces parameters (numbers): weights in linear/logistic regression, split thresholds in a decision tree, support vectors in an SVM. "Training a model" means searching for the parameter values that minimize error on the training data.

Practical Use Cases

This same loop underlies a spam classifier, a house-price regressor, and a recommendation engine — only the representation, the model type and the loss function change.

Common Mistakes

  • Believing more complex models always "learn better" — a model can also learn the noise in the training data instead of the real pattern (see Overfitting).
  • Forgetting that the loop needs a way to measure error — without a loss function there's nothing for the algorithm to optimize.

Interview Relevance

Q: "What does it mean for a model to 'learn'?" It means iteratively adjusting internal parameters to minimize a loss function computed on training data — not writing new code or rules.

Practice Question

For a spam classifier, describe what the "representation," "prediction," "error" and "improve" steps would concretely look like.

Related ML Notes

Want to go beyond the notes?

Join CodingNow's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →