A Gentle Introduction to AI
Get a simple introduction to Artificial Intelligence is and why it should be important to you, with a specific focus on Machine Learning.
Join the DZone community and get the full member experience.
Join For Freelooking at the latest google and apple conventions, it is clear to all: if in the past years the main buzzwords in the information technology field were iot and big data, the catchall word of this year is without a doubt machine learning. what does this word mean exactly? are we talking about artificial intelligence? is somebody trying to build a skynet to ruin the world? will machines steal my job in the future? “know your enemy,” they say. so let’s try to understand what machine learning really means.
definitions
the task we are going to accomplish is not simple. so, let’s start from the beginning: what does machine learning refer to?
machine learning is a discipline of artificial intelligence that is responsible for studying and developing algorithms that allow machines to learn information. in detail, the learning process is done using an inductive approach that tries to extract rules and behavioral patterns from huge amounts of data.
the types of information used by the algorithms (learners) to learn to identify the following categorization of machine learning algorithms are:

supervised learning
. the learner a set of given couples (input, output) to learn a function
\(f\)
that maps input to output. the above couples are called supervisions and using them, the learner tries to find the function that approximately fits, like\(f\)
. supervisions must be available at the beginning of the learning process. 
unsupervised learning
. in this kind of learning process, the function
\(f\)
is learned by the learner using solely the given inputs. there is no a priori information relative to the output of the function\(f\)
. in this type of learning process, the learner tries to approximate the probability distribution of the given inputs.  reinforcement learning . given an environment that an agent can interact with and given a set of positive and negative returns that the environment can give to the agent, the objective, in this case, is to find a policy of action of the agent that maximizes the values of the above returns.
let's look at some examples. we have some food, i.e. pasta, oranges, apples, and chocolate. using a supervised approach, we give to the learner the whole set of foods, specifying which of these is a fruit and which is not. using this information, the learner tries to understand what features fruits have. given a new food, the algorithm will try to guess if it is a fruit or not.
using an unsupervised approach, we do not know the type of each food. our task is to group each piece with something that seems to be similar. the learner will try to build these groups (or clusters) looking at the information it has.
in reinforcement learning, the food is all scattered on the floor of a room. each type of food smells in a different way and has a caloric intake. an agent that can recognize smells is free to move inside the room. it does not know the caloric intake of each food until it eats it. the algorithm will learn how to move inside the room trying to maximize the caloric intake of the eaten food.
given the above definitions, we can now move on. in this post, i will focus on supervised learning.
supervised learning
we said that in this kind of learning we need a set of couples of inputs and outputs that we called supervisions . someone has to give us this information; otherwise, it is not possible to learn anything using this approach. we can call this “someone” the oracle.
let’s try to define the process of learning now. we need a set of items we want to categorize in some way. let’s call this set
\(x\)
and the items belonging to it
\(x \in x\)
. we define a supervisor
\(\mathcal{s}\)
that, given a
\(x \in x\)
, gives a label
\(\hat{y} \in \mathcal{y}\)
. finally, we call
\(\mathcal{h}\)
a set of functions
\(h\)
(a.k.a. hypothesis space) that maps an
\(x\)
into an
\(y\)
, such that
y=h(x)
.
then, the learning process can be viewed as the choice of a
\(h \in \mathcal{h}\)
such that the differences between
\(y = h(x)\)
and the labels chosen by the supervisor
\(\mathcal{s}\)
are minimized. in other words, we want to minimize cases in which
\(y \neq \hat{y}\)
.
just to be a little bit formal, supervisions
\(x\)
belong to an unknown probability distribution
\(\mathcal{d}(x)\)
. also, labels
\(\hat{y}\)
given by the supervisor belong to a conditional probability distribution
\(\mathcal{d}(\hat{y} \mid x)\)
. if you did not understand these last sentences, it does not matter: there is a world full of white unicorns out of there.
data representation and features selection
so far, so good. we came up with a set of examples
\(x \in x\)
that we want to classify in some way. how can we do that? the key concept is how we are going to represent our data, how we are going to explain to the computer how to treat this data.
a computer is simply a machine that is able to do some arithmetical operation over a representation of numbers, isn’t it? then, we need to transform the examples
\(x \in x\)
in something that a computer is able to understand. this phase is called features selection.
the number of features that characterize example
\(x\)
is clearly infinite. think to an apple: it has a color, a volume, a radius, a quality, an age…but also a number of molecules, atoms, and so on. then, the first operation we need to do on
\(x\)
is to choose some of these features, mapping them into a new space
\(\mathcal{x}\)
, called the features space.
the best choice for
\(\mathcal{x}\)
is a space in which each feature is represented by a number. doing so, an example
\(\mathbf{x} \in \mathcal{x}\)
becomes a vector of numbers
\((x_1,\dots, x_n)\)
: every feature
\(x_i\)
is a possible dimension in this space.
let’s call
\(\phi : x \to \mathcal{x}\)
the function that maps examples from the input space to the features space.
as an example, suppose we want to associate a set of emails the relative author. this task is called authorship attribution. the first step we need to do is to map each email
\(x\)
in the relative vector
\(\mathbf{x}\)
in some features space. obviously, the selection process of the features space is one of the core processes of machine learning: representing the examples with the wrong set of features could mean to fail the entire learning process.
for our example, some possible features can be the following:
 the number of words used in the email.
 the number of adjectives.
 the number of adverbs.
 the number of occurrences of each single punctuation character.
 and so on…
an email
\(x\)
is represented in the features space with something like this:
\(\mathbf{x} = (34, 7, 10, 3, 6)\)
. as you can see, it’s a simple vector in
\(\mathbb{n}^5\)
! this kind of representation opens up a lot of useful considerations that will complete our introduction to machine learning.
vector similarity and the concept of distance
given a supervisor
\(\mathcal{s}\)
that gives us supervisions
\((\mathbf{x}_1, \hat{y}_1), \dots
,
(\mathbf{x}_m
, and
\hat{y}_m)\)
, the learning process is equal to find the degree of similarity between a new example
\(\mathbf{x}_{m+1}\)
and all the previous.
speaking of vectors in some numeric features space, the similarity concept is equal to the concept of distance between two vectors. defining as
\(d: \mathcal{x} \times \mathcal{x} \to \mathbb{r}^+\)
,
the distance between vectors
\(\mathbf{x}\)
and
\(\mathbf{z}\)
, a good choice of distance between two vectors is the dot product or inner product.
we have just defined a good way to understand how vectors are related to each other inside the features space. eureka! let’s try to make a step beyond and to close the first circle of this introduction to machine learning.
it’s all about hyperplanes
using the framework we just built, we can imagine our examples as vectors inside an
n
dimensional features space
\(\mathbb{r}^d\)
. if every vector is associated with a label for each class
\(\hat{y}\)
, the classification problem is equal to find an hyperplane that divides into different groups the vectors.
ok, wait. i think i lost many of you in this last step. let’s take a step back.
in the above image, a set of supervisions is represented in a twodimensional features space, a.k.a.
\(\mathbb{r}^2\)
. each vector
\(\mathbf{x}_i\)
is colored either blue or orange. the colors represent the classes.
as you can see, using this features space, supervisions are naturally distributed in two different sets inside
\(\mathbb{r}^2\)
. so, a learner in such space is represented by a line
\(\mathbf{w}\)
that divides the two sets of supervisions — orangecolored and bluecolored. orangecolored supervisions are above
\(\mathbf{w}\)
; bluecolored supervisions are below
\(\mathbf{w}\)
.
for this problem, the hypothesis space is the set of all hyperplanes in
\(\mathbb{r}\)
. the learning process tries to discover the hyperplane
\(h\)
that divides supervisions of their classes.
conclusion
we just reduced the problem of supervised learning into a simpler problem, which is the selection process of an hyperplane in
\(\mathbb{r}^d\)
. we can identify different types of supervised learning (i.e. neural networks, support vector machines, and so on) that differ by the algorithm that is used to find the hyperplane.
as we saw, the selection process of the features space is a core process. if we choose a features space in which the supervisions are not separable, the learning process will become harder and an optimal solution cannot exist.
in the next part of this series of posts, we are going to explore some other interesting features of machine learning, i.e. training, validation and testing processes, generalization, overfitting, and many others.
Published at DZone with permission of Riccardo Cardin, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments