


































































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!



































































TPoich´e la frase inizia gia con un’affermazione (”The P performance measure is...”), non puoi inserire una struttura interrogativa invertita a meta. Suonerebbe ”spezzata”. Mettere il verbo alla fine serve a chiudere la proposizione subordinata in modo fluido.
0.0.1 Altri esempi simili
Questo succede ogni volta che usi parole come how, what, where o why dentro una frase:
Introduction The machine Learning is the field that builds machines that can learn from experience. It studies all those that are concerned with the automatic discovery of regularities to take actions, such as classifying the data into different categories. For most practical applications, the original data are typically preprocessed to transform them into some new space where the pattern recognition problem will be easier to solve. This is the feature extraction, Care must be taken during pre-processing because of-ten information is discarded, and if this information is important to the solution of the problem then the overall accuracy of the system can suffer.
”A computer program is said to learn from experience E with respect to some class of tasks ”T” and performance measure ”P”. If its performance at tasks T as measured by P, improves with experience E. The task T is described in terms of how ML algorithm should process an example, which is represented by as a collection of features that can be measured. The performance measure P allow to understand how good the ML system is. P depends on the task. The experience is provided by the available data, which is obtained:
In machine learning we have focus on learning data from a specific kind of problem and training a machine learning program to solve it. The goal of ML is to learn all the specific examples in the data set to be able to generalize the solution also to new and unseen examples.
You can imagine many functions that can have y = f (x), where x is an input and y an output. You make an assumption of the kind of function that you are going to find. ML models, need to make assumptions to solve to find the right function. The dataset we have is a random sample i.i.d. according to some probability distribution D. In general we are interested in generalization, mimicking inductive reasoning We should use Machine Learning:
There is no rule in how many examples do i need to make a good ML model. The more you have, the better will be the model.
An algorithm is a clearly and unambiguous description of a set of steps for solving a problem. The algorithm computes based on input and gives an output. In ML we want that the computer look for pattern within the data automatically. the system searches for pattern that correlate specific inputs with specific classes or outputs. Input and Output are fed into the system to generate underlying algorithm or logic. we train our algorithm in order to obtain the best model which uses to predict the best model. In fact, the process to follow when you train MLA is:
In Machine Learning, the process is divided into two main stages: Training and Prediction
During the training phase, the primary goal is to build the model. Here we provide the Input and the corresponding correct Output (often called labels) to the computer. The system analyzes these pairs to find underlying patterns, creating a Model. Mathematically, the objective of this stage is to establish a function where the expected value of the predictions aligns as closely as possible with the real-world labels.
Once the training is complete, the model is put to work in the prediction phase. At this point, the system is being ”tested” on New Input that it has never encountered before. By feeding this new input into the model, the system executes its learned logic to generate a pre- dicted Output. This is the stage where the Machine Learning algorithm provides its final answer or classification based on the experience it gained during the training phase.
The problem is that we use inference, so we use approximation to solve the problem and not ever will be 100% perfect. You need to check the own model with other input. When we train the model, you have to put it in your input and check the results to confirm the correctness in the way to compare the other model that we have. We say ”training a model”, not ”create an algorithm”.
There are three main kinds of approach:
Unsupervised learning is often used when a problem doesn’t have a single ”right” solution that can be pre-defined. It allows the machine to simplify complex information, reduce noise, and highlight the most important features of the input. It is the primary tool for exploring raw, unlabeled data to find insights that a human might not even know to look for So in the supervised learning, our dataset is composed by couple of x input and y output
1.2.3 Reinforcement Learning
Reinforcement Learning is usually used to improve language models. In this case, there is an agent that exists in one state s in a time t that can perform an action a. Being that not all actions can be performed, depending on the state, we have some actions that you can perform and that we move to a new state. Furthermore, we have to define what is the goal of the agent, in the way to defining a reward for it. The difficulties here are mainly two
The aim of Reinforcement Learning is to build an agent which able to try several times from different states and different actions which will give the best reward
1.2.4 Some definition
Features The feature is the interdependent variable, that is the input that the algorithm process to predict the label
Label Label represents the dependent variable (y) that the algorithm try to predict. is the desirable output
Ground Truth Ground truth refers to the reality you want model with your algorithm. Thus is the information that is known to be real or true, provided by direct observation and measurement, as opposed to information provided by inference; for that reasons it represent the maximum accuracy of the data. It is the target for training or validating the model with labeled dataset, allow to compare the data obtained by the model whit it.
The hypothesis space is the set of all function that the algorithm can consider to solve a specific task Our goal is to find the true function h ∈ H that best maps the features to the correct labels, hence, minimizing the error relative the ground truth
h ∼ f : X → Y
The hypothesis space H, is the set of all functions that could be the potential solution. Once the space is defined, a method must be chosen to explore this space and find the best function. To do it, the algorithm find the optimal solution h means that the hypothesis solution that can approximate the unknown target function. Learning means finding the function h that approximate the most f. However, defining the hypothesis space involves trade-off. If we only consider linear function within our hypothesis space, we may never find a solution, whether the true underlying function is not an hyperplane (the data is not linear). Furthermore when you increase the size of H , it becomes harder to find the right function, getting an infinite possible function, that are consistent in the training set.
For that reasons we introduce specific biases into the algorithm, regarding how the hypothesis space is built to guide the selection process Inductive bias is the set of all the assumptions about the nature of the target function and there are two type of bias:
An induction bias is any basis for choosing one generalization over another, other than strict consistency with the observed training instances. The ”no free lunch theorem” states that every ML algorithm must make assumptions and there is no single ML algorithm works for every setting
Find-s Algorithm It is an algorithm usually used in the concept learning to identify a target concept from labeled.The idea is to find an hypothesis that classifies true or false our data. The goal is to identify the functions which satisfies all the positive example and ignoring the negative one in our training set. In this case, the bias is represented as a binary values, and our hypothesis space by a function which are a conjunction of boolean facts. c : X → { 0 , 1 }
an example in X is defined as (x, c(x)) , and the function h that we have found is consistent, which means that it is able to classify correctly each example in training set. Let h : X → { 0 , 1 }:
2 Errors
In the Machine Learning the fundamental object is to approximate an unknown target function f. The available training data consists of observations, which are adhere to the trajectory of f , they are inevitable subject to stochastic noise. Consequently, the task of MLA is to reconstruct the underlying function f by distinguishing the signal from the noise
We want to generalize the examples of our dataset which come from the same probability distribution. To do this, we have to search the best approximation, but if the error would be 0, we have anything to train. Thus we check how much our function is compliant with the ground truth, and we compute how much the function differs from the real values
True error The true error of hypothesis h, with respect to target concept c and distribution D (errorD (h)), is the probability that h will misclassify an instance drawn at random, according to D
ErrorD (H) ≡ P r[c(x) ̸= h(x)]
The idea behind the True Error is that you calculate how many times our function that we have estimated gives s solution which differ from the real
variance instead, is the error that can make the model too sensitive with respect to small fluctuations in the training dataset. It measures how much the model,s predictions change when trained on different dataset. High variance can cause an algorithm to model the random noise in the training data, which implies a low error on a training data, but an high error on unseen data. When we make a prediction we have
to consider that there is a trade-off between bias and variance. The goal is to find a model with a low level of both. Simpler models tend to have low variance and high bias; whereas complex model tend to have low bias and high bias. Thus, when we make prediction, we have a loss, computes for instance with MSE. The higher the loss will be, the higher the errors will be too.
2.3.2 Error Decomposition
Let Lmse(h, D) = (^) D^1
(x,y)∈D (h(x)^ −^ y) (^2) , and be ϵi a random variable with mean 0 and variance σ (^2) ,
then yi = f (xi) = ϵi
and BIAS(h(x)P ) = ED∼P [(h(x) − y)] V ARIAN CE(h(x), P ) = ED∼P [(ED∼P [(h(x)] − h(x))^2 ]
In general we have two sets:
In the training set we train our model, while in the test set, we try the found model to evaluate the model. If we take the function RISK(h, P ) and substitute y with its function y = f (xi) + ϵ, we have
RISK(h, P ) = ED∼P [(h(x) − (f (x) + ϵ))^2 = ED∼P [(h(x) − f (x) − ϵ)^2
we isolate the noise:
ED∼P [((h(x) − f (x)) − ϵ)^2 ] = ED∼P [(h(x) − f (x))^2 = ϵ^2 − 2 ϵ(h(x) − f (x))]
RISK(h, P ) = σ^2 + BIAS(h, P )^2 + V ARIAN CE(h, P )
Thanks for the property of the linear operator, we have:
RISK(h, P ) = ED∼P [h(x) − f (x))^2 ] = ED∼P [ϵ^2 ] − 2 ED∼P [ϵ(h(x) − f (x))
we obtain RISK(h, P ) = ED∼P [(h(x) − f (x))^2 + σ^2
after that we may add to the function ±¯h(x)
RISK(h, P ) = ED∼P [((h(x) − h¯(x)) + (¯h(x) − f (x)))^2 ] + σ^2
We can show that
ED∼P [(h(x) − ¯h(x))^2 ] + ED∼P [(h(x) − f (x))^2 ] + 2ED∼P [(h(x) − ¯h(x))(¯h(x) − f (x))] + σ^2
Hence: RISK(h, P ) = σ^2 + BIAS(h, P )^2 + V ARIAN CE(h, P )
2.3.3 Test Error
To reliably estimate the generalization error of a model, we typically use k-fold cross-validation. This technique involves partitioning the dataset into k equal-sized blocks (e.g., 5 blocks for a 5-fold CV). In each iteration, k − 1 blocks (80% of the data) are used to train the model, while the remaining block (20%) is held out as the test set. This process is repeated k− times so that every block is used exactly once as a test set. The final test error is the average of the errors recorded across all iterations.” ”When analysing a model’s performance during training (e.g., across training epochs or as model complexity increases), we expect the training error to decrease continuously. Initially, the test error decreases alongside it. However, at a certain critical point, the test error starts to increase while the training error continues to drop towards zero. This divergence is the hallmark of overfitting: the model is memorizing the specific noise of the training data rather than learning the underlying, generalizable patterns
3 Linear Approaches
The simplest forms of linear regression models are also linear functions of the input variables. However, we can obtain a much more useful class of functions by taking linear combinations of a fixed set of nonlinear functions of the input variables, known as basis functions. Such models are linear functions of the parameters, which gives them simple analytical properties, and yet they can be nonlinear with respect to the input variables.
An important model which relates in m example of our data in input x. The function h is represented by a linear combination
hθ = θ 0 + θ 1 x
The idea is to choose the optimal values of θ 0 and θ 1 , which defines the position of the straight line, such that hθ (x) is close to y for the training examples. To measure that, we use the cost function
RESIDU AL = (hθ (xi) − yi)
Being that the negative error could be canceled out, we use the sum square:
J(θ 0 , θ 1 ) =
2 m
X^ m
i=
(hθ (xi) − yi)^2
We want to find the θ 0 , θ 1 , that minimize the loss function. Every combination of θ 0 , θ 1 , represent a different hypothesis. The function J(θ), can be convex or non-convex:
Closed-Form Solution for Linear Regression
To determine the optimal parameters θ, we must minimize the cost function associated with our hypothesis. In a linear regression model, the hypothesis function is defined as:
hθ (x) = θ 0 + θ 1 x
To generalize this for k attributes, we represent the parameters as a vector θ ∈ Rk+1^ and the features as a vector x. By adding a ”fictitious” attribute x 0 = 1 to account for the bias term θ 0 , we can write the hypothesis in a compact matrix form:
hθ (x) = θT^ x
The Design Matrix and Loss Function Given a dataset of m examples, we construct the Design Matrix X of dimensions m × (k + 1). Each row of this matrix represents a single training example xTi :
1 x 0 , 0... x 0 ,k− 1
.. .
1 xm− 1 , 0... xm− 1 ,k− 1
, y =
y 0
.. .
ym− 1
The loss function J(θ) is defined as the Mean Squared Error (MSE), which represents the squared L 2 norm (squared Euclidean distance) between our predictions and the ground truth:
J(θ) =
m
∥Xθ − y∥^2 =
m
(y − Xθ)T^ (y − Xθ)
Using the squared L 2 norm is advantageous because it ignores the direction of the error, penalizes larger outliers more heavily, and is strictly differentiable, which facilitates optimization.
Deriving the Normal Equation To find the optimal parameters, we want to solve the following minimization problem:
arg min θ
m ∥Xθ − y∥^2 = arg min θ
m (y − Xθ)T^ (y − Xθ)
To achieve this, we calculate the gradient ∇θ J(θ) and set it to zero. Expanding the loss function yields:
J(θ) =
m
h yT^ y − yT^ Xθ − θT^ XT^ y + θT^ XT^ Xθ
i
Since yT^ Xθ and θT^ XT^ y are scalars, they are equal to each other. We can thus simplify the expression:
J(θ) =
m
h yT^ y − 2 θT^ XT^ y + θT^ XT^ Xθ
i
Applying the partial derivative with respect to θ:
Setting the resulting gradient to zero:
2 m
[−XT^ y + XT^ Xθ] = 0 =⇒ XT^ Xθ = XT^ y
Solving for θ gives the Closed-Form Solution (Normal Equation):
θ = (XT^ X)−^1 XT^ y
Limitations and the Pseudo-Inverse This solution provides the global minimum because the cost function is convex. However, a significant problem arises if the matrix (XT^ X) is not invertible (singular). This occurs if:
In such cases, a unique solution does not exist. To resolve this, we can clean the data by removing redundant features or use the Moore-Penrose Pseudo-Inverse (X†). This technique allows us to find a solution even for non-invertible matrices, typically selecting the θ with the smallest L 2 norm.
While with regression we try to predict a continuous real value given the inputs, with classification we restrict the output to a finite and discrete set of categories. Therefore, our goal is to find a function f that best approximates the discrete target variable Y. Generally, we can distinguish three different types of classification problems:
In the context of supervised learning, a linear discriminant function is a model that partitions the input space using a linear decision boundary. For a binary classification problem with classes C 1 and C 2 , the discriminant function takes the form of a linear combination of the input variables:
y(x) = wT^ x + w 0
where w is called the weight vector, and w 0 is the bias (or threshold).
The ”Classification as Regression” Approach Regression is designed to minimize vertical distances between the predicted line and the target points. We can use a Regression algorithm for classification, for example setting a threshold
( if h(x) ≥ c predict y = 1 if h(x) < c predict y = 0
where c is the threshold In classification, this is suboptimal because:
In regularized linear regression, we modify the cost function J(θ) by adding a regularization term. The objective is to minimize the following function:
min θ J(θ) = min θ
2 m
X^ m
i=
(hθ (x(i)) − y(i))^2 + λ
X^ n
j=
θ^2 j
Where:
Pn j=1 θ
2 j is the regularization term.
Note: By convention, we do not regularize the bias term θ 0 (the sum starts from j = 1).
To minimize the cost function, we use the gradient descent algorithm. Since the bias term θ 0 is not regularized, the parameter update is separated into two cases. Repeat until convergence:
For j = 0 : θ 0 := θ 0 − η
m
X^ m
i=
(hθ (x(i)) − y(i))x( 0 i ) (3)
For j ≥ 1 : θj := θj − η
m
X^ m
i=
(hθ (x(i)) − y(i))x( ji )+ λ m
θj
In the second case (j ≥ 1), the term (^) mλ θj represents the partial derivative of the regularization term with respect to θj : ∂ ∂θj
λ 2 m
θ^2 j
λ m
θj
We can rewrite the update rule for j ≥ 1 by grouping the terms containing θj. This provides an interesting intuitive interpretation of the regularization effect:
θj := θj
1 − η
λ m
− η
m
X^ m
i=
(hθ (x(i)) − y(i))x( ji ) (5)
In this formulation:
1 − η (^) mλ
is usually a positive number slightly less than 1 (since η and λ are small and positive).
This effect is known as Weight Decay, as it forces the parameters to decay towards zero at each step unless the data strongly supports a different value.
4 Perceptron
The perceptron is a learning algorithm for binary classification problems, useful for its update rule. Given x ∈ Rd^ the hypothesis space is composed of all linear functions in the input space
θT^ x
where θ ∈ Rd^ are the parameters we want to learn from the data. When we use this model, we assume the the data are linearly separable: exists a line or hyperplane that cut the space and separates the data in two class. To do that we use sign function. The algorithm follows this:
where the θT^ x is the untransformed condition. Classification is correct if the prediction is the same as the label y, so if θT^ xy has the positive sign. If our prediction involves a negative score ( θT^ xy ≤ 0), while y is positive, the prediction is incorrect. So, when there is an error, we enter the if condition: we adjust the weight θ′^ = θ ± xy
So now is: θ′T^ xy = (θ + xy)T^ xy = θT^ xy + xT^ x What can we do if we don’t have linearly separable data? We have two kinds of solutions:
||θ∗|| = 1 θk+1^ ∗ θ∗^ ≤ ||θk+1|
so: ||θk+1|| ≥ kγ
4.1.1 2. Upper bound
This tell you the number of steps is for sure is less or equal than this other value. The step analyzes the squared norm of the new weight vector (θk+1), which has been updated following the misclassifications of example j. ||θk+1||^2 = ||θk^ + yixi||^2 = ||θk||^2 + ||yixi||^2 + 2(θk^ ∗ yixi)
Being that the updating happens only when there is an error, where the condition to that is (θk^ ∗ yixi) ≤ 0, the product 2(θk^ ∗ yixi) would be negative. So when we delete this term, we increase the values in the right of the equation
||θk+1||^2 = ||θk^ + xi||^2 ≤ ||θk||^2 + ||xi||^2
||θk||^2 + ||xi||^2 + 2(θk^ ∗ yixi) ≤ ||θk||^2 + ||xi||^2
Being that the second assumption is ||xi|| ≤ R
||θk+1||^2 ≤ ||θk||^2 + R^2
and if we assume that θ^0 = 0, we have that:
∥θk+1∥^2 ≤ kR^2
Now we combine the two binding limits and we can see
k^2 γ^2 ≤ ||θk+1||^2 ≤ kR^2
Which implies that k^2 γ^2 ≤ kR^2 , so k ≤ R
2 γ
5 Logistic Regression
When you do not have a separable line or hyperplane to classify each example we are not sure if the model will converges or not. In this case we use the Logistic Regression. This model is a classification algorithm, which has a property that 0 ≤ hθ (x) ≤ 1, hence it can be represent has a probability to predict the belonging of an observation in one of the two classes. The hypothesis function follow a sigmoid function
hθ (x) = g(θT^ x) where g(z) =
1 + e−z
the probability interpretation can be written more formally in this way:
hθ (x) = p(y = 1|x; θ)
That is the probability that y belong to the class 1 give x and the parameter θ. Using the marginal- ization property we can obtain:
p(y = 1|x; θ) + p(y = 0|x; θ) = 1 (6) p(y = 0|x; θ) = 1 − p(y = 1|x; θ) (7)
= 1 −
1 + e−θT^ x^
e−θ
T (^) x
1 + e−θT^ x^
To prevent overfitting, regularization can be used, in fact, the latter adds a penalty to the cost function for large coefficient, promoting a more general and less complex model.
The decision boundary is still linear and occurs when the probability of belonging to the negative class is equals to the probability of belonging to the positive class, hence, when both probability are equal to 0.5:
p(y = 1|x; θ) = p(y = 0|x; θ) = (10) 1 1 + e−θT^ x^
e−θ
T (^) x
1 + e−θT^ x^
1 = e−θ
T (^) x (12) ln(1) = ln(e−θ
T (^) x ) (13) 0 = θT^ x (14)
This model has a convex loss function, derived from the likelihood function. in fact if we use the MSE in this case would produces an irregular curve , with many local minima. If Gradient Descent begins training at an unlucky starting point, it risks to fails in finding the true global minimum. The goal is to maximize the model’s likelihood. The probability distribution for each training example can be written as P (y(1), · · · , y(m)|x(1), · · · , x(m); θ). Assuming that the samples are IID, the likelihood function can be written as:
L(θ) = P (y(1), · · · , y(m)|x(1), · · · , x(m); θ) =
Y^ m
i=
p(y(i)|x(i); θ)
To facilities computation, we maximize the log-likelihood function The resulting cost function for logistic regression, also know cross-entropy or log loss, is:
J(θ) =
m
X^ m
i=
cost(hθ (x(i)), y(i))
logit(p) = ln
p 1 − p
= logit(p) = ln
1 1 −e−z e−z 1 −e−z
= logit(p) = ln
1 − e−z
1 − e−z e−z
= logit(p) = ln
e−z
= logit(p) = ln (ez^ ) (19) = logit(p) = z (20)
Meaning that the inverse of the Sigmoid. We apply the derivative of the sigmoid function
d dz
σ(z) =
d dz
f (x) g(x)
d dz
1 + e−z^
d dz
σ(z) =
0 ∗ (1 + e−z^ ) − 1 ∗ ((−1) ∗ e−z^ ) (1 + e−z^ )^2
e−z (1 + e−z^ )^2
1 + e−z^
e−z 1 + e−z^
1 + e−z^
1 − 1 + e−z 1 + e−z^
1 + e−z^
1 + e−z^
1 + e−z 1 + e−z
1 + e−z^
1 + e−z
= σ(z) ∗ (1 − σ(z)) (28)
Now we write the loss function in term of partial derivatives:
m
X^ m
i=
[y(i)^ ∗ log(hθ (x(i))) + (1 − y(i)) ∗ log(1 − hθ (x(i)))]
∂θ
J(θ) = −
m
X^ m
i=
yi^ ∗
hθ (xi)
∂θ
hθ (xi) + (1 − yi) ∗
(1 − hθ (xi))
∂θ
(1 − hθ )
m
X^ m
i=
yi^ ∗
hθ (xi)
∗ σ(z) ∗ (1 − σ(z))
∂θj
(θT^ xi) + (1 − yi) ∗
(1 − hθ (xi))
∗ σ(z) ∗ (1 − σ(z))
∂θj
(θT^ xi)
m
X^ m
i=
yi^ ∗
hθ (xi)
∗ hθ (xi) ∗ (1 − hθ (xi)) ∗ xi^ − (1 − yi) ∗
(1 − hθ (xi))
∗ (−hθ (xi)) ∗ (1 − hθ (xi)) ∗ xi
m
X^ m
i=
yi^ ∗ (1 − hθ (xi)) ∗ xi^ − (1 − yi) ∗ hθ (xi) ∗ xi
m
X^ m
i=
yi^ − yihθ (xi) − hθ (xi) + yihθ (xi)
xi
m
X^ m
i=
yi^ − hθ (xi)
xi
m
X^ m
i=
hθ (xi) − yi
xi
That is the same of the linear regression
Overfitting occurs when a model is too complex and fits the training data too well, resulting in poor generalization to new data. Regularization helps mitigate this problem by adding a penalty term to the cost function
m
X^ m
i=
[y(i)^ ∗ log(hθ (x(i))) + (1 − y(i)) ∗ log(1 − hθ (x(i)))] +
λ 2 m
X^ m
j=
θ^2 j
The regularization term penalizes large values of the model parameters, encouraging the model to learn a simpler representation of the data. The parameter λ controls the strength of regularization
min θ
J(θ) = min θ
m
X^ m
i=
[y(i)^ ∗ log(hθ (x(i))) + (1 − y(i)) ∗ log(1 − hθ (x(i)))] +
λ 2 m
X^ m
j=
θ^2 j
Repeat until convergence {
θ′ 0 = θ 0 −
η m
X^ m
i=
(hθ (xi) − yi)xi 0
θj ′^ = θj − η
m
X^ m
i=
(hθ (xi) − yi)xij +
λ m
θj
(j = 1, · · · , n)
} The term 1 − η (^) mλ in the update rule for θj ; (j = 1, · · · , n) shrinks the value of the parameter at each iteration, implementing ”weight decay”. This helps reduce the complexity of the model and prevent overfitting.
6 Regularization and other ways to control model complexity
Regularisation is a technique used to control the model complexity when we build a ML model we have to think about:
Regularisation introduce a penalty term to the error function, in the way that discourages the model coefficients from taking on large values. A common way to implement it is to add the sum of the squares of the coefficients of the weight vector to the error function. The result is a simpler model that is less prone to overfitting. This introduces a Hyperparameter, that controls the balance among fitting the training data and the model complexity. The choice of the hyperparameter value is crucial to allow training complex models on limited sized datasets without excessive overfitting and is performed using techniques like cross-validation.