Introduction
Chapter Objective
Introduce artificial intelligence, machine learning, and linear regression.
1.1 Artificial Intelligence
The term intelligence has definitions that depend heavily on context. This can create some confusion when trying to understand and define the boundaries of the subject. Less broad, yet even more confusing, is the term artificial. Therefore, given the many definitions of artificial intelligence (AI), we will narrow the scope of the intelligence under discussion.
We humans belong to the species Homo sapiens. This name comes from Latin and means “wise man” (Wikipedia 2024b). The importance of wisdom (a synonym for intelligence) is so great that it defines our very species. AI has captured the human imagination for a long time. For instance, it has appeared in our culture in many forms, such as the talking AI HAL 9000 that controls a spacecraft in Stanley Kubrick’s classic film “2001: A Space Odyssey”, or the AI in the film “Her”, starring Joaquin Phoenix, in which a human falls in love with an operating system. However, AI actually appeared in literature thousands of years ago. In Ancient Greece, people already contemplated and debated the impacts of an artificial being capable of performing human tasks. One example is the giant Talos of Crete, an automaton from Greek mythology [20]. Other examples related to artificial intelligence can be found in the book “Artificial Intelligence: An Illustrated History: From Medieval Robots to Neural Networks” (Pickover 2021). In this context, however, we recognize that species other than Homo sapiens, such as a cat, a dog, or a bee, are also endowed with intelligence. Accordingly, we will take a more restrained and measured view of what the term “intelligence” means.
“Intelligence” and “artificial” are words that carry implicit meaning for people outside the field of computer science. Naturally, doctors, lawyers, and engineers (to name just a few) want to see how AI can fit into their daily routines. My dentist once asked how AI would affect his dental procedures. Yet he never asked me how the “Fourier Transform” could improve his day-to-day work, even though the transform is widely and enthusiastically used across many domains of knowledge (Wikipedia 2024a).
A more formal definition of AI is still necessary. In computer science, AI is primarily concerned with the ability to perform tasks that intelligent beings (such as a cat, a baby, a bee, or an adult human) carry out—for example, instinctively pulling a hand (or paw) away upon touching a hot surface, taking a multiple-choice anatomy exam, or drafting an appeal to void a civil service exam question. If a program performs an action typically carried out by an intelligent entity, it can be viewed as a program that artificially simulates intelligence. Admittedly, almost anything can fit within this concept. We could also have given this field any other name without losing anything of substance, yet the term has brought with it associations that sometimes help and sometimes confuse newcomers. Regarding the definition of AI, Russell and Norvig’s textbook offers a solid formulation: “The field of artificial intelligence [...] attempts not just to understand but also to build intelligent entities” (Russell and Norvig 2002). In other words, artificial intelligence in computer science has the ambitious goal of building intelligent agents.
The origin of the term “artificial intelligence” in computer science is generally attributed to John McCarthy, a mathematics professor at Dartmouth College (Blog 2024) (Figure 1.1). He organized an eight-week conference with colleagues in 1956, a few years after World War II, and since then the term has been used to designate an area of study within computer science. Shortly before that, Alan Turing’s seminal paper had already presented reflections on the intelligence that a machine might possess (Turing 1950). It is worth noting that Alan Turing and John McCarthy already worked together. Other researchers were also pivotal to the field, including Warren McCulloch, Walter Pitts, Allen Newell, Herbert A. Simon, Cliff Shaw, and Frank Rosenblatt, among others.


Figure 1.1. John McCarthy and Alan Turing.
We can classify the various AI techniques into two groups: deduction and induction. Deduction draws inferences from general rules, whereas induction draws inferences by generalizing from individual events. See Figure 1.2.

Figure 1.2. AI deduction and induction diagram. Source: The Author (2024).
It was in the 1970s that the use of artificial intelligence began to spread more widely. One of the earliest approaches to achieve relative success was Expert Systems (ES). They relied on domain experts to transform tacit knowledge (based on personal experience) into explicit knowledge (formalized and documented), which was then encoded as rules in formal logic. The process of acquiring this knowledge ended up becoming a major obstacle to the mass adoption of this approach. Figure 1.3 shows an example of software implementing an inference engine based on Expert Systems theory.

Figure 1.3. Interface of the Expert SINTA Expert System. Source: The Author (2024).
Overcoming several limitations (such as increased computing and storage capacity, the generation of massive volumes of data, scientific and technological breakthroughs, superconducting chips, and energy efficiency) enabled the advancement of other techniques. One of the techniques that has gained prominence thanks to these advances is Machine Learning (Figure 1.4).

Figure 1.4. ML is a subset of AI. Source: The Author (2024).
1.2 Machine Learning (ML)
Machine Learning (ML) is a subfield of AI motivated by the development of software that relies less on human intervention to extract knowledge, which had been a major bottleneck in Expert Systems. In general, ML applications use induction to search for models capable of representing the knowledge embedded in data.
In Figure 1.5, we can see several examples of ML integrated into everyday activities: (a) a smartphone with a voice assistant providing weather updates; (b) a smart home system adjusting the thermostat based on user preferences; (c) an autonomous car driving down a busy city street; and (d) an online shopping platform recommending products to a user based on previous purchases. Notably, this figure was created using an artificial intelligence tool called DALL-E 3, available within ChatGPT. ChatGPT is a chatbot that gained global attention as one of the fastest-growing applications in history.

Figure 1.5. Examples of ML. Source: The Author (2024), with assistance from the ChatGPT AI.
Machine learning tasks can be divided into predictive and descriptive tasks. Predictive learning tasks aim to infer the target attribute of a new input based on prior exposure to data during model training. Descriptive tasks seek to uncover patterns and correlations; moreover, they make no distinction between target and predictive attributes.

Figure 1.6. Classification of ML tasks. Source: The Author (2024).
Both types of tasks fall under the concept of inductive learning, which is the ability to generalize from specific examples—that is, from a training dataset. For predictive tasks, algorithms can perform classification, where the target attribute is discrete qualitative (or categorical), or regression, where the target attribute is continuous quantitative (or numerical). Descriptive tasks, in turn, include clustering, which looks for similarities; association, which searches for frequent patterns; and summarization, which produces a compact summary of the dataset.
However, other supervised and unsupervised machine learning techniques, aside from linear regression, are outside the scope of this book. It is important not to confuse linear regression with the regression task category in machine learning. Linear regression is a specific algorithm used to perform, for example, supervised learning.
1.3 Linear Regression
Linear regression is a statistical technique used to model and analyze the relationship between a dependent variable and one or more independent variables. It provides a way to understand how the dependent variable changes as one or more independent variables vary. By analyzing trends in the data, linear regression enables us to make predictions and identify patterns. This technique is widely used across fields such as economics, social sciences, engineering, medicine, and many others.
In linear regression, the dependent variable is represented as a linear combination of the independent variables, where the coefficients of that linear combination are estimated from the observed data. This makes it possible to build a mathematical model describing the relationship between the variables. Fundamental concepts include the regression line equation, the slope coefficient, the intercept coefficient, and the notion of residual error. Understanding these concepts is essential for properly applying and interpreting linear regression.
Example with a Fictitious Dataset
In machine learning, linear regression is frequently used as a starting point for predictive modeling. Its simplicity and interpretability make it a valuable tool for exploring data and understanding relationships between variables. It forms the foundation for many supervised learning algorithms and serves as a benchmark (or baseline) for more complex models. Furthermore, it is widely used in fields such as economics, finance, biology, and engineering, wherever predicting continuous values is needed.
To illustrate this, we will build a predictive model from a dataset with two predictor attributes, and , and a target attribute . For example, could represent years of education, could represent age, and could represent salary.
There is an unknown function that generated the training data. This function is sometimes referred to as the god function, . Our goal is to find another function , within a universe of available functions, that best approximates . The premise is that the machine learning engineer does not know—and will never know—the true function that generated the data, but will instead make the best technical estimate of it, denoted . Because it is an approximated and estimated function, we place a hat over it and write it as .
First, we will try to infer this function using our own human intelligence. Next, we will use a predictive model and compare whether the artificial intelligence machine learning technique arrives at a similar result.
Table 1.1. Fictitious dataset used to train the model
| X1 | X2 | y |
|---|---|---|
| -4 | -4 | 0 |
| -3 | -3 | 0 |
| -2 | -2 | 0 |
| -1 | -1 | 0 |
| 0 | 0 | 0 |
| 1 | 1 | 1 |
| 2 | 2 | 1 |
| 3 | 3 | 1 |
| 4 | 4 | 1 |
| 5 | 5 | 1 |
| 6 | 6 | 1 |
The dataset is presented in Table 1.1. Note that this is a pedagogical example; real-world datasets are typically much more complex. In this example, the table represents our entire dataset. In this format, we also refer to it as a matrix. Columns and correspond to two features, where each feature/column can be represented as a vector (which is simply a matrix with a single column); together they form a two-dimensional predictor matrix . Meanwhile, is a column that can be understood as a vector (or a single-column matrix) containing the target attribute.
Use your intuition. Based on the training data in Table 1.1, what would the value of be for a new observation with values and ?
Now that you have used your intuition (or logic)—that is, your human intelligence—it is artificial intelligence’s turn. The machine will do the same thing you just did: make its best estimate using a specific technique to infer the value of a new observation. We will use logistic regression (which is closely related to linear regression) as implemented in the popular scikit-learn library, using the Python language, to build, train, and generate predictions from this model.
In the following example, we implement a predictor using logistic regression and make a prediction for a new observation with attributes ( and )—the very same prediction you made earlier using human intelligence.
# Loading the required libraries
import numpy as np
import pandas as pd
from sklearn.linear_model import LogisticRegression
# Loading fictitious data
X = np.array([[-3,-3], [-2,-2], [-1,-1], [0,0], [1,1], [2,2], [3,3],
[4,4], [5,5], [6,6]])
y = np.array([0, 0, 0, 0, 1, 1, 1, 1, 1, 1])
# Training the model
model = LogisticRegression()
model.fit(X, y)
# Prediction
print('Prediction: y =', model.predict([[8, 8]]))
Prediction: y = [1]
The predictive model’s output for the test input and was . Compare this with what you expected. Did the machine artificially arrive at the same result as you?
Example with Another Dataset
In the next example, we present a predictive model in Python using the same library (scikit-learn). The model uses the Logistic Regression algorithm and the iris dataset, which contains petal and sepal measurements along with flower species names. The Iris dataset is well known and widely used in other books and websites because its classes are largely linearly separable.
# Loading the libraries
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_iris
# Loading the data
iris = load_iris()
X = iris.data
y = iris.target
# Training the model
reg = LogisticRegression()
reg.fit(X, y)
# Making a prediction
print('Prediction: y =', reg.predict([[2, 2, 2, 2]]))
Prediction: y = [0]
Do not worry about fully understanding the code or the model’s evaluation metrics right now. In the upcoming chapters, we will dive deeply into the concepts needed to thoroughly understand these examples.
At the end of each chapter, you will find a list of questions to reinforce what you have learned. The answer key is located at the end of the book. Enjoy your studies!