




























































































Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!





























































































Machine learning is the sub-field of artificial intelligence where knowledge comes from experience and induction. Such discipline has been developed in order to train computers to make informed decisions on unseen data: indeed, it is often too difficult to design a set of meaningful rules for humans. In particular, machine learning allows to automatically extract relevant information from previous data and exploit it on new one. Moreover, it also allows computers to program themselves so that we can avoid writing software. Machine learning is characterized by three learning paradigms: supervised learning, unsupervised learning and reinforcement learning.
The goal of supervised learning is to learn a model from data that maps known inputs to known outputs starting from a training set 𝒟𝒟 = {〈𝑥𝑥, 𝑡𝑡〉} consisting in labelled data. Therefore, the main tasks of supervised learning are classification, regression and probability estimation.
The goal of unsupervised learning is to learn previously unknown patterns and efficient data representation starting from a training set 𝒟𝒟 = {𝑥𝑥}^ of unlabelled data. Therefore, the main tasks of unsupervised learning are dimensionality reduction and clustering.
The goal of reinforcement learning is to learn the optimal policy, namely the optimal strategy to perform a task.
Supervised learning is the most popular and well-established learning paradigm of machine learning. Starting from a training set made of data coming from an unknown function 𝑓𝑓 that maps an input 𝑥𝑥 ( features or attributes ) to an output 𝑡𝑡 ( targets or labels ), the goal of supervised learning is to learn a good approximation of 𝑓𝑓. The main tasks of supervised learning are:
Supervised learning can be helpful in various scenarios, such as when human cannot perform the task (e.g. DNA analysis), when human can perform the task but cannot explain how (e.g. medical image analysis), when the task changes over time (e.g. stock price prediction) and when the task is user-specific (e.g. movie recommendation).
As we said, the goal of supervised learning is to approximate the function 𝑓𝑓 that maps the input 𝑥𝑥 into the output 𝑡𝑡 starting from a given training set 𝒟𝒟. In order to find a good approximation, the first thing we need to do is to introduce some measure of how good our estimate is. In particular, such metric is called loss function and it is denoted by 𝐿𝐿. Once we have introduced an appropriate loss function we need to choose an hypothesis space ℋ, which is the subspace containing all the functions we are interested in to pursue our goal. Finally, we need to choose the function ℎ ∈ ℋ that minimizes the loss function 𝐿𝐿.
Remark: One may think that a larger hypothesis space always lead to an estimate of 𝑓𝑓 that is no worse that the estimate obtained by choosing a
the class of models by considering linear combinations of fixed nonlinear functions of the input variables:
𝑀𝑀−
𝑗𝑗=
where 𝜙𝜙�𝑥𝑥� = �1, 𝜙𝜙 1 �𝑥𝑥�, … , 𝜙𝜙 (^) 𝑀𝑀−1 �𝑥𝑥��
𝑇𝑇 is the vector of basis functions.
There are many possible choices for the basis functions, such as:
�𝑥𝑥−𝜇𝜇𝑗𝑗 �^2 2𝜎𝜎 2 �.
Remark: One limitation of polynomial and sigmoidal basis functions is that they are global functions of the input variable, so that changes in one region of the input space affect all other regions. On the other hand, Gaussian basis functions are local functions of the input variable.
A convenient error loss function for linear models is the sum of squared
errors 𝐿𝐿�𝑤𝑤� = 12 ∑ 𝑁𝑁𝑛𝑛=1�𝑦𝑦�𝑥𝑥 𝑛𝑛, 𝑤𝑤� − 𝑡𝑡𝑛𝑛 � 2 = 12 �𝜖𝜖� 22 where 𝑅𝑅𝑅𝑅𝑅𝑅�𝑤𝑤� =
�𝜖𝜖� 22 = ∑ 𝑁𝑁𝑛𝑛=1�𝑦𝑦�𝑥𝑥 𝑛𝑛, 𝑤𝑤� − 𝑡𝑡𝑛𝑛 � 2 is the residual sum of squares.
In the case of linear models it is possible to provide a closed-form optimization of the residual sum of squares, which is known as ordinary least squares. Let us consider the matrix form of the loss function:
𝐿𝐿�𝑤𝑤� =
where Φ = �𝜙𝜙�𝑥𝑥 1 �, … , 𝜙𝜙�𝑥𝑥𝑁𝑁 ��
𝑇𝑇 and 𝑡𝑡 = (𝑡𝑡 1 , … , 𝑡𝑡𝑁𝑁)𝑇𝑇. We can find the
optimal value for 𝑤𝑤 by setting the gradient to 0 :
𝜕𝜕𝐿𝐿�𝑤𝑤� 𝜕𝜕𝑤𝑤
So far, we have considered the case of a single target variable 𝑡𝑡. In some applications, we may wish to predict 𝐾𝐾 > 1 target variables, which we denote collectively by the target vector 𝑡𝑡. This could be done by introducing a different set of basis functions for each component of 𝑡𝑡, leading to multiple, independent regression problems. However, a more interesting, and more common, approach is to use the same set of basis functions to model all of the components of the target vector so that:
𝑦𝑦 = 𝑊𝑊 𝑇𝑇^ 𝜙𝜙�𝑥𝑥�
where 𝑦𝑦 is a 𝐾𝐾-dimensional vector and 𝑊𝑊 is an 𝑀𝑀 × 𝐾𝐾 matrix. The optimal
matrix 𝑊𝑊 is given by:
𝑊𝑊�^ = (Φ T^ Φ)−1^ Φ T^ 𝑇𝑇
where each column of the matrices 𝑇𝑇 and 𝑊𝑊�^ are respectively the target vector and the weight vector for each output. All in all, the solution can be easily decoupled for each output:
𝑤𝑤� (^) 𝑘𝑘 = (Φ T^ Φ)−1^ Φ T^ 𝑡𝑡𝑘𝑘
where the matrix (Φ T^ Φ)−1^ may only be computed once.
An important issue regarding the design of linear models is the choice of the complexity of the model (i.e. the number of parameters). Suppose, for instance, to have a training set consisting in 10 observations generated by the process 𝑡𝑡 = sin(2𝜋𝜋𝑥𝑥) + 𝜖𝜖 where 𝜖𝜖 is a small random noise having a
Gaussian distribution. Moreover, assume that we want to fit the data using a linear model with polynomial basis functions:
𝑦𝑦�𝑥𝑥, 𝑤𝑤� = 𝑤𝑤 0 + 𝑤𝑤 1 𝑥𝑥 + 𝑤𝑤 2 𝑥𝑥 2 + ⋯ + 𝑤𝑤𝑀𝑀 𝑥𝑥 𝑀𝑀
The following figure shows the results of fitting polynomials for various choices of 𝑀𝑀.
We can notice that models with low complexity (𝑀𝑀 = 0 and 𝑀𝑀 = 1) are not capable of fitting the data so that they provide a poor representation of the true model ( under-fitting ). On the other hand, models with high complexity (𝑀𝑀 = 9) give an excellent fit of the training set but they still give a poor representation of the true model as the fitted curve oscillates wildly ( over-fitting ). Since the goal is to achieve good generalization by making accurate predictions for new data, we need to obtain some quantitative insight into the dependence of the generalized performance on 𝑀𝑀. This can be done by considering a separate test set of, say, 100 data points generated using the same procedure and evaluating the root-mean-square
Therefore, if we want to use relatively complex and flexible models starting from data sets of limited size we need some way of controlling the over- fitting phenomenon. One technique that is often used in such cases is that of regularization, which involves adding a penalty term to the error function in order to discourage the coefficients from reaching large values:
𝐿𝐿�𝑤𝑤� = 𝐿𝐿 (^) 𝐷𝐷 �𝑤𝑤� + 𝜆𝜆𝐿𝐿 (^) 𝑊𝑊 �𝑤𝑤�
where 𝜆𝜆 is the regularization coefficient.
Remark: The coefficient 𝜆𝜆 governs the relative importance of the regularization term compared with the sum-of-squares error term. If we pick too large a value for such parameter then we again obtain a poor fit.
One of the simplest forms of regularizer is given by the sum-of-squares of the weight vector elements:
𝐿𝐿 (^) 𝑊𝑊 �𝑤𝑤� =
This particular choice is called ridge regression and since the loss function is still quadratic with respect to 𝑤𝑤 we have that closed-form optimization is still possible:
𝑤𝑤� (^) 𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 = (𝜆𝜆𝜆𝜆 + Φ T^ Φ)−1^ Φ 𝑇𝑇^ 𝑡𝑡
Another common choice for the regularizer is the so-called lasso regression :
𝑀𝑀−
𝑗𝑗=
In this case, however, closed-form optimization is not possible. Moreover, we have that if the regularization coefficient is large enough then lasso regression leads to sparse regression models, meaning that some components of 𝑤𝑤� (^) 𝑙𝑙𝑙𝑙𝑙𝑙𝑙𝑙𝑙𝑙 become equal to 0. Too see this, let us notice that
regularization techniques are equivalent to minimizing the term 𝐿𝐿 (^) 𝐷𝐷 �𝑤𝑤�
under the constraint ∑^ �𝑤𝑤𝑗𝑗 � 𝑀𝑀−1 𝑞𝑞 𝑗𝑗=0 ≤ 𝜂𝜂^ (where^ 𝑞𝑞^ = 1^ for lasso and^ 𝑞𝑞^ = 2^ for
ridge) for an appropriate value of 𝜂𝜂. The origin of the sparsity can then be seen in the following figure.
It is possible to deal with regression in a probabilistic way by resorting to the concept of likelihood. In particular, if we consider a probabilistic model depending on some unknown parameters 𝑤𝑤 that maps the inputs to the outputs we can define the likelihood as the probability that the observed data 𝒟𝒟 is generated by a given set of parameters 𝑤𝑤: ℙ�𝒟𝒟�𝑤𝑤�. It is then possible to estimate the parameters by maximizing the likelihood:
𝑤𝑤� (^) 𝑀𝑀𝑂𝑂 = arg max 𝑤𝑤 ℙ�𝒟𝒟�𝑤𝑤�
Let us suppose that the target variable 𝑡𝑡 is given by a deterministic function 𝑦𝑦�𝑥𝑥, 𝑤𝑤� (which is assumed to be a linear model) with additive Gaussian noise:
𝑡𝑡 = 𝑦𝑦�𝑥𝑥, 𝑤𝑤� + 𝜖𝜖 = 𝑤𝑤 𝑇𝑇^ 𝜙𝜙�𝑥𝑥� + 𝜖𝜖
with 𝜖𝜖~𝑁𝑁(0, 𝜎𝜎 2 ). Given a data set of 𝑁𝑁 samples with inputs 𝑋𝑋 =
�𝑥𝑥 1 , … , 𝑥𝑥𝑁𝑁 � and outputs 𝑡𝑡 = �𝑡𝑡 1 , … , 𝑡𝑡𝑁𝑁 �
𝑇𝑇 we have that the likelihood is given by:
𝑁𝑁
𝑛𝑛=
greenhouse gasses. In such circumstances we would like to be able to quantify our expression of uncertainty and make precise revisions of uncertainty in the light of new evidence. This can be achieved through the elegant Bayesian interpretation of probability. The Bayesian approach to probability consists in the following steps:
In particular, the posterior probability distribution for the parameters can be found by combining the prior distribution with the likelihood function according to the Bayes theorem:
where ℙ�𝑤𝑤� is the prior distribution, ℙ�𝒟𝒟�𝑤𝑤� is the likelihood function,
ℙ(𝒟𝒟) = (^) ∫ ℙ�𝒟𝒟�𝑤𝑤�ℙ�𝑤𝑤�𝑑𝑑𝑤𝑤 is a normalizing constant and ℙ�𝑤𝑤�𝒟𝒟� is the posterior distribution. All in all, we shall see that an important role is played by conjugate priors , that lead to posterior distributions having the same functional form as the prior.
We begin our discussion of the Bayesian treatment of linear regression by introducing a prior probability distribution over the model parameters 𝑤𝑤.
Assuming that the likelihood ℙ�𝒟𝒟�𝑤𝑤� is still Gaussian we have that the corresponding conjugate prior (which is the most convenient choice) is given by a Gaussian distribution of the form:
The posterior distribution is proportional to the product of the likelihood
function and the prior: ℙ�𝑤𝑤�𝑡𝑡, Φ, 𝜎𝜎 2 � ∝ 𝑁𝑁�𝑤𝑤�𝑤𝑤 0 , 𝑅𝑅 0 �𝑁𝑁�𝑡𝑡�Φ𝑤𝑤, 𝜎𝜎 2 𝜆𝜆�. Therefore, it is still a Gaussian distribution given by:
At this point we have that a reasonable choice for the parameter 𝑤𝑤 is the mode of the posterior (also known as maximum a posteriori ) since it coincides with the most probable value of 𝑤𝑤. Since for the Gaussian distribution the mode coincides with the mean we have that the maximum a posteriori is given by 𝑤𝑤𝑁𝑁.
Remark: If we set 𝑅𝑅 0 = 𝜏𝜏 2 𝜆𝜆 with 𝜏𝜏 2 → +∞ (i.e. the prior is infinitely broad) then the maximum a posteriori reduces to the maximum likelihood
solution 𝑤𝑤� (^) 𝑀𝑀𝑂𝑂. Moreover, since we have (^) 𝛼𝛼→0lim 𝑅𝑅𝑁𝑁−1^ = Φ^
𝑇𝑇 (^) Φ 𝜎𝜎 2 where^ 𝜎𝜎^
1 𝑁𝑁−𝑀𝑀 ∑^ �𝑡𝑡𝑛𝑛^ − 𝑤𝑤^
2 𝑁𝑁𝑛𝑛=1 we can conclude that the maximum
likelihood estimate of 𝑤𝑤 has the smallest variance and the lowest mean squared error among the linear unbiased estimates.
Remark (regularization): If we set 𝑅𝑅 0 = 𝜏𝜏 2 𝜆𝜆 and 𝑤𝑤 0 = 0 we get
ln ℙ�𝑤𝑤�𝑡𝑡, Φ, 𝜎𝜎 2 � = − (^) 2𝜎𝜎^1 2 ∑ �𝑡𝑡𝑟𝑟 − 𝑤𝑤 𝑇𝑇^ 𝜙𝜙�𝑥𝑥𝑟𝑟�� 𝑁𝑁^2 𝑟𝑟=1 −^
1 2𝜏𝜏 2 �𝑤𝑤�^2
(^2) so that the
maximum a posteriori is equivalent to the solution given by ridge
regression for 𝜆𝜆 = 𝜎𝜎^
2 𝜏𝜏 2.
We can illustrate Bayesian learning in a linear basis function model, as well as the sequential update of the posterior distribution, using a simple example involving straight-line fitting. Consider a single input variable 𝑥𝑥, a single target variable 𝑡𝑡 and a linear model of the form 𝑦𝑦�𝑥𝑥, 𝑤𝑤� = 𝑤𝑤 0 +
it is possible to compute the probability distribution of the target for a new sample 𝑥𝑥 ∗^ by integrating over the posterior distribution:
ℙ�𝑡𝑡 ∗^ �𝑥𝑥 ∗, 𝒟𝒟� = 𝔼𝔼�𝑡𝑡 ∗^ �𝑥𝑥 ∗, 𝑤𝑤, 𝒟𝒟� = � ℙ�𝑡𝑡 ∗^ �𝑥𝑥 ∗, 𝑤𝑤, 𝒟𝒟�ℙ�𝑤𝑤�𝒟𝒟�𝑑𝑑𝑤𝑤
The previous expression is called predictive distribution and its computation involves the convolution of two Gaussian distribution. In particular, it is possible to show that the predictive distribution takes the form:
ℙ�𝑡𝑡�𝑥𝑥, 𝒟𝒟, 𝜎𝜎 2 � = 𝑁𝑁 �𝑡𝑡�𝑤𝑤𝑁𝑁𝑇𝑇^ 𝜙𝜙�𝑥𝑥�, 𝜎𝜎𝑁𝑁^2 �𝑥𝑥��
where 𝜎𝜎𝑁𝑁^2 �𝑥𝑥� = 𝜎𝜎 2 + 𝜙𝜙�𝑥𝑥� 𝑇𝑇𝑅𝑅𝑁𝑁 𝜙𝜙�𝑥𝑥�. The first term in the expression of
𝜎𝜎𝑁𝑁^2 �𝑥𝑥� represents the noise on the data whereas the second term reflects the uncertainty associated with the parameter vector 𝑤𝑤. Therefore, in the limit 𝑁𝑁 → ∞ the second term goes to zero and the variance of the predictive distribution depends only on the variance of the noise. As an illustration of the predictive distribution for Bayesian linear regression models, let us consider the problem of approximating a sinusoidal dataset with a linear model comprising a linear combination of gaussian basis functions.
For each plot, the red curve shows the mean of the corresponding Gaussian predictive distribution, and the red shaded region spans one standard deviation either side of the mean. Note that the predictive uncertainty depends on x and is smallest in the neighbourhood of the data points. Also note that the level of uncertainty decreases as more data points are observed.
The goal of classification is to take an input vector 𝑥𝑥 and to assign it to one of 𝐾𝐾 discrete classes 𝐶𝐶𝑘𝑘 where 𝑘𝑘 = 1,... , 𝐾𝐾. In the most common scenario, the classes are taken to be disjoint, so that each input is assigned to one and only one class. The input space is thereby divided into decision regions whose boundaries are called decision boundaries or decision surfaces. In particular, we will consider linear models for classification, by which we mean that the decision surfaces are linear functions of the input vector 𝑥𝑥 and hence are defined by (𝐷𝐷 − 1)-dimensional hyperplanes within the 𝐷𝐷- dimensional input space. One of the first question to answer is how to encode the class labels by using target values. In probabilistic models the most convenient choice is the following one:
We can identify three distinct approaches to the classification problem:
If 𝐾𝐾 > 2 we might be tempted be to build a 𝐾𝐾-class discriminant by combining a number of two-class discriminant functions. However, this leads to some serious difficulties. Consider the use of 𝐾𝐾 − 1 classifiers each of which solves a two-class problem of separating points in a particular class 𝐶𝐶𝑘𝑘 from points not in that class ( one-versus-the-rest ). This approach may lead to regions of input space that are ambiguously classified.
An alternative is to introduce 𝐾𝐾(𝐾𝐾−1 2 )binary discriminant function, one for
every possible pair of classes ( one-versus-one ). However, this too runs into the problem of ambiguous regions.
We can easily avoid these difficulties by considering a single 𝐾𝐾-class discriminant comprising 𝐾𝐾 linear functions of the form 𝑦𝑦𝑘𝑘 �𝑥𝑥� = 𝑤𝑤𝑘𝑘𝑇𝑇^ 𝑥𝑥 +
𝑤𝑤𝑘𝑘0 and then assigning a point 𝑥𝑥 to the class 𝐶𝐶𝑘𝑘 if 𝑦𝑦𝑘𝑘 �𝑥𝑥� > 𝑦𝑦𝑗𝑗 �𝑥𝑥� for all 𝑗𝑗 ≠
𝑘𝑘.
Theorem: The decision regions of such a discriminant are always singly connected and convex.
Proof: Let 𝑥𝑥𝐴𝐴, 𝑥𝑥𝐵𝐵 ∈ ℛ (^) 𝑘𝑘 so that 𝑦𝑦𝑘𝑘 �𝑥𝑥𝐴𝐴 � > 𝑦𝑦𝑗𝑗 �𝑥𝑥𝐴𝐴 � and 𝑦𝑦𝑘𝑘 �𝑥𝑥𝐵𝐵 � > 𝑦𝑦𝑗𝑗 �𝑥𝑥𝐵𝐵 � for
all 𝑗𝑗 ≠ 𝑘𝑘. Therefore we have that ∀𝛼𝛼 ∈ (0,1)^ it holds 𝑦𝑦𝑘𝑘 �𝛼𝛼𝑥𝑥𝐴𝐴 + (1 − 𝛼𝛼)𝑥𝑥𝐵𝐵 � > 𝑦𝑦𝑗𝑗 �𝛼𝛼𝑥𝑥𝐴𝐴 + (1 − 𝛼𝛼)𝑥𝑥𝐵𝐵 � so that 𝛼𝛼𝑥𝑥𝐴𝐴 + (1 − 𝛼𝛼)𝑥𝑥𝐵𝐵 ∈ ℛ (^) 𝑘𝑘.