Chapter 1
Foundations of Machine Learning and Data Science
Diploma in Data science
Machine Learning for Data Science
•
Diploma
Foundations of Machine Learning and Data Science
Introduction
Data science combines statistical reasoning, computing, domain knowledge and communication to extract useful insight from data. Machine learning (ML) is one of its principal technical methods: it enables computer systems to identify patterns and make predictions or decisions from examples rather than relying entirely on explicitly programmed rules. Artificial intelligence (AI) is the broader field concerned with systems that perform tasks normally associated with human intelligence, such as perception, language understanding, planning and decision-making.
These terms overlap but are not interchangeable. AI is the broadest concept; machine learning is a major approach within AI; and data science is an interdisciplinary problem-solving discipline that may use machine learning, statistics, databases, visualization and qualitative domain knowledge. A data scientist may use a machine-learning model, but may also solve a problem through descriptive statistics or a carefully designed database query.
This chapter establishes the conceptual foundation needed for later study of regression, classification, clustering, model evaluation and deployment.
Learning Objectives
After studying this chapter, you should be able to:
distinguish AI, machine learning, deep learning, statistics and data science;
explain the main stages of a data-science and machine-learning workflow;
distinguish supervised, unsupervised, semi-supervised and reinforcement learning;
explain assumptions, generalization, overfitting, underfitting and the bias–variance trade-off;
identify suitable machine-learning applications and their limitations;
discuss professional, ethical and governance responsibilities in applied ML.
1. The Conceptual Landscape
Artificial intelligence
AI refers to the design of systems that perceive their environment, process information and produce outputs intended to achieve goals. An AI system may use rules, search, optimization, probability, machine learning or combinations of these methods. A rule-based fraud alert system, for example, can be AI even if it does not learn from data.
AI should not automatically be interpreted as human-like reasoning or consciousness. Most deployed AI is narrow AI: it performs a limited task under specified conditions. A credit-risk model, speech recognizer and route planner may all be highly capable in their domains while lacking general intelligence.
Machine learning
Machine learning studies algorithms that improve their performance on a task through experience, usually represented by data. A useful formalization is:
f̂ = A(D)
Here, D is a dataset, A is a learning algorithm and f̂ is the learned model or function. The model maps inputs to outputs, but its quality must be assessed on data not used to fit it.
A model is not simply a stored collection of examples. It is a representation of regularities that can be applied to new cases. This ability is called generalization.
Deep learning
Deep learning is a family of machine-learning methods based primarily on multilayer neural networks. It is particularly effective for unstructured or high-dimensional data such as images, audio, text and video. Deep learning is therefore a subset of ML, and ML is commonly treated as a subset of AI.
Statistics and data science
Statistics provides methods for describing uncertainty, estimating quantities, testing claims and modelling relationships. Machine learning often emphasizes predictive performance, whereas traditional statistical analysis may emphasize explanation, parameter interpretation or inference about a population. The distinction is useful but not absolute: modern practice contains substantial overlap.
Data science is a broader workflow and professional discipline. It includes problem formulation, data acquisition, cleaning, exploration, modelling, evaluation, communication and deployment. It also includes decisions about whether a predictive model is appropriate at all.
2. The Data-Science and Machine-Learning Workflow
A practical project is iterative rather than strictly linear.
Iterative data science and machine learning workflow
Figure: Iterative data science and machine learning workflow
Figure: A machine-learning workflow in which evaluation and monitoring feed back into problem definition and preparation.
Problem definition
The project begins with a decision or question, not with an algorithm. The team should specify the prediction target, the unit of analysis, the time at which predictions are made, the consequences of errors and the success metric. For example, “predict whether an account will default within 90 days” is more precise than “use AI for lending.”
Data and variables
An observation is a record about an entity or event. A feature, also called a predictor or input variable, is information used by a model. A target, label or response is the outcome to be predicted in supervised learning. A dataset is often represented as a matrix with rows as observations and columns as variables.
Categorical variables represent groups, such as payment method. Numerical variables represent quantities, such as income. Missing values, duplicate records, inconsistent units and measurement errors can substantially affect results. Data preparation may include validation, imputation, encoding, scaling and feature construction.
Training, validation and testing
A training set is used to fit model parameters. A validation set supports model selection and hyperparameter tuning. A test set provides a final estimate of performance on unseen data. The test set should remain isolated until important modelling decisions are complete.
Random splitting is not always appropriate. For time-dependent data, training should normally use earlier periods and testing later periods. For medical records or customer data, related records may need to remain in the same partition to prevent information leakage.
Deployment and monitoring
A model can perform well in a laboratory and fail in production because data distributions change, users adapt to it, upstream systems change or the target definition changes. Monitoring should cover predictive performance where labels become available, input-data quality, population drift, latency, fairness and operational outcomes.
3. Learning Paradigms
Paradigm
Training information
Typical task
Example
Supervised learning
Inputs paired with target labels
Predict or classify
Predict loan default
Unsupervised learning
Inputs without target labels
Discover structure
Customer segmentation
Semi-supervised learning
Small labelled set plus larger unlabelled set
Improve prediction with limited labels
Classify medical images
Reinforcement learning
Rewards from interaction with an environment
Learn a policy or sequence of actions
Robot navigation
Supervised learning
In supervised learning, the training data contain pairs (xi, yi), where xi is an input and yi is its target. Regression predicts a numerical quantity, such as delivery time. Classification predicts a category, such as fraudulent or legitimate.
A model is fitted by minimizing a loss function over training examples. A general empirical-risk objective is:
J(f) = (1/n) ∑ᵢ₌₁ⁿ L(f(xᵢ), yᵢ)
Here, n is the number of training examples, f is a candidate model, L is a loss function, xi is the input and yi is the observed target. This objective is appropriate when the training examples are sufficiently representative and the loss reflects the practical cost of errors.
For numerical prediction, mean squared error is often used:
MSE = (1/n) ∑ᵢ₌₁ⁿ (yᵢ − ŷᵢ)²
The units of MSE are the squared units of the target. Root mean squared error is RMSE = √MSE, which returns to the target’s units. Neither metric alone describes fairness, business value or performance on unusual cases.
Unsupervised learning
Unsupervised learning uses inputs without specified target labels. Clustering groups observations according to a similarity criterion; dimensionality reduction represents data using fewer variables; and anomaly detection identifies unusual observations. Because there is no universally correct label, evaluation often requires domain judgement, stability analysis or downstream usefulness.
In k-means clustering, each observation is assigned to one of k clusters, and the algorithm seeks to minimize within-cluster squared distance:
J = ∑ⱼ₌₁ᵏ ∑xᵢ ∈ Cⱼ ||xᵢ − μⱼ||²
Here, Cj is cluster j, μj is its centroid and ||xi − μj||² is squared Euclidean distance. The method assumes that this distance is meaningful and that compact, roughly separated clusters are suitable for the problem. It does not discover objectively true groups in every dataset.
Semi-supervised learning
Semi-supervised learning uses a small labelled dataset and a larger unlabelled dataset. It is useful when labels require costly expert work but unlabelled examples are abundant. Its assumptions must be examined carefully: unlabelled data should usually come from a relevant distribution, and the structure inferred from them should help predict the target. Poor assumptions or systematic differences between labelled and unlabelled cases can reduce performance.
Reinforcement learning
In reinforcement learning, an agent observes a state, chooses an action and receives a reward from an environment. It learns a policy that maps states to actions. Unlike supervised learning, the system is not normally given the correct action for each situation; it receives feedback that may be delayed.
Important concepts include state, action, reward, policy, episode and exploration. Exploration tries actions whose consequences are uncertain; exploitation chooses actions currently believed to be effective. A reward function is a specification of what the system optimizes, so an incomplete reward can produce undesirable behaviour.
4. Assumptions and Generalization
A machine-learning model does not learn without assumptions. Common assumptions include:
Representativeness: training examples provide relevant information about future cases.
Independence or appropriate dependence structure: observations are not treated as independent when they are actually repeated measurements, family-linked records or time series.
Stable target definition: the meaning of the outcome remains sufficiently consistent.
Informative features: inputs contain signal related to the target and are available at prediction time.
Suitable measurement: variables are recorded with enough accuracy for the decision.
These assumptions are often more important than the choice between two similar algorithms. A random train–test split can produce misleading results if a feature contains information recorded after the outcome, a problem known as target leakage.
Overfitting and underfitting
Underfitting occurs when a model is too limited to represent important structure. It tends to perform poorly on both training and unseen data. Overfitting occurs when a model captures noise or accidental details of the training sample. It may have excellent training performance but poor performance on new data.
Generalization error is the expected loss on future cases from the relevant population. It cannot be known exactly, so it is estimated using validation, testing and, where appropriate, cross-validation.
Bias–variance trade-off
For a regression problem with squared-error loss, prediction error can be conceptualized as:
Here, Y is the random target, f̂(x) is the fitted prediction at input x, bias is systematic error in the average prediction, variance is sensitivity of the fitted model to the training sample and σ² is irreducible noise under the model of the data. The decomposition assumes a fixed input, squared loss and a probabilistic data-generating process.
A simple model may have high bias and low variance; a highly flexible model may have low bias and high variance. Increasing complexity does not guarantee better test performance. Regularization, more representative data, feature selection, early stopping and cross-validation can help manage the trade-off.
Regularized objectives add a penalty to discourage excessive complexity. For example, ridge regression uses:
Here, β₀ is the intercept, βj are coefficients, p is the number of features and λ ≥ 0 controls the penalty. Variables should generally be scaled when coefficient penalties are compared across features. The penalty changes the fitting objective; it does not create information absent from the data.
5. Applications Across Industry
Machine learning is used in many sectors:
Finance: credit-risk estimation, fraud detection, anti-money-laundering alerts and customer service automation.
Health care: image assistance, risk stratification and resource planning. Clinical use requires validation, safety controls and professional oversight.
Manufacturing: predictive maintenance, visual quality inspection and process optimization.
Retail and media: demand forecasting, recommendation and customer segmentation.
Transport and logistics: routing, estimated arrival times and fleet maintenance.
Public services: workload forecasting and anomaly detection, subject to legal and fairness constraints.
Cybersecurity: detection of unusual access patterns and malicious activity.
The appropriate question is not “Can machine learning be used?” but “Does a data-driven model improve a clearly defined decision, with acceptable risk and cost?” A transparent baseline, such as a rule or simple statistical model, should normally be compared with a more complex model.
A fictional streaming company, StreamNow, observes that cancellations increase after repeated service interruptions. Management wants to identify customers at high risk of cancellation within the next 30 days so that support teams can offer assistance. The proposed system must not penalize customers unfairly or use information unavailable when an intervention would be made.
Analysis
The data team defines one observation as a customer-week. Candidate features include recent interruption count, usage frequency, subscription age, support contacts and payment history. The target is whether the customer cancels within the following 30 days. Because records are temporal, the team uses earlier months for training, a later month for validation and the most recent month for testing.
The team checks for leakage. A “cancellation-request date” would reveal the outcome and must not be used. It also checks whether support-contact counts differ because some customers have easier access to support, which could introduce unequal treatment.
Approach and solution
A simple logistic-regression baseline is compared with a tree-based model. Performance is assessed using recall, precision, calibration and the cost of unnecessary interventions. If TP denotes correctly identified cancellations, FP false alerts, FN missed cancellations and TN correctly identified non-cancellations, then:
Precision = TP ÷ (TP + FP)
Recall = TP ÷ (TP + FN)
Precision measures the proportion of alerts that are correct; recall measures the proportion of actual cancellations detected. These metrics are defined when their denominators are non-zero. The company should choose a threshold in relation to intervention capacity and the relative costs of false alerts and missed cases.
The model is calibrated so that predicted probabilities correspond reasonably to observed frequencies. Staff receive an explanation of influential factors and a process for correcting inaccurate records. The system supports—not replaces—customer-service judgement.
Outcome and learning points
In this illustrative case, the model improves targeting over a broad untargeted campaign, but it is not treated as a guarantee that a customer will cancel. Monitoring is established for changes in customer behaviour, missing data, performance by relevant groups and intervention outcomes. The central lesson is that success depends on problem definition, valid temporal evaluation, operational design and responsible governance, not merely on model accuracy.
7. Ethical, Legal and Professional Considerations
Data scientists are responsible for more than technical performance. Important risks include privacy violations, unauthorized secondary use, discriminatory outcomes, insecure data, opaque decisions and automation bias. Sensitive attributes may be excluded from a model yet their proxies—such as location or purchasing history—may preserve unequal effects.
Good practice includes data minimization, lawful and transparent data use, access controls, retention limits, documentation, reproducible analysis, representative evaluation and human review for high-impact decisions. Teams should document the intended use, known limitations, training data, evaluation design and monitoring plan. Consent, privacy and anti-discrimination obligations depend on jurisdiction and application, so legal and compliance expertise should be involved where appropriate.
Explainability has several meanings: a global description of model behaviour, an explanation of an individual prediction, or a simpler model that is inherently interpretable. An explanation is useful only if it is faithful to the model and understandable to its audience. It should not be used to disguise poor data quality or unjustified decisions.
8. Contemporary Developments and Best Practice
Current practice increasingly includes foundation models, generative AI, automated machine learning, federated learning and responsible-AI evaluation. These technologies expand capability but do not remove fundamental issues of data quality, evaluation, security or accountability. Generative systems may produce fluent but incorrect outputs; their use therefore requires verification, access controls and clearly defined human responsibility.
For diploma-level practice, the following habits are especially valuable:
Begin with a measurable decision and a defensible target.
Establish a simple baseline before adopting a complex model.
Separate training, validation and testing data correctly.
Prevent leakage and respect time, groups and dependence in the data.
Select metrics that reflect consequences, not convenience.
Examine errors across relevant populations and operating conditions.
Record assumptions, transformations, versions and decisions.
Monitor deployed systems and define retraining or shutdown criteria.
Communicate uncertainty and limitations plainly.
Treat privacy, security, fairness and human oversight as design requirements.
Chapter Summary
Artificial intelligence is the broad field of goal-directed intelligent systems; machine learning is an approach in which models learn patterns from data; deep learning uses multilayer neural networks; and data science integrates statistical, computational and domain methods across a complete data-to-decision workflow. Supervised learning uses labelled examples, unsupervised learning discovers structure without target labels, semi-supervised learning combines labelled and unlabelled data, and reinforcement learning learns actions through rewards.
Machine learning depends on assumptions about data, measurement, target definitions and future stability. Generalization is the ability to perform on new cases. Underfitting reflects excessive simplicity, while overfitting reflects excessive sensitivity to training data. The bias–variance framework explains why both systematic error and instability matter. Effective professional practice combines appropriate modelling with valid evaluation, monitoring, ethical governance, privacy protection and clear communication.
Key Terms
Artificial intelligence: The field of systems that perform tasks associated with intelligent behaviour.
Machine learning: Methods that learn patterns or decision rules from data.
Deep learning: Machine learning based mainly on multilayer neural networks.
Data science: An interdisciplinary process for obtaining insight and supporting decisions with data.
Feature: An input variable used by a model.
Target: The outcome a supervised model is trained to predict.
Observation: A recorded case, entity or event in a dataset.
Supervised learning: Learning from input–target pairs.
Unsupervised learning: Learning structure from inputs without specified targets.
Semi-supervised learning: Learning from both labelled and unlabelled examples.
Reinforcement learning: Learning actions through rewards from interaction with an environment.
Generalization: Performance on relevant unseen cases.
Overfitting: Fitting noise or sample-specific details rather than general patterns.
Underfitting: Failure to represent important structure because a model is too limited.
Bias: Systematic error in average predictions.
Variance: Sensitivity of a fitted model to the training sample.
Data leakage: Use of information during training that would not be available at prediction time.
Precision: The proportion of positive predictions that are correct.
Recall: The proportion of actual positive cases that are detected.
Model drift: Degradation or change caused by evolving data, relationships or operating conditions.
Review Questions
Short Answer Questions
Distinguish artificial intelligence, machine learning and data science.
What is the difference between a feature and a target?
Why should a test set remain isolated during model development?
Define overfitting and underfitting.
State one suitable application of each of the four learning paradigms.
Long Answer Questions
Explain the stages of a machine-learning workflow, including why the workflow is iterative.
Compare supervised, unsupervised, semi-supervised and reinforcement learning, with examples.
Explain the bias–variance trade-off and describe two methods for managing it.
Discuss why data assumptions can matter more than algorithm selection.
Explain the ethical and governance responsibilities involved in deploying a model for a high-impact decision.
Analytical / Application Questions
A bank has 50,000 unlabelled transaction records but only 1,000 records reviewed by fraud experts. Which learning paradigm could be considered, and what assumptions and risks should be examined?
A model has excellent training accuracy but poor performance on a later time period. Diagnose at least three possible causes and propose a revised evaluation approach.
A customer-retention system produces many alerts, but support staff can contact only 5% of customers. Which performance measures and operational information should guide the alert threshold?
Multiple Choice Questions with Answers
Question 1
Which statement best describes the relationship among AI, machine learning and deep learning?
A. AI is a subset of machine learning, which is a subset of deep learning.
B. Machine learning is a broad field unrelated to AI.
C. Deep learning is a subset of machine learning, which is commonly treated as a subset of AI.
D. Deep learning and AI are identical terms.
Correct Answer: C. Deep learning is a subset of machine learning, which is commonly treated as a subset of AI.
Question 2
Which learning paradigm uses input examples paired with known target values?
A. Supervised learning
B. Unsupervised learning
C. Reinforcement learning
D. Exploratory visualization
Correct Answer: A. Supervised learning
Question 3
A dataset contains customer records but no outcome labels. Which task is most directly unsupervised?
A. Predicting next month’s revenue
B. Grouping customers by similarity
C. Predicting whether a customer will cancel
D. Learning an action from rewards
Correct Answer: B. Grouping customers by similarity
Question 4
What is the main purpose of a test set?
A. To create additional labels
B. To tune every hyperparameter repeatedly
C. To provide a final estimate on unseen data
D. To replace problem definition
Correct Answer: C. To provide a final estimate on unseen data
Question 5
A model performs very well on training data but poorly on new data. What is the most likely problem?
A. Underfitting
B. Overfitting
C. Clustering
D. Data normalization only
Correct Answer: B. Overfitting
Question 6
In the bias–variance trade-off, variance describes a model’s:
A. Sensitivity to the particular training sample
B. Average systematic error only
C. Number of target categories
D. Amount of missing data
Correct Answer: A. Sensitivity to the particular training sample
Question 7
Which situation is an example of target leakage?
A. Using an input measured before prediction
B. Splitting data by time
C. Using a cancellation-request date to predict cancellation
D. Scaling numerical features
Correct Answer: C. Using a cancellation-request date to predict cancellation
Question 8
Recall is calculated as:
A. TP ÷ (TP + FP)
B. TP ÷ (TP + FN)
C. TN ÷ (TN + FP)
D. (TP + TN) ÷ total observations
Correct Answer: B. TP ÷ (TP + FN)
Question 9
What distinguishes reinforcement learning from ordinary supervised learning?
A. It never uses data.
B. It learns actions through interaction and rewards rather than being given the correct action for every case.
C. It can only solve clustering problems.
D. It requires every input to have a human-provided label.
Correct Answer: B. It learns actions through interaction and rewards rather than being given the correct action for every case.
Question 10
Why might a random train–test split be inappropriate for time-dependent data?
A. It always reduces the dataset to one observation.
B. It can allow information from the future to influence evaluation of the past.
C. It prevents numerical variables from being used.
D. It automatically causes underfitting.
Correct Answer: B. It can allow information from the future to influence evaluation of the past.