Machine Learning
Machine learning is a branch of AI where systems learn patterns from data instead of following rules a person wrote by hand.
What Is Machine Learning?
In traditional programming, a person writes explicit rules: given this input, do that. Machine learning flips that around — instead of writing the rules, you show the system examples, and it learns the rules on its own.
Rules + Data
Output
Data + Desired Outcomes
Learned Model
Once a model exists, using it looks like this:
New Data + Model
Uses Trained ModelData the model hasn't seen before.
Prediction
Learned, Not CodedProduced by learned rules, not hand-written ones.
Training vs. Inference
The overall flow of a machine learning system is: data goes in, training produces a model, and the model then makes predictions on new data.
Data
ExamplesWhat the system learns from.
Training
Happens OnceRuns ahead of time, over the full dataset.
Model
Learned RulesThe result of training, ready to be used.
Inference
Happens Every TimeRuns each time the model is actually used.
- Training
- The process of adjusting a model's parameters so its predictions get closer to correct, using example data.
- Inference
- Using an already-trained model to produce a prediction on new data it has not seen before.
- Features
- The input variables a model uses to make a prediction — for example, a house’s size, age, and location when predicting its price.
- Labels
- The correct answer associated with a training example — the actual sale price, in the house example above.
- Model
- The trained structure that maps features to a prediction, based on patterns learned from training data.
Types of Learning
- Supervised learning — the model trains on examples that already have the correct answer attached (labeled data), such as emails marked spam or not spam.
- Unsupervised learning — the model finds structure in data that has no labels, such as grouping customers into segments based on behavior.
- Reinforcement learning — the model learns by taking actions in an environment and getting a reward or penalty as feedback, adjusting its behavior over time.
Code Example
A minimal supervised learning example, using a small, well-known library for illustration:
# Illustrative example using scikit-learn
from sklearn.linear_model import LinearRegression
# Features: [square_feet], Labels: price
X_train = [[1000], [1500], [2000], [2500]]
y_train = [200000, 275000, 340000, 410000]
model = LinearRegression()
model.fit(X_train, y_train) # training
predicted_price = model.predict([[1800]]) # inference
print(predicted_price)The model isn't given a formula for house prices — it learns the relationship between square footage and price from the training examples, then applies that learned relationship to a new input.
Common Mistakes
Confusing training with inference
Training happens once (and periodically after); inference happens every time the model is used to make a prediction.
Assuming more data always means a better model
Data quality, relevant features, and how well the data represents real-world cases usually matter more than raw volume.
Treating a model’s output as ground truth
A prediction is a statistical estimate based on patterns in training data, not a guaranteed correct answer.
Interview Question
What is machine learning and how is it different from traditional programming?
In traditional programming, a person writes explicit rules that map inputs to outputs. In machine learning, you instead give the system data and the desired outcomes, and it learns the mapping itself — producing a model. Once trained, that model can take new, unseen data and produce a prediction. The key shift is that the rules are learned from examples rather than hand-written.
What an interviewer may ask next
- What is the difference between supervised and unsupervised learning?
- What is the difference between training and inference?
- How would you know if a model is overfitting to its training data?
Explain It in 30 Seconds
Machine learning is a way of getting a system to perform a task by learning patterns from data instead of following hand-written rules. You give it examples with known outcomes during training, it produces a model, and that model then makes predictions on new data during inference. Supervised, unsupervised, and reinforcement learning describe different ways the system learns from data or feedback.