How does machine learning differ from traditional programming?
Machine learning (ML) is a data-driven approach to solving problems by learning patterns from examples rather than having every decision rule written manually. It is useful for tasks whose rules are difficult to specify, such as predicting customer churn or classifying images, but its results depend heavily on data quality, can be difficult to interpret, and may degrade when production data changes.
Read full answerHide full answer
Applies tomachine learning concepts (examples in Python 3.12)
How It Works
A machine learning system follows a repeatable process:
-
Define the business problem: Translate the objective into a measurable task and metric.
-
Collect and prepare data: Clean missing values, remove duplicates, engineer features and split the data into training and test sets.
-
Train a model: An algorithm adjusts parameters or learns rules from the training data.
-
Evaluate performance: Use validation or cross-validation and metrics appropriate to the task.
-
Deploy and monitor: Make predictions, track real-world results and retrain when the data or business conditions change.
ML includes several main approaches:
-
Supervised learning: Learns from labelled examples, such as predicting house prices from historical sales.
-
Unsupervised learning: Finds structure in unlabelled data, such as grouping customers by purchasing behaviour.
-
Reinforcement learning: Learns actions through rewards and penalties, commonly used in robotics and recommendation systems.
Comparison With Traditional Programming
| Aspect | Traditional programming | Machine learning |
|---|---|---|
| Core approach | Developer writes explicit rules | Algorithm learns patterns from data |
| Input | Rules plus input data | Training examples plus input data |
| Output | Deterministic result produced by the coded rules | Prediction or decision produced by a trained model |
| Main effort | Designing and maintaining business logic | Data preparation, model selection and evaluation |
| Handles changing conditions | Requires code changes when rules change | Can retrain or adapt if suitable data is available |
| Interpretability | Usually easy to trace the execution | Varies by model; linear models are often clearer |
| Failure mode | Incorrect or incomplete rules | Poor-quality data, overfitting or data drift |
| Example | Manually flag transactions over a fixed threshold | Learn a model that estimates transaction risk |
For example, traditional code might calculate a customer discount using explicit rules. An ML system might learn which customer characteristics are associated with purchases. Traditional programming remains preferable when the rules are known, stable and must be fully auditable.
Data Analyst Workflow
Data analysts commonly use ML as one part of a broader analytical workflow:
-
Understand the business question and define success.
-
Find, profile and clean the relevant data.
-
Explore distributions, relationships and anomalies.
-
Analyse the data and test hypotheses.
-
Visualise findings for non-technical stakeholders.
-
Communicate a recommendation and, where appropriate, build or evaluate a predictive model.
SQL, Excel or Google Sheets, Python with pandas, and BI tools such as Tableau or Power BI are commonly used. Traditional statistics remain important: ML cannot compensate for an unclear objective, biased sampling or an unsuitable evaluation metric.
Role Boundaries
| Role | Primary responsibility | Typical focus |
|---|---|---|
| Data analyst | Turn business questions into reliable findings and recommendations | SQL, spreadsheets, descriptive statistics, dashboards and lightweight analysis |
| Data scientist | Develop and evaluate models or conduct deeper experiments | ML, statistical modelling, feature engineering and model validation |
| Data engineer | Build and maintain the systems that produce and transport data | Databases, pipelines, orchestration, reliability and infrastructure |
The boundaries overlap. A data analyst may train a simple predictive model, while a data scientist may spend substantial time cleaning data and communicating results.
Interview Tips
Common mistakes include treating correlation as causation, evaluating on the training set, leaking validation information into preprocessing, and selecting an inaccurate metric. For classification, explain why accuracy can be misleading with imbalanced classes and when precision, recall, F1, ROC-AUC or PR-AUC are preferable.
Useful follow-up questions include:
-
How would you define the target variable and success metric?
-
How would you prevent data leakage?
-
Which baseline should the model outperform?
-
How would you diagnose bias, overfitting or performance degradation?
-
When would a simple rule-based solution be better than ML?