Skip to main content
CBE Nexus · Undergraduate Computer Science

Chapter 13: Machine Learning and Data Science

Undergraduate machine learning and data science notes on data preparation, probability, regression, classification, clustering, validation, feature engineering, neural networks, evaluation and responsible data practice.

Back to Computer Science course guide

Chapter overview and learning outcomes

This chapter develops the theory and practical foundations of machine learning and data science, linking core concepts to the design, evaluation and responsible operation of computing systems.

1. Data science lifecycle and problem framing

Data science combines domain knowledge, statistics, computing and communication to extract useful insight from data. A project begins with a decision or question, not an algorithm. Define the target population, unit of analysis, outcome, constraints and success measure. The lifecycle includes acquisition, understanding, preparation, exploration, modelling, evaluation, communication and monitoring. A technically accurate model may still be unsuitable if it answers the wrong question or cannot be used responsibly.

Applied study: Work through a realistic scenario from the domain. Identify the assumptions, constraints, relevant stakeholders and expected outcome. Explain the reasoning behind a proposed method, compare it with at least one alternative, and discuss reliability, security, performance, ethical implications and limitations.

Learning activity: Prepare a labelled model or worked example, define how you would test it, and write a short reflection on what evidence would change your conclusion.

2. Data types, collection and data quality

Data may be numerical, categorical, ordinal, textual, temporal, spatial, image or graph-based. Collection methods include surveys, experiments, sensors, administrative systems and public datasets. Quality dimensions include accuracy, completeness, consistency, validity, timeliness and uniqueness. Missingness may be random or systematic; duplicates and measurement errors can distort conclusions. Record provenance, collection methods, definitions and limitations. Assess whether data are representative of the intended population and lawful to use.

Applied study: Work through a realistic scenario from the domain. Identify the assumptions, constraints, relevant stakeholders and expected outcome. Explain the reasoning behind a proposed method, compare it with at least one alternative, and discuss reliability, security, performance, ethical implications and limitations.

Learning activity: Prepare a labelled model or worked example, define how you would test it, and write a short reflection on what evidence would change your conclusion.

3. Descriptive statistics and exploratory analysis

Descriptive statistics summarise data using counts, proportions, mean, median, mode, range, variance, standard deviation and quantiles. The mean is sensitive to extreme values; the median is more robust for skewed distributions. Visualisations such as histograms, box plots, scatter plots and time-series charts reveal shape, outliers and relationships. Exploratory analysis generates hypotheses but does not by itself establish causation. Avoid misleading axes, inappropriate aggregation and unreported exclusions.

Applied study: Work through a realistic scenario from the domain. Identify the assumptions, constraints, relevant stakeholders and expected outcome. Explain the reasoning behind a proposed method, compare it with at least one alternative, and discuss reliability, security, performance, ethical implications and limitations.

Learning activity: Prepare a labelled model or worked example, define how you would test it, and write a short reflection on what evidence would change your conclusion.

4. Probability and statistical inference

Probability quantifies uncertainty and supports reasoning about events. Conditional probability describes the chance of an event given another event; Bayes' theorem updates beliefs using evidence. Sampling distributions explain how statistics vary across samples. Confidence intervals describe uncertainty under specified assumptions; p-values quantify how incompatible data are with a null model, not the probability that a hypothesis is true. Statistical inference requires attention to sampling design, dependence, multiple testing and practical significance.

Applied study: Work through a realistic scenario from the domain. Identify the assumptions, constraints, relevant stakeholders and expected outcome. Explain the reasoning behind a proposed method, compare it with at least one alternative, and discuss reliability, security, performance, ethical implications and limitations.

Learning activity: Prepare a labelled model or worked example, define how you would test it, and write a short reflection on what evidence would change your conclusion.

5. Data preparation and feature engineering

Preparation may involve cleaning, encoding categories, scaling numerical features, handling missing values, parsing dates, transforming skewed variables and selecting relevant predictors. Feature engineering uses domain understanding to create informative representations. All transformations must be fitted using training data only when evaluating predictive performance, then applied consistently to validation and test data. This prevents leakage. Preserve a reproducible pipeline and document decisions so that results can be independently checked.

Applied study: Work through a realistic scenario from the domain. Identify the assumptions, constraints, relevant stakeholders and expected outcome. Explain the reasoning behind a proposed method, compare it with at least one alternative, and discuss reliability, security, performance, ethical implications and limitations.

Learning activity: Prepare a labelled model or worked example, define how you would test it, and write a short reflection on what evidence would change your conclusion.

6. Regression methods and prediction

Regression predicts a numerical outcome. Linear regression models a conditional mean as a combination of predictors and coefficients. Coefficients require interpretation in relation to units, other variables and model assumptions. Nonlinear patterns may need transformations, interactions or other models. Evaluate prediction using metrics such as mean absolute error, mean squared error and root mean squared error, selected according to the task. Inspect residuals, influential observations and performance across relevant subgroups.

Applied study: Work through a realistic scenario from the domain. Identify the assumptions, constraints, relevant stakeholders and expected outcome. Explain the reasoning behind a proposed method, compare it with at least one alternative, and discuss reliability, security, performance, ethical implications and limitations.

Learning activity: Prepare a labelled model or worked example, define how you would test it, and write a short reflection on what evidence would change your conclusion.

7. Classification and probabilistic prediction

Classification predicts categories, such as disease status or transaction risk. Models include logistic regression, decision trees, random forests, support vector machines and neural networks. A decision threshold converts scores or probabilities into classes and should reflect the costs of false positives and false negatives. Confusion matrices support calculation of precision, recall, specificity and F1. For imbalanced data, accuracy alone can be misleading. Calibration matters when predicted probabilities inform decisions.

Applied study: Work through a realistic scenario from the domain. Identify the assumptions, constraints, relevant stakeholders and expected outcome. Explain the reasoning behind a proposed method, compare it with at least one alternative, and discuss reliability, security, performance, ethical implications and limitations.

Learning activity: Prepare a labelled model or worked example, define how you would test it, and write a short reflection on what evidence would change your conclusion.

8. Unsupervised learning and clustering

Unsupervised methods explore data without a supplied target label. Clustering groups observations according to a similarity measure. K-means partitions data into a chosen number of clusters and is sensitive to scaling, initialisation and outliers. Hierarchical clustering builds nested groupings; density-based approaches can identify irregular clusters and noise. Dimensionality reduction methods such as principal component analysis summarise variation. Clusters require interpretation and external validation before being treated as meaningful categories.

Applied study: Work through a realistic scenario from the domain. Identify the assumptions, constraints, relevant stakeholders and expected outcome. Explain the reasoning behind a proposed method, compare it with at least one alternative, and discuss reliability, security, performance, ethical implications and limitations.

Learning activity: Prepare a labelled model or worked example, define how you would test it, and write a short reflection on what evidence would change your conclusion.

9. Model validation, generalisation and selection

A model should be evaluated on data that were not used to fit or tune it. Train-validation-test splits support model development; cross-validation estimates performance across repeated partitions. Time-dependent data require chronological splits to avoid training on future information. Hyperparameter tuning should not repeatedly use the final test set. Compare against simple baselines, quantify uncertainty and inspect subgroup performance. Monitor distribution shift after deployment because real-world data may change.

Applied study: Work through a realistic scenario from the domain. Identify the assumptions, constraints, relevant stakeholders and expected outcome. Explain the reasoning behind a proposed method, compare it with at least one alternative, and discuss reliability, security, performance, ethical implications and limitations.

Learning activity: Prepare a labelled model or worked example, define how you would test it, and write a short reflection on what evidence would change your conclusion.

10. Neural networks, ensembles and advanced methods

Neural networks learn layered representations through optimisation of a loss function. Ensembles combine models: bagging reduces variance through parallel fits, while boosting builds sequential learners to address errors. These methods can improve predictive performance but increase computational cost and complexity. Interpretability tools can help investigate model behaviour, yet explanations are approximations and may be unstable. Choose model complexity according to data volume, deployment constraints and the consequences of error.

Applied study: Work through a realistic scenario from the domain. Identify the assumptions, constraints, relevant stakeholders and expected outcome. Explain the reasoning behind a proposed method, compare it with at least one alternative, and discuss reliability, security, performance, ethical implications and limitations.

Learning activity: Prepare a labelled model or worked example, define how you would test it, and write a short reflection on what evidence would change your conclusion.

11. Communication, reproducibility, ethics and deployment

A data-science report should explain the question, data source, methods, assumptions, uncertainty, results and limitations in accessible language. Reproducibility requires versioned code, documented environments, recorded parameters and controlled data access. Ethical practice includes privacy, consent or other lawful basis, fairness, transparency, security and minimising harm. Deployment needs monitoring for drift, performance decay and unintended impacts. A model should have an owner, review schedule and process for withdrawal or retraining.

Applied study: Work through a realistic scenario from the domain. Identify the assumptions, constraints, relevant stakeholders and expected outcome. Explain the reasoning behind a proposed method, compare it with at least one alternative, and discuss reliability, security, performance, ethical implications and limitations.

Learning activity: Prepare a labelled model or worked example, define how you would test it, and write a short reflection on what evidence would change your conclusion.

Figure 1. Data science workflow
Frame question and success measure→Acquire and assess data→Prepare and explore→Train and validate model→Communicate and monitor

Conceptual diagram for learning and revision.

Figure 2. Model evaluation split
Training data fit parameters→Validation data tune choices→Test data estimate generalisation→Monitor deployment drift

Conceptual diagram for learning and revision.

Figure 3. Classification assessment
Predicted labels and scores→Confusion matrix→Precision, recall and F1→Threshold chosen for decision costs

Conceptual diagram for learning and revision.

Practical laboratory or project activity

  1. Choose a bounded problem relevant to this chapter and state its purpose.
  2. Identify inputs, outputs, constraints, assumptions and potential failure cases.
  3. Develop a small model, prototype, experiment or worked analysis.
  4. Use appropriate tools and authorised datasets or test environments.
  5. Test normal, boundary and failure conditions; record reproducible observations.
  6. Write a report explaining method, evidence, limitations and recommendations.

Follow institutional rules, protect private information and obtain permission before testing systems or collecting data.

Worked reasoning and self-assessment

Start by translating the question into a precise problem statement. Define variables and assumptions before calculating or implementing. Work through a small example manually, then verify it with an appropriate tool. Explain why the selected approach is suitable, identify an alternative, and discuss its trade-offs. For empirical claims, describe the data and method needed to support them; for system claims, specify observable tests and expected outcomes.

Examination and revision questions

Answer using precise definitions, diagrams, calculations and examples where appropriate.

  1. What is the data science lifecycle?

    Show answer guidance

    Problem framing, data acquisition, preparation, exploration, modelling, evaluation, communication and monitoring.

  2. Differentiate population and sample.

    Show answer guidance

    A population is the full group of interest; a sample is the subset observed.

  3. When is the median preferable to the mean?

    Show answer guidance

    For skewed distributions or data with influential extreme values.

  4. What does a confidence interval express?

    Show answer guidance

    An interval procedure's uncertainty about a population parameter under stated assumptions.

  5. What is feature engineering?

    Show answer guidance

    Creating or transforming input variables to better represent useful information for a model.

  6. Differentiate regression and classification.

    Show answer guidance

    Regression predicts numerical outcomes; classification predicts categories.

  7. What is overfitting?

    Show answer guidance

    A model fits training data too closely and generalises poorly to new observations.

  8. Why use cross-validation?

    Show answer guidance

    To estimate model performance across multiple training and validation partitions.

  9. What is data leakage?

    Show answer guidance

    Information unavailable at prediction time improperly influences training or evaluation.

  10. Define precision.

    Show answer guidance

    The proportion of predicted positive cases that are truly positive.

  11. Define recall.

    Show answer guidance

    The proportion of actual positive cases correctly identified.

  12. What is clustering?

    Show answer guidance

    Grouping observations based on similarity without supplied target labels.

  13. Why scale features for some algorithms?

    Show answer guidance

    Distance- or gradient-based methods may be dominated by variables with larger numeric ranges.

  14. What is model drift?

    Show answer guidance

    A change in data or relationships that causes deployed model performance to deteriorate.

  15. Name two responsible data-science principles.

    Show answer guidance

    Privacy, fairness, transparency, accountability, security and minimisation of harm.

Revision checklist

Further study and academic references

Consult current university textbooks, peer-reviewed conference and journal papers, official standards and authoritative technical documentation. Verify versions and publication details before citing sources. Use the citation style required by your institution, cite data and software as well as written sources, and distinguish published evidence from your own analysis. Do not invent references, measurements or experimental outcomes.

Academic and responsible-use note: These notes support undergraduate study and do not replace your institution's course outline, laboratory rules or supervisor guidance. Respect privacy, intellectual property, licences, research ethics and applicable law.

Return to the full Computer Science course guide

Official Education References

Use these official organisations for curriculum guidance, examinations and further learning information.