AI & Machine Learning Foundations
Build the mental model that makes every later algorithm easier: what intelligence means in software, how machines learn from data, how a model moves from examples to decisions, and how to frame a real problem correctly.
LEARNING
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
By the End of This Level, You Can
Five Ideas to Recall Before AI & ML
No advanced mathematics is required here. Start with these familiar programming ideas.
Numbers, text, images, audio or sensor readings can become model inputs.
A program applies instructions; an ML model applies a learned mathematical function.
The output may be a class, number, recommendation, generated text or action.
Model parameters are adjustable values learned during training.
A model is a parameterized function that approximates a useful relationship.
AI, Machine Learning, Deep Learning & Data Science
These terms overlap, but they answer different questions.
Artificial Intelligence
The broad field of building systems that perform tasks requiring perception, reasoning, language, planning or decision-making.
Examples: search, expert systems, robotics, game playing, ML.Machine Learning
A way to build behaviour by learning patterns from data instead of writing every decision rule manually.
Examples: price prediction, spam detection, recommendations.Deep Learning
A branch of ML using multilayer neural networks that learn useful representations from large or complex data.
Examples: vision, speech, language models.Data Science
The broader practice of turning data into reliable insight using statistics, computing, domain knowledge and communication.
Examples: analysis, experimentation, dashboards, predictive modelling.Artificial intelligence is the broad goal of building systems that perform tasks requiring human-like reasoning. Machine learning is one way to achieve that goal by learning patterns from examples. Deep learning is a machine-learning family built from many-layer neural networks, while data science combines data collection, analysis, modelling and communication to support decisions.
A hospital dashboard that summarizes patient trends is data science. A model that predicts readmission risk is machine learning. A system that combines predictions with rules and clinician review is an AI application.
Interviewers often test whether you can distinguish a complete AI system from the statistical model inside it.
Do not use AI, ML, deep learning and data science as interchangeable words. Their scopes overlap, but they are not identical.
Programmed Rules vs Learned Patterns
The central shift is where the decision logic comes from.
Best when rules are stable, explicit and manageable.
if temperature > 38:
alert = "High"Best when useful patterns exist but rules are difficult to write completely.
model.fit(examples, labels)The trained model applies what it learned to unseen input.
prediction = model.predict(new_data)A rule-based program follows conditions written directly by a developer. A learned system receives examples containing inputs and outcomes, adjusts parameters to reduce error, and then applies the discovered relationship to new inputs. Learning is useful when rules are too numerous, uncertain or constantly changing.
A fixed tax calculation is clearer as rules. Spam detection is better suited to learning because useful signals include thousands of changing word, sender and behaviour patterns.
Problem framing includes deciding whether machine learning is necessary at all. A simpler deterministic solution is often safer and easier to maintain.
Learning from historical decisions can reproduce their mistakes or bias. More data does not automatically produce better rules.
The Vocabulary of Learning from Data
Use these words precisely; interviewers notice when a candidate does.
A table, image folder, document set or stream used for learning or evaluation.
One row, image, message or event in the dataset.
A measurable property supplied to the model, often written as x.
The value to predict, often written as y.
A mathematical function that maps input features to an output.
A weight or bias updated by the training process.
A learning rate, depth or neighbour count selected outside training.
A number the learning process tries to minimize.
A business-relevant measure such as accuracy, F1 or mean absolute error.
Generating a prediction for new, previously unseen input.
A dataset contains samples. Each sample is described by features and, in supervised learning, a target or label. A model contains learned parameters. Training changes those parameters; inference uses the fixed parameters to create a prediction. Hyperparameters control the learning process or model structure and are selected using validation evidence.
For house-price prediction, one house is a sample, area and location are features, sale price is the target, regression coefficients are parameters, and regularization strength is a hyperparameter.
Clear vocabulary makes data shapes, training code and interview explanations much easier to reason about.
A feature available after the real prediction time is leakage, even if it appears in the historical table.
Four Learning Paradigms
The available feedback determines the learning setup.
Supervised Learning
Learn from inputs paired with known labels.
Classification predicts categories.
Unsupervised Learning
Discover useful structure when labels are absent.
Reduction compresses representation.
Self / Semi-Supervised
Exploit abundant unlabelled data with generated or limited supervision.
Semi-supervised mixes labelled and unlabelled samples.
Reinforcement Learning
An agent learns actions through rewards and consequences.
The goal is long-term cumulative reward.
Supervised learning uses labelled examples to predict a target. Unsupervised learning searches for structure without a supplied answer. Semi-supervised learning combines a small labelled set with a larger unlabelled set. Reinforcement learning improves a policy through actions, rewards and delayed consequences.
Price prediction is supervised regression; customer grouping is unsupervised clustering; image learning with 500 labels and 50,000 unlabelled images is semi-supervised; game-playing from rewards is reinforcement learning.
The correct paradigm follows from the feedback available to the system, not from the algorithm name alone.
Clustering does not discover objectively correct groups. It produces structure according to the features, distance measure and assumptions chosen.
Frame the Problem Before Choosing the Algorithm
A strong ML solution begins with a measurable decision—not with a favourite model.
- 1DecisionWhat decision or action will the prediction support?
- 2InputWhat information is available at prediction time?
- 3TargetWhat exactly should the model predict?
- 4MetricHow will usefulness and failure be measured?
- 5ConstraintsWhat limits exist for latency, cost, privacy, fairness and explanation?
- 6BaselineWhat simple rule or model must the solution beat?
Weak framing: “Use AI to help students.”
Useful framing: “Each week, predict which enrolled students are at high risk of missing the next assessment, using only activity available before that week, so mentors can intervene. Optimize recall while controlling false alerts.”
Good machine learning begins with a decision that must improve. Define the prediction unit, target, prediction time, allowed inputs, success metric, acceptable latency and cost of each error. Only then should you choose an algorithm. This prevents technically impressive models that solve the wrong business problem.
Instead of saying ‘predict student success,’ define: ‘At week four, estimate whether each active student will need support, using only attendance and assessments available by that date.’
Placement interviews reward candidates who translate a vague request into a measurable and leakage-safe formulation.
Do not optimize a convenient metric that ignores real consequences. A false negative and false positive may have very different costs.
The End-to-End Machine Learning Lifecycle
A model is only one component of a reliable AI system.
Decision, target, success metric and constraints.
Relevant, lawful and representative data.
Clean, explore and transform without leakage.
Separate train, validation and test evidence.
Learn parameters from training data.
Compare baselines, metrics and failure slices.
Serve predictions in a usable system.
Track quality, drift, safety and retraining needs.
The ML lifecycle is iterative: frame the problem, collect and understand data, split evaluation evidence, clean and transform, build a baseline, train candidates, validate, test once, deploy and monitor. Feedback from production may require new data or a reformulated objective rather than only model tuning.
A churn model may perform well initially, then weaken after a pricing change. Monitoring detects the shift, analysis identifies the changed behaviour, and retraining or reframing follows.
Real ML work includes data contracts, experiment records, deployment checks and monitoring—not only calling fit and predict.
Treating deployment as the final step hides drift, broken features and changing user behaviour.
Training, Validation and Test Data
Each split has a different job. Reusing the test set for decisions makes the final score untrustworthy.
The model learns weights or patterns from these examples.
You compare models and tune hyperparameters without touching the test set.
You use it after decisions are finalized to estimate performance on unseen data.
Training data estimates parameters. Validation data supports model, feature, threshold and hyperparameter decisions. Test data provides one final unbiased estimate after those choices are complete. The split must respect time, people, devices or groups whenever related samples could otherwise appear in multiple partitions.
For repeated medical visits, split by patient rather than by row. Otherwise the same patient’s patterns can appear in both training and test data.
A valid evaluation design is more important than a sophisticated algorithm because every later conclusion depends on it.
Repeatedly checking test performance turns the test set into another validation set and makes the reported score optimistic.
Generalization: The Real Goal
A useful model succeeds on unseen cases, not only on examples it memorized.
Too Simple
High training error and high validation error. The model misses important structure.
Useful Pattern
Low enough training error and similar validation performance on unseen examples.
Memorizes Noise
Very low training error but worse validation error. The model learns accidental details.
Generalization is the ability to perform well on relevant unseen cases. Underfitting occurs when a model cannot capture important structure. Overfitting occurs when it learns training-specific noise. The goal is neither minimum training error nor maximum complexity, but reliable performance under realistic future conditions.
A very deep tree may memorize every training customer yet fail on new customers. Pruning, regularization and better validation can expose and reduce the problem.
Learning curves, cross-validation and subgroup analysis help separate limited data, excessive complexity and distribution shift.
A small train–test gap is not sufficient if both scores are poor or if the test distribution is unrealistic.
Accuracy Alone Is Not Enough
Check whether errors harm groups differently.
Collect only necessary data and protect it.
Document data, assumptions, limits and intended use.
Design fallbacks, human review and monitoring for failures.
People remain responsible for system decisions and impact.
🎬 How a Machine Learns — Visual Flow
Move from raw examples to a tested prediction. Every step shows what changes and why.
Collect representative examples
Begin with examples that represent the conditions where the model will be used.
Trace Your First Learning Algorithm
Follow simple linear regression from examples to a prediction. Observe every variable and calculation.
—Waiting for print(...)
Simple Linear Regression from Scratch
The model learns a line prediction = weight × input + bias.
hours = [1, 2, 3, 4, 5]
scores = [20, 35, 50, 65, 80]
mean_x = sum(hours) / len(hours)
mean_y = sum(scores) / len(scores)
numerator = sum((x - mean_x) * (y - mean_y)
for x, y in zip(hours, scores))
denominator = sum((x - mean_x) ** 2 for x in hours)
weight = numerator / denominator
bias = mean_y - weight * mean_x
new_hours = 6
prediction = weight * new_hours + bias
print(round(prediction, 2))score = 15 × hours + 5- Weight = 15: estimated score increase per extra study hour.
- Bias = 5: the line’s predicted value when hours is zero.
- For 6 hours:
15 × 6 + 5 = 95. - Limitation: extrapolation beyond observed data may be unreliable.
Build the Foundation with Code
Read the task, attempt it independently, use the hint only when needed, then compare with the model program.
Test Understanding, Not Memorization
Select one answer for every question. Results will show your choice, the correct answer and an explanation.
How Interviewers Test These Foundations
Strong candidates connect terminology to evaluation and business consequences.
Definition with Contrast
“Explain AI vs ML vs deep learning with one example each.”
Problem Framing
“Design the target, features and metric for churn prediction.”
Failure Diagnosis
“Training accuracy is high but test accuracy is low. What happened?”
Production Thinking
“Why can a model’s quality decline after deployment?”
🎤 AI & ML Foundations — Interview Questions
Answer aloud before opening each explanation.
The Foundation in One View
Start with a decision and measurable success.
Use representative data to fit parameters.
Evaluate honestly on unseen evidence.
Deploy responsibly and monitor continuously.
Machine learning is not “data in, magic out.” It is a disciplined process of defining, learning, testing and improving a measurable system.
Habits That Prevent Beginner Mistakes
Always write the target and prediction-time features before selecting a model.
Build a simple baseline first; complexity must earn its place.
Keep the test set untouched until model and hyperparameter choices are complete.
Inspect examples and labels manually before trusting summary statistics.
Choose metrics from the cost of errors, not from habit.
Record assumptions, dataset limits and known failure cases as part of the model.
Strengthen Your AI & ML Thinking
Attempt these without opening notes. Explain every answer with a reason.
- 01
For an email spam detector, identify one sample, three possible features and the label.
- 02
Decide whether house-price prediction is regression or classification, and explain why.
- 03
Give one problem better solved with explicit rules than with machine learning.
- 04
Explain why a model scoring 100% on its training data may still be useless.
- 05
Design a train/validation/test split for time-ordered sales data without future leakage.
- 06
For fraud detection, explain why accuracy alone can be misleading.
- 07
Give one parameter and one hyperparameter for a model you know.
- 08
Classify customer segmentation by learning paradigm and justify your choice.
- 09
Name two reasons production data may differ from training data.
- 10
Write a useful baseline for predicting whether a student submits an assignment.
- 11
Turn “build an AI hiring tool” into a measurable problem statement with safeguards.
- 12
Draw the complete ML lifecycle and mark where human review should occur.
