Chapter 1 — Introduction to Machine Learning
Learning from data
1 Chapter overview
Machine learning has become an important approach for analysing data, making predictions, and developing intelligent systems. This chapter introduces the basic idea of learning from examples. We first distinguish machine learning from conventional programming and explain how training differs from using a trained model. We then examine applications built around input–output pairs and use a binary image-classification problem to illustrate how a simple model learns. Finally, we discuss the interdisciplinary nature of machine learning, its historical development, practical applications and societal challenges.
1.1 Learning objectives
By the end of this chapter, you should be able to:
- Explain machine learning as a method for learning useful relationships from data.
- Distinguish traditional programming, model training, inference, and evaluation.
- Recognize possible learning problems by identifying inputs, outputs, and suitable examples.
- Describe, at a conceptual level, how a simple binary image classifier learns from classification errors.
- Identify applications of machine learning across different disciplines and data types.
- Discuss the opportunities, limitations, and societal implications of machine-learning systems.
2 What is machine learning?
2.1 What is Machine Learning?
Machine learning (ML) enables computers to learn useful patterns from examples and apply those patterns to new situations. Instead of prescribing every decision through explicit instructions, we construct a model whose behaviour is determined, at least in part, by data. This approach is especially useful when the relationships we want to describe are difficult to express as a short list of rules. Examples include recognizing objects in photographs, interpreting spoken language, recommending products, and detecting anomalies in sensor measurements.
Learning from data does not mean that a machine develops human understanding or that it can answer any question correctly. It means that a computational procedure adjusts a model using evidence provided by examples. The central question in this chapter is therefore straightforward: what information is available, what do we want to predict, and how can examples help us make that prediction?
2.2 Algorithms that Learn from Data
A useful starting definition is:
Machine learning consists of algorithms that can learn from data.
Consider photographs of buildings. A conventional image-processing program could identify damage using thresholds for colour, line orientation, or geometric shape that an engineer specifies in advance. A machine-learning approach could instead use many labeled photographs to adjust its parameters until it recognizes visual patterns associated with damage. The result is not a list of hand-written conditions but a model learned from examples.
A model does not simply store all the examples it has seen. The aim is to capture relationships that remain useful when presented with previously unseen observations. This ability to make useful predictions beyond the training examples is called generalization; we will study it more formally in a later chapter.
2.3 Traditional programming versus learning
In traditional programming, an engineer specifies the rules and the computer applies them to input data. For instance, an automated building-control system might use the rule: if the measured temperature exceeds \(25^\circ\mathrm{C}\), raise the blind; otherwise, lower it. The input is the temperature, the rule is explicit, and the output is the action.
In supervised machine learning, the starting information is different. We collect temperatures together with the desired blind actions and allow a learning algorithm to estimate a rule from those pairs. Instead of entering a threshold ourselves, we ask the model to infer an appropriate decision boundary from the examples. The learned rule is usually encoded in numerical parameters, often denoted by \(\mathbf w\).
Both approaches process data. Their key distinction is whether the decision rule is specified by the programmer or inferred from training examples. The learned rule may still be evaluated and implemented as an ordinary program once training is complete.
2.4 Training and inference
Training and inference are different operations. During training, we provide input examples and their known desired outputs, called targets or labels. A learning algorithm uses them to adjust the model parameters. We can represent the training dataset as
\[\mathcal D=\{(\mathbf x_i,y_i)\}_{i=1}^{n},\]
where \(\mathbf x_i\) is an input and \(y_i\) is its target. The trained model is a function \(f(\mathbf x;\mathbf w)\) whose behaviour depends on the learned parameter vector \(\mathbf w\).
During inference, the model receives a new input \(\mathbf x_{\mathrm{new}}\) and produces a prediction \(\hat y=f(\mathbf x_{\mathrm{new}};\mathbf w)\). Its correct target does not need to be available.
Evaluation is a separate activity: we compare predictions with known labels, ideally on data not used for training, to measure performance.
Training answers how do we estimate a model? Inference answers what does the trained model predict? Evaluation answers how reliable are those predictions?
3 Learning from input–output examples
3.1 Learning functions from data — examples
The most useful way to recognize a machine-learning problem is often to identify two related kinds of information: an input \(\mathbf x\) and a desired output \(y\). A collection of matched examples \((\mathbf x,y)\) provides the evidence from which we can learn a mapping.
An image can serve as input and an object category as output; that is an image-classification task. A sentence in French and a sentence conveying the same meaning in English form a training pair for machine translation. An audio recording paired with its transcription provides training data for speech recognition. An image paired with a natural-language description supports image captioning. A sequence of words followed by its next word supports text prediction.
The pairing matters. Thousands of unrelated sentences in two languages do not convey the same direct translation as thousands of matched sentence pairs. Similarly, an image dataset without reliable labels cannot directly support the same supervised task as a labeled dataset. Before selecting an algorithm, we should identify what can realistically be learned from the available evidence.
Outputs do not need to be single numerical measurements or simple class labels. A search engine can learn to produce a ranking of webpages for a query. A recommender system can propose items likely to interest a user, using previous interactions as inputs. In medical imaging, an image can be mapped to a diagnostic category (classification) or a region of interest (segmentation). In lip reading, video frames can be paired with spoken words. In text and media generation, the output itself can be a new sequence, image, or video.
These tasks look very different, but each raises the same basic questions: what is known at prediction time, what is the desired result, and which examples allow the relationship to be learned? Availability alone is not enough; the pairs must be relevant, correctly matched, and appropriate for the intended application.
4 A first classification model
4.1 Binary classification: damaged buildings
Imagine that we want to distinguish photographs of damaged buildings from photographs of undamaged buildings. We begin with a collection of images whose labels are already known. Each image corresponds to one example; its label indicates one of two possible classes.
The task is called binary classification because the output is a choice between two categories. During training, the classifier uses labeled examples to determine a decision rule. Once trained, it receives a photograph that it has not seen before and predicts one of the two classes.
Overall, an input image can be represented numerically, the model is adjusted using training examples, and this model will assign the image to a class. These same conceptual steps apply to many other binary classification problems.
4.2 Representing images as vectors
A digital image is a grid of numbers. For a grayscale image of height \(H\) and width \(W\), each pixel contributes one numerical value. Reading those values row by row creates a vector
\[\mathbf x=(x_1,x_2,\ldots,x_d)^\top \in\mathbb R^d,\qquad d=H W.\]
For a \(1000\times1000\) grayscale image, \(d=10^6\): a single image is represented by one million numerical features. An RGB image normally contains three values per pixel, so the vector would have \(3HW\) entries. Normalizing pixel values may make numerical training more convenient, but does not change the underlying idea.
A binary classifier treats each image as a point in this feature space. Although we usually draw the points in two dimensions, image vectors can occupy millions of dimensions. The aim is to find a decision boundary that places the two classes on different sides. A straight line is a boundary in two dimensions; its higher-dimensional counterpart is a hyperplane.
4.3 The learning algorithm: dot products and updates
A particularly simple binary classifier uses a vector of weights \(\mathbf w\). For an input vector \(\mathbf x\), it computes the score
\[s(\mathbf x)=\mathbf w^\top\mathbf x=\sum_{j=1}^{d}w_jx_j.\]
With class labels \(y\in\{-1,+1\}\), the prediction can be defined as \(\hat y=\operatorname{sign}(s(\mathbf x))\); a score of zero requires a tie-breaking convention. Here we use a hyperplane through the origin for simplicity. A more general linear classifier adds a bias \(b\) and uses \(s(\mathbf x)=\mathbf w^\top\mathbf x+b\).
How can the weights improve? Suppose the classifier makes a mistake on a labeled example \((\mathbf x_i,y_i)\). One elementary update is
\[\boxed{\mathbf w\leftarrow\mathbf w+\lambda y_i\mathbf x_i,}\]
where \(\eta>0\) is a learning rate controlling the update magnitude. For a positive example that was wrongly placed on the negative side, we add a fraction of its vector; for a negative example wrongly placed on the positive side, we subtract a fraction. Repeating this procedure produces the perceptron learning algorithm. Its prediction and update are composed of elementary vector operations, with computational cost proportional to the number of features \(d\) per example.
This rule can be related to stochastic subgradient updates for an appropriate perceptron loss. Not every mistake is guaranteed to improve all other examples, and perfectly separating the entire dataset may be impossible. What matters for this introductory illustration is that prediction errors supply a signal for changing the model.
5 Machine Learning as an Interdisciplinary Field
Machine learning is an interdisciplinary field that draws knowledge and methods from several areas, including artificial intelligence, computer science, statistics, and data mining. The boundaries between these fields are not always clearly defined, as they have developed through overlapping research traditions with different objectives and perspectives.
Computer science contributes algorithms, computational tools, and software systems, while statistics provides principles for handling variability, estimation, and uncertainty. Application domains contribute relevant research questions, practical constraints, and criteria for evaluating the usefulness of predictions. Artificial intelligence (AI) has traditionally represented the broader ambition of developing systems capable of intelligent behaviour, whereas machine learning focuses on algorithms that learn from data. However, the success of learning-based systems has brought AI and ML closer together in many modern applications, even though they remain conceptually distinct.
The relationship between machine learning and neuroscience provides another interesting perspective. The term artificial neural network is inspired by biological neural systems, but artificial networks and living brains operate differently. A simple artificial neuron combines numerical inputs through weighted operations, whereas biological neurons communicate through much more complex electrical, chemical, and structural mechanisms. Nevertheless, both machine learning and neuroscience study systems capable of adapting to experience. Comparing these systems raises interesting scientific questions about learning, representations, and behaviour, although the similarities should not be interpreted as evidence that artificial neural networks reproduce the mechanisms of the human brain.

This interdisciplinary nature also influences the skills required to develop and apply machine learning successfully. Software engineers contribute reliable computational infrastructure, statistical specialists evaluate evidence and uncertainty, and domain experts help formulate meaningful questions, identify plausible prediction targets, and recognize practical constraints and potential failure modes. Combining these complementary skills is particularly important in engineering, where successful machine learning applications require both computational expertise and an understanding of the physical systems being studied.
6 Why Machine Learning Matters
Machine learning is often associated with major technology companies such as Google, Amazon, and Meta. Their search engines, recommendation systems, and digital services are familiar examples of data-driven technologies. However, the potential of machine learning extends far beyond businesses that were digital from the beginning.
Many sectors—including construction, agriculture, manufacturing, transportation, logistics, healthcare, and public services—have traditionally relied on physical processes, manual observations, and records that were not readily available in digital form. As these activities become increasingly digitized, they create new opportunities to collect information, identify patterns, and support decisions using machine learning.
A similar transformation is taking place across scientific disciplines. Psychology, economics, medicine, and the social sciences increasingly use digital measurements, large datasets, and computational analysis to investigate questions that were previously difficult to study at scale. This broader shift is sometimes described as the digitalization of a discipline: the development of data-driven approaches to complement its established knowledge, theories, and methods. Machine learning is one set of tools that can contribute to this transformation, rather than a replacement for scientific reasoning or domain expertise.
Civil engineering provides a useful example. Information about infrastructure can be collected throughout the entire life cycle of an asset, from planning and design to construction, operation, maintenance, and eventually deconstruction or reuse. Digital models, inspection images, monitoring sensors, construction records, and operational data can help engineers understand the condition and performance of structures. Machine learning can then support particular tasks, such as identifying defects in inspection images, predicting deterioration, assessing construction progress, or estimating future maintenance needs. The value of these applications depends not simply on adopting a new algorithm, but on having relevant, reliable information and a well-defined engineering question.

6.1 Machine learning is only one part of a larger workflow
Machine learning is important, but it should not be confused with the whole data-driven process. In practice, work usually begins in the real world, where observations, measurements, and records are produced by physical systems, human activities, and operational processes. These raw observations must first be collected. After that, they are processed and organized into a form that can be used reliably. Only then do we obtain clean data, which is suitable for systematic analysis.
At this stage, several activities can happen. Clean data may be studied through exploratory data analysis, which helps us understand distributions, trends, anomalies, and relationships in the data before formal modelling. Clean data can also be used to develop machine learning algorithms and statistical models. This is the stage that often receives the most attention, but it is only one component of the larger pipeline.
The results of analysis and modelling must then be turned into something useful. They may support the creation of a data product, such as a predictive tool, a monitoring system, or a decision-support application. They must also be communicated through visualizations, reports, and findings so that people can interpret the results and act on them. These outputs ultimately support decision-making.
An important final point is that this process forms a feedback loop. Decisions and products influence the real world, and the real world in turn generates new data. For this reason, good machine-learning practice requires more than model training alone: it requires careful data collection, preparation, analysis, communication, and continued evaluation after deployment. This broader perspective is especially important in engineering applications, where safety, reliability, and accountability are essential.
7 Origins, Growth, and Challenges
The idea of learning from data is not new. Long before the development of modern machine learning algorithms, scientists were already using observations, measurements, and patterns in data to investigate complex problems. A well-known example is the 1854 cholera outbreak in London, investigated by physician John Snow. By mapping the geographical distribution of cholera deaths in the Soho district, Snow identified a concentration of cases near the Broad Street water pump. This observation, together with further investigation, provided evidence that contaminated water was responsible for the outbreak. Although this was not machine learning in the modern sense, it illustrates a fundamental principle of data-driven analysis: patterns in data can help us formulate hypotheses, identify relationships, and make better-informed decisions.

The foundations of modern artificial intelligence and machine learning began to take shape during the middle of the twentieth century. In 1950, Alan Turing published Computing Machinery and Intelligence, in which he explored whether machines could exhibit intelligent behaviour and proposed what later became known as the Turing test. During the 1950s and 1960s, researchers also developed some of the earliest artificial neural networks, including the perceptron, an algorithm capable of learning simple classification rules by adjusting numerical weights. These developments introduced several ideas that remain central to machine learning today: representing information numerically, learning relationships from examples, and using computational models to make predictions. Thus, many of the fundamental concepts behind modern machine learning have existed for decades, even though their practical capabilities were initially limited.

What has changed, then, to make machine learning so successful today? One of the most important developments has been the enormous increase in computational power. Early electronic computers in the 1950s could perform on the order of (\(10^3\)) floating-point operations per second (FLOPs per second, or FLOP/s), whereas training some large-scale AI models in 2024 required on the order of (\(10^{25}\)) floating-point operations in total (Llama 3.1 405B training was \(3.8x10^25\) flops). These figures illustrate the extraordinary scale of modern computation, although they represent different quantities: the first describes a computer’s processing speed, while the second describes the cumulative computational work required for model training.
The difference between (\(10^3\)) and (\(10^{25}\)) is 22 orders of magnitude, illustrating how dramatically the scale of computation has changed. However, advances in hardware alone do not explain the success of modern machine learning. The increasing availability of large digital datasets and improvements in learning algorithms have been equally important. Together, greater computational capacity, larger datasets, and more effective algorithms have enabled models to solve problems that were previously computationally impractical. Furthermore, improvements in hardware and algorithms have reduced the cost of achieving a given level of performance, making machine learning increasingly accessible across different applications.

7.1 Challenges of Machine Learning
Despite its remarkable progress, machine learning faces several important challenges. One is the hype surrounding artificial intelligence. Since its early development, AI has experienced repeated cycles of enthusiasm, ambitious expectations, disappointment, and renewed interest. Advances in machine learning can generate considerable excitement, but successful demonstrations do not necessarily translate into reliable solutions for every application. It is therefore important to distinguish between what a model can accomplish under controlled conditions and how well it performs when confronted with real-world situations.
Another important challenge concerns data ethics, privacy, and fairness. Machine learning algorithms identify patterns in the data they are given, but these patterns are not necessarily objective, representative, or desirable. Historical datasets may contain biases arising from how information was collected, which populations were represented, and which decisions were made in the past. Consequently, a model can reproduce or even reinforce undesirable patterns without being explicitly programmed to discriminate.
Consider, for example, a machine learning system designed to prioritize buildings for post-earthquake inspections. Suppose its training data contain substantially more inspection records from certain neighborhoods than from others. If the model learns correlations between neighborhood characteristics and historical inspection activity, it may systematically prioritize buildings from better-documented areas while overlooking damaged structures in less-represented locations. Even if its predictions appear consistent with the training data, they may not reflect the actual distribution of structural damage or risk. This illustrates why the quality and representativeness of training data, as well as the consequences of model predictions, must be carefully evaluated.

A further challenge is the lack of interpretability of some machine learning models. While relatively simple models may allow us to understand how individual inputs influence their predictions, complex models such as deep neural networks can be considerably more difficult to interpret. This becomes particularly important in applications involving medical diagnoses, structural safety, or other high-stakes decisions, where knowing the prediction alone may not be sufficient. Engineers and scientists must also evaluate the reliability of the result, understand the limitations of the model, and determine whether its predictions are consistent with available physical evidence and domain knowledge.
Beyond technical performance, machine learning and AI also have broader social implications. Existing systems can influence employment, education, access to information, and decision-making processes. They may also be misused to produce misleading content, automate harmful activities, or reinforce inequalities. Looking further ahead, the possibility of developing AI systems with capabilities exceeding those of humans raises additional questions about safety, control, and governance. These longer-term risks remain subjects of active research and debate, and should be distinguished from the observable challenges posed by systems already in use.
Addressing these challenges requires more than improving predictive accuracy. It calls for the scientific method, reproducible research, transparent evaluation, and responsible data management. Open-source software, open datasets, and clearly documented experimental procedures can help researchers verify findings, compare methods, and identify limitations. However, openness must be balanced with privacy, intellectual property, and safety considerations. Ultimately, trustworthy machine learning depends not only on developing effective algorithms, but also on understanding their limitations and ensuring that they are used responsibly.
8 Data Modalities and Modern Applications
Machine learning can be applied to many different types of data, ranging from images and text to audio recordings, sensor measurements, and information collected through digital platforms. Although these data may appear very different, they share an important characteristic: they can be represented numerically and processed by computational algorithms. Depending on the application, a machine learning model can learn to recognize patterns, classify observations, predict numerical values, generate new content, or support decision-making. The type of data available and the desired output largely determine how the learning problem is formulated.
Image data are among the most widely used inputs in machine learning. A digital image consists of a grid of pixels whose numerical values describe intensity or color. By learning patterns from these values, models can identify and classify objects, locate them within images, or assign labels to individual pixels. Applications include identifying astronomical objects in telescope images, recognizing faces, analyzing two-dimensional and three-dimensional medical images, and extracting written information through optical character recognition (OCR). Images are also essential for autonomous vehicles, where machine learning helps identify traffic signs, pedestrians, vehicles, and other elements of the surrounding environment. Depending on the required output, these applications may involve image classification, object detection, semantic segmentation, or image reconstruction.

Text data provide another important source of information. Written language can be analyzed to identify its meaning, extract specific information, determine sentiment, or generate new text. For example, machine learning can distinguish spam from legitimate emails, classify online comments as positive or negative, extract diagnoses or medication names from medical reports, and translate documents between languages. Text generation systems can also produce summaries, answer questions, and assist with writing. While many earlier applications used specialized models designed for individual tasks, modern language models can perform several of these operations within a single computational framework. Nevertheless, specialized approaches may remain preferable when accuracy, efficiency, privacy, or domain-specific requirements are particularly important.

In medicine and genetics, machine learning is increasingly used to analyze large quantities of biological and clinical information. Genetic data, for example, can be represented as sequences of nucleotides, while medical information may include laboratory results, patient records, and diagnostic images. A major development has been the dramatic reduction in the cost of sequencing the human genome. As sequencing technologies became more affordable, researchers gained access to substantially larger genetic datasets, creating opportunities to identify genetic variations, investigate relationships between genes and diseases, and support personalized medicine. Machine learning can also contribute to disease-risk prediction, drug discovery, and the analysis of complex biological processes. This illustrates an important point: advances in data collection technologies can be just as influential as improvements in learning algorithms.

Audio and video data introduce additional possibilities. Audio recordings are represented as sequences of numerical measurements describing how a signal changes over time. These signals can be analyzed directly or transformed into representations such as spectrograms, which describe how the frequency content varies over time. Applications include speech recognition, voice-controlled systems, automatic translation, and assistive hearing technologies. Video data consist of sequences of images and can be analyzed to recognize activities, track objects, or understand human behavior. When information from multiple sources—such as images, audio, video, and text—is processed together, the problem is referred to as multimodal learning. For example, combining facial movements with audio can improve speech recognition in noisy environments, while analyzing video and spoken language together can help systems interpret human interactions.

Another important category is numerical and sensor data. These data may consist of individual measurements, collections of variables, or time series recorded continuously by sensors. Examples include measurements from scientific instruments such as particle detectors and astronomical telescopes, physiological signals collected by fitness trackers, and environmental observations used in weather forecasting. Robotics also relies extensively on sensor measurements, including position, acceleration, distance, and orientation, to perceive the environment and control movement. Machine learning can identify patterns in these measurements, detect anomalies, estimate quantities that cannot be measured directly, and predict future behavior. When working with sensor data, attention must be given to measurement quality, calibration, missing values, and the temporal relationships between observations.

Civil engineering provides numerous examples of how these data modalities can be combined to address practical engineering problems. Images captured by cameras or drones can be analyzed to detect cracks, spalling, corrosion, and other forms of structural damage. Photographs, LiDAR measurements, and point clouds can support the reconstruction of three-dimensional building models and digital twins. During construction, images and sensor measurements can be used to monitor progress, identify deviations from planned activities, and support site automation. In structural health monitoring, accelerometers, strain gauges, and displacement sensors produce time-series data that can help identify changes in structural behavior. Historical inspection records, environmental conditions, and monitoring measurements can also be used to predict deterioration and support maintenance planning. These applications demonstrate how machine learning can contribute throughout the infrastructure life cycle, from construction and operation to inspection, maintenance, and eventual replacement or reuse.

Games and simulation environments provide another perspective on learning. Unlike applications in which a model learns from a fixed collection of labeled examples, games allow a system to interact with an environment, perform actions, and receive feedback about their consequences. This forms the basis of reinforcement learning, where an agent learns a strategy, or policy, through experience. In games such as chess and Go, the agent must select actions that improve its chances of winning, even when the consequences of individual moves are not immediately apparent. Similar principles can be applied to robotics and control problems, where an agent learns how to navigate, manipulate objects, or perform tasks. Simulation environments are particularly useful because they allow repeated experiments without the cost or risk of operating directly in the physical world. However, strategies learned in simulations must be carefully evaluated before deployment, since simulated conditions may not fully reproduce real-world behavior.

The internet is another major source of machine learning data. Digital platforms generate enormous quantities of information through user interactions, searches, purchases, documents, videos, and social networks. These observations support applications such as recommendation systems, personalized advertising, information retrieval, and content ranking. For example, an online platform may record which products users view or purchase and use these patterns to recommend other products. One approach represents these observations using a user–item interaction matrix (R), where rows correspond to users, columns correspond to items, and entries describe observed interactions. Because most users interact with only a small fraction of available items, this matrix is typically sparse. Matrix factorization methods approximate these interactions using lower-dimensional representations:
\[ R \approx UV^\top, \]
where (U) and (V) contain learned representations of users and items, respectively. These representations capture underlying preferences and relationships that can be used to predict previously unobserved interactions. This is one example of how machine learning can discover useful patterns in large datasets without requiring every relationship to be specified explicitly.

The availability of large collections of digital text has also contributed to the development of large language models (LLMs). These models learn statistical relationships between words, tokens, and their surrounding contexts by training on extensive collections of text. Many modern LLMs are initially trained to predict tokens from their context and are subsequently adapted to perform tasks such as answering questions, summarizing documents, translating languages, generating computer code, and supporting conversational interactions. Virtual assistants built using language models can therefore perform a wide range of tasks through natural-language instructions. However, their outputs are not guaranteed to be factually correct. They may produce convincing but inaccurate information, make reasoning errors, or generate answers that depend strongly on how a question is formulated. Their use in scientific and engineering applications consequently requires appropriate verification and critical evaluation.

Together, these examples illustrate the breadth of modern machine learning. The central idea is not that every application requires a completely different learning principle, but that different forms of data and different objectives lead to different learning problems. Understanding the available inputs, the desired outputs, and the limitations of the data is therefore an essential first step in designing a meaningful machine learning application.
9 Language Models and Generative AI
Language models are machine learning systems designed to learn patterns and relationships in human language. They are trained on large collections of text, including books, articles, websites, and other digital documents, to learn how words and expressions relate to one another. Modern large language models (LLMs) contain large numbers of trainable parameters and can perform a wide range of tasks, including answering questions, translating languages, summarizing documents, generating computer code, and assisting with writing. Despite their apparent complexity, an important foundation of many modern language models is a relatively simple learning objective: predicting the next token in a sequence of text.
Consider the sentence “Tomorrow I think it is going to…”. A language model receives the preceding text as input and estimates which token is most likely to follow. Possible continuations include “rain”, “snow”, or “change”, although some are more plausible than others in the given context. The model assigns a probability to each possible continuation and uses these probabilities to produce its prediction. For example, the model may assign a relatively high probability to “rain” because it has learned statistical relationships between expressions such as “tomorrow”, “going to”, and descriptions of the weather. A token is a unit of text that may represent an entire word, part of a word, or punctuation. During text generation, the model predicts a token, adds it to the existing sequence, and repeats the process. In this way, a model trained to predict one token at a time can generate complete sentences, paragraphs, and longer documents.
To perform these predictions, language must first be converted into a numerical representation. A simple approach is one-hot encoding, in which each word is represented by a vector containing zeros everywhere except at the position corresponding to that word. For example, if a vocabulary contains five words—tomorrow, I, think, rain, and snow—the word rain could be represented as \((0,0,0,1,0)^\top\). A neural network processes numerical representations of the preceding text through layers of trainable parameters and produces scores for possible next tokens. These scores are converted into probabilities, typically using the softmax function, and compared with the correct next token during training. The difference between the prediction and the target is measured using a loss function, which guides the adjustment of model parameters. Modern LLMs use more sophisticated representations called embeddings, together with neural-network architectures based predominantly on transformers and attention mechanisms, which allow the model to account for relationships between tokens across the context. Nevertheless, the underlying learning principle remains familiar: numerical inputs are processed to make predictions, which are compared with targets to improve the model.
The capabilities of language models have improved considerably in recent years. Advances in computational hardware, access to large text datasets, improved neural-network architectures, and more effective training procedures have enabled increasingly capable systems. Modern models can perform tasks that extend well beyond simple text completion, including solving mathematical problems, writing and explaining code, working with information across long documents, and interacting with external tools. Their capabilities are commonly evaluated using standardized benchmarks that measure performance across different tasks. Although these evaluations show substantial progress, they do not imply that models are equally reliable in every situation. LLMs can produce incorrect information, make reasoning mistakes, and generate responses that appear convincing despite being unsupported. Consequently, their outputs should be critically evaluated, particularly when used for scientific, technical, or safety-critical purposes.
Generative artificial intelligence extends beyond language models and text generation. Generative models learn patterns in training data and use them to produce new content, such as images, audio, video, or three-dimensional representations. For example, an image-generation model can create a new image from a written description, while audio-generation systems can synthesize speech or music. Video-generation models can produce sequences of frames representing moving scenes. The development of these technologies has been particularly rapid. Early image-generation systems typically produced small, blurry, or visually inconsistent results, whereas more recent models can generate detailed and realistic images from complex text instructions. These developments illustrate how improvements in data availability, computational resources, and learning methods can significantly expand the capabilities of generative models.

Language models and other generative AI systems demonstrate that machine learning is not limited to recognizing patterns or assigning labels to existing data. It can also generate new outputs based on relationships learned during training. However, generating plausible content is not equivalent to guaranteeing correctness. Understanding the capabilities, limitations, and appropriate use of these systems is therefore essential when applying generative AI in scientific and engineering contexts.
10 From Machine Learning Opportunities to Mathematical Foundations
The wide range of applications discussed in this chapter demonstrates that machine learning offers opportunities to solve problems across many scientific, engineering, and industrial domains. However, developing a useful machine learning application begins with more than simply choosing an algorithm. The first step is to identify a meaningful problem and determine whether learning from data could provide a suitable solution. This requires understanding what needs to be predicted, which information is available, and how the resulting predictions would support decisions or improve existing processes.
Consider, for example, the inspection and maintenance of civil infrastructure. Engineers may want to predict whether a bridge component is deteriorating, estimate the severity of structural damage, or identify which structures should be prioritized for inspection. These problems require different types of input data, such as images, sensor measurements, environmental conditions, and historical inspection records. They also require appropriate target information, which might consist of damage categories, measured crack widths, or observed structural conditions. The usefulness of the resulting model depends not only on its predictive accuracy but also on the quality and representativeness of the available data, its ability to perform well on previously unseen cases, and the practical consequences of incorrect predictions.
Once a problem has been identified, the next step is to formulate it mathematically. A machine learning model establishes a relationship between input variables and desired outputs through a set of parameters that are learned from data. To determine suitable parameter values, we need a way to measure prediction errors and a procedure for reducing those errors. This introduces several fundamental concepts, including regression, loss functions, optimization, and gradient-based learning. Equally important is understanding the difference between fitting the observations used for training and making reliable predictions for new observations, a concept known as generalization.
These principles provide the foundation for many machine learning methods, from simple linear regression models to complex neural networks. By first understanding them through relatively simple mathematical models, we can progressively develop the tools needed to analyze, implement, and evaluate more advanced learning algorithms. The goal of this introductory course is to establish these essential foundations and encourage further exploration of the broader principles and applications of machine learning.
11 Chapter Summary
Machine learning enables computers to learn useful relationships from data rather than relying exclusively on explicitly programmed rules. A typical supervised learning problem involves collecting input–output examples, representing the inputs numerically, and adjusting model parameters during training. Once trained, the model can make predictions for previously unseen inputs through a process called inference. Its performance must then be evaluated using appropriate data, with particular attention to its ability to generalize beyond the examples used for training.
The binary classification of damaged and undamaged buildings illustrates how learning can be formulated using relatively simple mathematical operations. Images can be represented as numerical vectors, a linear classifier can compute predictions using weighted inputs, and its parameters can be updated in response to classification errors. These ideas introduce the fundamental relationship between data, model parameters, predictions, and learning algorithms, which extends to more advanced machine learning methods.
Machine learning is an interdisciplinary field that combines ideas from computer science, statistics, artificial intelligence, and application-specific knowledge. Its development has been supported by advances in computational power, the availability of digital data, and improvements in learning algorithms. Today, machine learning is applied to images, text, audio, video, sensor measurements, and many other forms of information. These applications extend across scientific and industrial domains, including civil engineering, where machine learning supports infrastructure inspection, structural monitoring, construction automation, and maintenance planning.
Despite its capabilities, machine learning is only one component of a broader data-driven workflow involving data collection, preparation, analysis, evaluation, communication, and decision-making. Its applications also raise important questions about data quality, privacy, fairness, interpretability, and responsible use. Recent developments in large language models and generative AI further demonstrate how models can learn complex relationships from data to generate text, images, and other content, although their outputs still require appropriate verification.
Ultimately, developing useful machine learning solutions requires a clearly defined problem, suitable data, and reliable evaluation methods. The mathematical foundations introduced in the following chapters—including regression, loss functions, optimization, and generalization—provide the essential tools for understanding how models learn and for exploring more advanced machine learning techniques.
11.1 Check Your Understanding
- What is the main difference between traditional programming and machine learning? How does a computer learn a decision rule from examples?
- What is the difference between training, inference, and evaluation? What information is needed during each stage?
- Give two examples of machine learning applications from different domains. For each example, identify the input data and the desired output.
- How can a digital image be represented as a numerical vector? Why might this vector contain millions of values?
- In a simple binary classifier, how are input features and model weights used to predict a class? How can the model improve when it makes an incorrect prediction?
- What is generalization, and why does good performance on training data not necessarily mean that a model will perform well on new observations?
- Why is machine learning considered an interdisciplinary field? Explain how computer science, statistics, and domain expertise contribute to developing useful applications.
- What three major developments have contributed to the rapid progress of machine learning in recent decades?
- Why is training a machine learning model only one part of a larger data-driven workflow? Identify other important activities involved in developing a practical application.
- Machine learning can process images, text, audio, and sensor measurements. What do these different types of data have in common, and how can they be used to formulate learning problems?
- What is next-token prediction, and how does this relatively simple training objective contribute to the capabilities of large language models? How does generative AI extend beyond text?
- What challenges must be considered when applying machine learning to real-world decisions? Discuss the importance of data quality, fairness, interpretability, and responsible use.
11.2 Coming Next
The next chapter introduces regression and linear regression, providing a mathematical foundation for understanding how machine learning models make predictions from data. We will examine how relationships between input and output variables can be represented using mathematical functions, how prediction errors can be measured through loss functions, and how model parameters can be adjusted to improve predictions. These concepts will provide the basis for studying optimization, model fitting, and generalization, which are fundamental to more advanced machine learning methods.
12 Acknowledgements and AI Disclosure
12.1 Acknowledgements
These lecture notes were developed with reference to the teaching materials of CS-433 Machine Learning, offered by the School of Computer and Communication Sciences at the École Polytechnique Fédérale de Lausanne (EPFL), Switzerland.
The original course provided a valuable reference for the selection, organization, and explanation of foundational machine learning concepts. The materials have been adapted, reorganized, and extended for the objectives of the present course, including additional examples and applications in civil engineering.
Reference course: EPFL CS-433 — Machine Learning.
This is an independent adaptation and does not imply endorsement by EPFL or the original course instructors.
12.2 Use of Generative AI
Generative AI tools were used to assist with drafting and editing lecture content, preparing examples, generating and refining figures, and developing interactive animations and visualizations.
The course instructor directed the development of these materials and remains responsible for their selection, organization, technical accuracy, and final presentation. AI-generated content was used as supporting material rather than as an independent authoritative source.
External figures, datasets, and other third-party materials are acknowledged separately where appropriate.