Docsity
Trusted Seller

Machine Learning Exams up to 2020, Prove d'esame di Machine learning

Toggle sidebar
bg1
!LucasMac !Machine Learning Questions !LucasMac !
Overfitting
Problem. Overfitting
Provide a formal (domain-independent and solution-independent) definition of overfitting.
Proof :
Given hypothesis space H, given h∈Hand with error and training set errorS(h), while error of entire
distribution Dis errorD(h).
Consider to have another h′∈Hin which we have that if errorS(h)< errorS(h′) =⇒
errorD(h)> errorD(h′). This means that hoverfit training data.
Problem. Overfitting in Decision Trees
Discuss the problem of overfitting in learning with Decision Trees and illustrate possible solution to it.
Proof :
We can have problem of overfitting in Decision Tree in particular when we have noise data in our dataset
or when you create a tree that is too deep and too specific for a particular training set because also if you
obtain an accuracy that us better than another decision tree that is more generic you risk to have a huge
overfit.
We can avoid overfit using two different methods:
•we stop growing the tree when data is not splitting in a significant way and when I don’t see any
improve in performance, or
•we build the complete tree and we start cutting some part of the tree to reduce his size (post-prune)
because growing the full tree means that we remove some branches.
Post-prune is the best idea. There are two types of post-prune: Reduced error-pruning and Role post-
pruning.
With Reduced-error pruning we split data in training test and validation test. Until prune is harmful we
remove all the subtree and assign the most common classification, then we select node to remove that is the
most improves validation set accuracy.
This reduced-error pruning is good only for subtree of our decision tree and furthermore if we have a small
training set it ca give us bad results.
Role-post pruning is a variant of reduced post-pruning and we infer the decision tree allowing for overfitting
and then we convert our tree into an equivalent set of rules, this because each data of the tree produce
different rule and converting you can see this distinction, so you can prune in different way.
After converting you prune each rule independently of others and finally sort final rules into a sequence that
you want to use.
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23

Anteprima parziale del testo

Scarica Machine Learning Exams up to 2020 e più Prove d'esame in PDF di Machine learning solo su Docsity!

Overfitting

Problem. Overfitting

Provide a formal (domain-independent and solution-independent) definition of overfitting.

Proof :

Given hypothesis space H, given h ∈ H and with error and training set error S (h), while error of entire

distribution D is error D (h).

Consider to have another h

′

∈ H in which we have that if error S (h) < error S (h

′

) =⇒

error D (h) > error D (h

′

). This means that h overfit training data.

Problem. Overfitting in Decision Trees

Discuss the problem of overfitting in learning with Decision Trees and illustrate possible solution to it.

Proof :

We can have problem of overfitting in Decision Tree in particular when we have noise data in our dataset

or when you create a tree that is too deep and too specific for a particular training set because also if you

obtain an accuracy that us better than another decision tree that is more generic you risk to have a huge

overfit.

We can avoid overfit using two different methods:

  • we stop growing the tree when data is not splitting in a significant way and when I don’t see any

improve in performance, or

  • we build the complete tree and we start cutting some part of the tree to reduce his size (post-prune)

because growing the full tree means that we remove some branches.

Post-prune is the best idea. There are two types of post-prune: Reduced error-pruning and Role post-

pruning.

With Reduced-error pruning we split data in training test and validation test. Until prune is harmful we

remove all the subtree and assign the most common classification, then we select node to remove that is the

most improves validation set accuracy.

This reduced-error pruning is good only for subtree of our decision tree and furthermore if we have a small

training set it ca give us bad results.

Role-post pruning is a variant of reduced post-pruning and we infer the decision tree allowing for overfitting

and then we convert our tree into an equivalent set of rules, this because each data of the tree produce

different rule and converting you can see this distinction, so you can prune in different way.

After converting you prune each rule independently of others and finally sort final rules into a sequence that

you want to use.

BAYES

Problem. Naive Bayes Classifier & Optimal

Describe the Naive Bayes Classifier and highlight the approximation made with respect to the Bayes

Optimal Classifier.

Proof :

Naive Bayes Classifier is a classifier able to find most probable classification for a new instance that is not

in the data set, it uses values of attribute, in particular instance is described with values of attribute.

Given D = {(x n

, t n

N

n= 1

} dataset, target function f : X → V, V = {v 1

, ..., v k

P (v j

|x, D) = P (v j

|a 1

, ..., a n

, D)

We need to maximize this to compute naive Bayes classifier class of new instance x

V

N B

= argmax

v j ∈V

P (v j

|D)

i

P (a i

|v j

, D)

Naive Bayes respect to Bayes optimizer don’t compute ”optimal value” but it do approximation and it

doesn’t need hypothesis and prior probability to find most probable classification for a new instance, and

this means that Naive Beyes don’t have problem of size of H that has Bayes optimal classifier.

Of course we lost optimality but approximation of Naive Bayes classifier are good enough.

Problem. Naive Bayes Classifier

Define the concept of Naive Bayes Classifier

Proof :

Given a dataset D = {(x n , t n

N

n= 1

} a target function f : X → v, V = v 1 , ..., v n and a new instance x ∕∈ D

that is described with values of attributes a 1 , ..., a n

V

N P = argmax

V J ∈V

P (v J |x, D) = argmax

V J ∈V

P (v J |a 1 , ..., a n , D) = argmax

V J ∈V

P (v J

|D)

i

P (a i , v J

, D)

If we assume that:

P (a i

, ..., a n

|v J

, D) =

i

P (a i

, v J

, D)

Naive Bayes use conditional independence to approximate P (a i

|v J

, D), this because we don’t have prior

probability of hypotheses and in this case we have values of attribute so we don’t compute ”optimal” value

for not probable classification of new instance but approximation give us good result.

Problem. Solve Naive Bayes

Provide design and implementation choices for solving the following problem through Naive Bayes

Classifier :

Classification of scientific papers in categories according to their main subject. The categories to be

classified are ML (Machine Learning), KR (Knowledge Representation), PL (Planning). Data available

for each scientific paper are: title, authors, abstract and publication site (name of the journal and/or of

the conference).

Proof :

We have 3 classes, so I need to use Naive Bayes with multinomial with probability P (c i ) = probability of

that particular class between ML, KR, PL.

We must estimate P (c j ) and P (w i |c j ), where w i is the i-th word and P (w i |c j ) is the probability to find word

w i given a class c j

v N B

= argmax

c j

P (c j

length(d)

!

i

P (w i

|c j

, D)

where d is the document that we want to analyze.

Logistic Regression Problems

Problem. Logistic Regression

Consider a Dataset D = {< (a 1

, s 1

), p 1

>, ..., < (a N

, s N

), p n

>} containing the number of hours a i

a

student has attended a course, the number of hours s i

s/he has studied for the course and whether or

not s/he has passed the exam p i

Problem. 1

Define a model based on logistic regression that, given the values of a and s, estimates whether a

student passes the exam or not.

Proof :

Giving a dataset D = {< (a 1 , s 1 ), p 1 >, ..., < (a N , s N ), p n >} and p i

P (t|w) =

N !

i= 1

y

p i

i

( 1 − y i

1 −p i

with y i )(w

T

x i

) = P (C

j |x i ) = posterior probability of class c J

We use cross-entropy function

E(w) = − ln P (t|w) = −

N "

n= 1

p i ln y i

  • ( 1 − p i ) ln( 1 − y i

w

∗

= argmax

w

E(w). In this way we can estimate if student pass or not exams, where w are weights.

We know iterative option to minimize error: Newton-Raphson gradient error respect to w

∇E =

N "

k= 1

(y i − p i )x i

Gradient descent step

w

new

← w

old

− H

− 1

∇E, where H

− 1

is hessian matrix of E(k).

H

− 1 = ∇∇E =

N

i= 1

y i

( 1 − y i

)x i

x

T

i

= X

T RX where R = y i

( 1 − y i

) and ∇E(w) = X

T (y − t)

=⇒ w ← w − (X

T RT )

− 1 · X

T (y − t)

Problem. 2

Discuss which are the parameters of the model that have to be learned based on the given data.

Proof :

Parameter that you have to learn are weight, so w and you update it using iterative method IRLS until there

are termination condition.

Problem. 3

What is suitable error function for learning the parameters of the model?

Error function is a cross entropy

E(w) = − ln p(t|w) = −

N "

i= 1

p i ln y i = ( 1 − p i ) ln( 1 − y i

Autoencoder

Problem. 1

Briefly describe what is the architecture of an autoencoder and its purpose

Proof :

Autoencoder are condition of encoder and decoder, encoder take images in input and return a vector such

as CNN, decoder takes in input a vector and return images so it is composed by deconvolutional layers.

Autoencoder trained is base on reconstruction loss and provides low dimentional representation.

Problem. 2

Draw an example of autoencoder.

Proof :

IN P U T → Encoder →

!

"

"

"

"

"

$

%

%

%

%

%

&

low dimensional representation → DECODER → OU T P U T

  • A is a set of actions
  • δ(x o

, a i

) = x 0

, ∀a i

∈ A is transition function

  • r(x 0 , a i , x 0 ))r(a i ) is reward function

We need to determine optimal policy but in k-armed bandit problem you don’t know δ and r so you need

to find some strategy to find the optimal policy.

In particular here we use value function iteration, more specific Q-learning Q(x 0 , a), often to compute this

π

∗

(x 0 ) = optimal policy = argmax

a∈A

Q(x 0 , a)

Problem. 2

Describe the Reinforcement Learning procedure to compute the optimal policy in the k-armed bandit

problem

Proof :

We have k actions a 1 , ..., a k , r(a i ) = N (μ i , σ i ) gaussian distribution. We choose $-greedy strategy so we have

uniform random choice with probability $ and best choice with probability 1 − $. The training rule is

Q

n (a i

) ← Q

n− 1 (a i ) + α[r t+ 1 (a i

) − Q

n− 1 (a i )], where α = 1 /(r n− 1 (a i

r n− 1

(a i

) is the number of execution of actions a i

up to time n − 1.

π

∗ = argmax Q n

(a i

Problem. Reinforcement Learning (RL)

Problem. 1

Provide a formal definition of the Reinforcement Learning (RL) problem. Describe formally what are

the inputs and the outputs of a RL algorithm.

Proof :

In reinforcement learning problem we have a dataset D = x 1 , a 1 , k 1 , ..., x n , a n , k n

. We want to minimize

reward, so we need to find optimal policy to obtain this.

In RL we have only inputs that are a collection of states, action and reward.

Problem. 2

Describe the main steps of a RL algorithm. Provide an abstract pseudo-code of a generic algorithm for

RL (e.g., Q-learning).

Proof :

Q-learning is an algorithm used to find optimal policy when transition function (δ) and reward function (r)

and not know, so we need to do an approximation with Q-learning where training value of this algorithm is

Q(x, a) ← ¯r + γ max(ˆa(x

′

, y

′

))

where ¯r is the immediate reward, x’ is the state from applying action a in state X, γ is scaling factor and ˆa

is the approximation function of a.

Optimal policy is:

π ∗ (x) = argmax

a∈A

ˆa(x, a)

We need to execute action and collect reward to find value of ˆa(x, a)

MARKOV

Problem. Markov Property, MDP, HMM

Describe the Markov property of Markovian models representing dynamic systems. Describe the dif-

ference between a Markov Decision Process (MDP and a Hidden Markov Model (HMM). Draw and

explain the graphical models of MDP and HMM.

Proof :

Markov property says that once the current state is known, the evolution of the dynamic system does not

depend on the history of states, actions and observations. The current state contains all information to know

and it doesn’t depend of precedent history.

In MDP we have < X, A, δ, r >, where X is a finite set of states, A is a set of actions, δ is transition function

and r is the reward function. In MDP we have states that are fully observable so we don’t need observations.

a t

x t

x t+ 1

HMM is composed by < X, Zπ >, where X is set of states, Z is the set of observation and π is initial

distribution.

In this case state are non-observable so we need observation but also in this case we have always Markov

property.

z 0

x 0 x 1

z 1

z t

z T

x T x t

Problem. 3

Is Backpropagation algorithm affected by overfitting? If so, how can we avoid or attenuate it?

Proof :

No, because Backpropagation is NOT a training algorithm so it doesn’t suffer of overfitting problem, because

it only propagates gradient value from loss function, computed in Forward Pass to the input in the backed

pass.

CNN

Problem. 1

Describe the convolutional stage of a Convolutional Neural Network (CNN)

Proof :

CNN is a neural network that use a convolutional function between input and kernel. It is composed by 3

stage, where the first one is the convolutional stage.

Convolutional stage is

(I · K)(i, j)

this is cross correlation

M

n

I(i + m, j + n)k(m, n)

Problem. 2

Discuss the properties of sparse connectivity and parameter sharing for CNN.

Proof :

In this stage we apply sparse connectivity, it means that only a subset of units is connected to the input, in

fact usually the kernel is much smaller than input so the output depends only on few inputs. In this case

each unit sees only a part of the precedent nodes and each node influences only a group of the next nodes.

The weights used at each node are the same used by the other nodes: all the vectors has the same weight

cause is the middle value of the kernel, so the only weights that are present are the one on the kernel and

the kernel size does not depend on the input size. We reduce the number of operations.

Another thing that is done in this stage is parameter sharing in which units of layer share a set of parameter.

In this way we increase efficient because we don’t need to learn mode parameters, such as in traditional

neural network.

Another important aspect is Padding, we have ”valid” padding when output contains only valid values (de-

pends on kernel size) and ”same” padding where input layer is padded with zeros (output size depends of

kernel size).

Problem. CNN practice

Consider a CNN with the following structure for its two layers:

conv 1 5 × 5 kernel and 64 feature maps with padding 2 and stride 1

relu 1 acting on ’conv 1 ’

pool 1 2 × 2 max pooling with stride 2 acting on ’relu 1 ’

conv 2 3 × 3 kernel and 128 feature maps with padding 0 and stride 2

relu 2 acting on ’conv 2 ’

pool 2 2 × 2 max pooling with stride 4 acting on ’relu 2 ’.

Problem. 1 - 2

For input images of dimension 1242 × 378 × 3 compute the dimensions of the volume on the output of

each layer and explain how it is computed.

Describe what is the number of parameters of each layer.

Proof :

Image 1242 × 378 × 3.

Dimensionality reduction

Problem. Exercise

Consider the binary (black & white) images below defined on 12 × 12 grid:

Problem. 1

Explain what is the dimensionality of the data space and what is the intrinsic dimensionality of the

given data.

Proof :

The dimensionality of the data space is the dimension of the images that in our case is 12 × 12 because we

have this matrix in input and for the dimensionality we have 3 because it correspond of translation and 1

rotation, so we have 3 degree of freedom.

Problem. 2

Suppose you apply PCA on the data x 1

, ..., x 6

and find that the data can be fully described using M

principal components, namely u 1

, ..., u M

. Describe how the original data can be written in the space

defined by these M principal components.

Proof :

We assume basis vector and we want, with eigenvalues and a sample x i

, to compute mean of x 1

, ..., x 6

so x =

6 "

k= 1

x n

, then [μ 1

x 1

, ..., μ N

x 6

], we maximize and obtain μ

T

i

Sμ i

= λ i

, where S is variance and to

maximize variance we consider to have μ i eigenvector corresponding to the latest eigenvalue λ i

Problem. 3

Is M going to be equal to the number of intrinsic dimensions? Explain

Proof :

M is generally different of 3 because principal components of PCA are NOT latent variables.

SVM & Perceptron

Problem. Support Vector Machine Regression

Consider the following energy-like function defining Support Vector Machine regression:

J(w, C) = C

N "

i= 1

L

! (t i , y i

||w||

2

with y i , t i target and predicted values, respectively, and L ! (t, y) =

0 if |t − y| < $

|t − y| − $ otherwise

the

$-insensitive error function.

Problem. 1

Plot the $-insensitive error function and explain what is the difficulty in minimizing J.

Proof :

L(z)

The problem of minimizing T is that is not differen-

tiable so it is difficult to solve.

Problem. 2

To overcome this difficult slack variables ξ

and ξ

−

are introduced. Explain (qualitatively) the role of

the slack variables.

Proof :

We use slack variables ξ

and ξ

−

because with them we can compute a gradient region that can be easily

to solve and we don’t have anymore the problem of not differentiable. So, our new optimization model =

minimize the sum of all the ξ variables.

Problem. SVM & Perceptron

Consider the following data set for binary classification, where the two classes are represented with

white and black circles.

Problem. 1

Draw in each of the diagrams below a possible solution based on Perceptron with very small learning

rate and a possible solution based on SVM.

Proof :

When we compute the optimal margin there will be 2 closest points, one for side, and these points will be

at distance 1 from the optimal hyperplane. When the maxim margin hyperplane x

∗

, w

∗

is found, there will

be at least 2 closest points x

⊕

k

and x

⊖

k

(one for each class; otherwise you can move far the plane from the

closest point until it is at the same distance from 2 points in the opposite sides):

w

∗T

x

⊕

k

  • w

∗

0

w

∗T x

⊖

k

  • w

∗

0

distance is

||w||

, where y(x) = w

T

x + w 0

This is the reason why we obtain that solution from SVM

Problem. 3

Discuss which solution do you prefer and why.

Proof :

I prefer SVM respect to perceptron because if a dataset is not linearly separable, perceptron will never

converge, indeed SVM use some slack variables to try to find solution of w and w

∗

0

, so to find the maximum

margin.

Problem. Perceptron

Problem. 1

Describe the perceptron model for classification.

Proof :

Is an iterative method in which we have a linear combination of input dimensions with some weights plus a

constant value w 0. The output will be a function that depends on the sign of the linear combination:

o(x 1

, ..., x d

1 if w 0

  • w 1 x 1
  • ... + w d x d

0 otherwise

In particular perceptron works with a function θ x

o(x) =

1 if w

T x > 0

− 1 otherwise

= sign(w

T

x)

So we have to find find w to have good separation of our classes. Given a dataset D = {(x n , t n

N

n= 1

} we

want to minimize sum of Squared error:

E(W ) =

N "

n= 1

(t n

− θ n

2

=

N "

n= 1

(t n

− w

T

x n

2

We need to derivate this error function with respect to each w i , so it’s on iterative method with a gradient

checking

∂E

∂w i

N "

n= 1

(t n − w

T

x n )(−x i , n)

In fact, the algorithm will just start to move to the negative gradient in order to minimize the error (this

explain the presence of the minus). The algorithm can update weights in order to adjust the classier and

this is done in an iterative way until we divide all the samples of the dataset.

This is the training rule:

w i

← w i

  • ∆w i

∆w i

= −η

∂E

∂w i

= η

N "

n= 1

(t n

− sign(w

T

x n

))x i,n

= η∇E = +η

N "

n= 1

(t n

− w

t

n

where η is the learning rate.

Perceptron improve weights when it finds an instance that is misclassified an in particular perceptron converge

after a FINITE number of steps IF dataset is linearly separable, otherwise it will never converge.

Problem. 2

Describe the perceptron training algorithm

Proof :

We have y = w

T

x, but in particular in this case we have function o(x) =

1 if w

R x > 0

− 1 otherwise

, o = w

T

x.

Given a dataset D = {(x n , t n

N

n= 1

} we want to minimize loss function

E(w) =

N "

n= 1

(t n − o n

N "

n= 1

(t n − w

T

x n

We compute derivate respect to w and we obtain

∂E(w)

∂w i

N "

n= 1

(t n − w

T

x n

2

x i,n

= ∇E

w ← w + ∆w i this is the formula for update weights

where

∆w i = −η∇E = +η

N "

n= 1

(t n − w

T

x n

2

x i,n , where η is the learning rate.

Problem. 3

Discuss convergence properties of perceptron training algorithm.

Proof :

Perceptron converges, so this means that we find a decision boundary that classify our instances in a such

way there is no instance that is misclassified, if dataset D is linearly separable and if learning rate η is too

small, the convergence will be too slow.

Problem. SVM

Problem. 1

Qualitatively explain the margin principle on which Linear SVM classification is based.

Proof :

In SVM we want to maximize margin to provide better accuracy.

Margin is the smallest distance between closest points to the hyperplane (decision boundary) and the hy-

perplane itself.

To find w

∗ and w

∗

0

we maximize that margin, so this means that we need to use Lagrange Method to compute

w

∗ and w

∗

0

, where w

∗

0

is computed using support vectors.

At the end we have

sign(y(x

′

)) = sign

x k ∈SV

a

∗

k

t k x

′T

x K

  • w

∗

0

At the end we obtain that we have thus closest points x

⊕

k

and x

⊖

k

and the distance should be the same

1

||w||

infact w

T · x

⊕

k

  • w 0

= 1 and w

T x

⊖

k

  • w 0

Problem. 3

Discuss why the maximum margin solution is preferred for the classification problem.

Proof :

We can notice how last square is not good in this problem because it’s sensitive to outliers, this because it’s

error is a function that is a sum, so every points in dataset contribute to the solution but this create problem

because it’s decision boundary is not in right position and doesn’t classify better solution, instead SVM is

robust to the outliers so it’s better solution in this case.

Furthermore maximum margin solution is preferred because is a method that create a good separation for

classification of instances, in this way we have a good margin that can provide to classify better also instances

near margin, this not happens in perceptron because we can have decision boundary that has very small

margin and so there is a risk to classify instance not in good way.

Generative and Discriminative probabilistic models for classification

Problem. 1

Describe the difference between generative and discriminative probabilistic models for classification.

Proof :

Both probabilistic models want to compute (estimate) P (C i |x), where i = 1 , ..., n, the probability that given

new instance x is classified of a class C i

Generative probabilistic model using Bayes to estimate this value, in particular

P (C

i |x) =

P (x|C i

)P (C

i

N

i= 1

P (x|C i

)P (C

i

So we compute P (x|C i ) and we have prior probability of that particular learn.

Instead with discriminative we use method of logistic region to estimate P (C i |x), so we estimate that value

directly from a model.

Problem. 2

Draw a 2 D dataset for a binary classification problem and show (also in graphical form) a possible

solution using a probabilistic generative model.

Proof : 2 D dataset of C 1

and C 2

P (C

1

|x) =

P (x|C 1

)P (C

1

P (x|C 1

)P (C

1

) + P (x|C 2

)P (C

2

we assume P (x|C 1

) = N (x|μ 2

, ξ)

They ave gaussian distribution with some covariance, and N 1

one sample of C 1

and N 2

one sample of C 2

N = N

1

+ N

2

P (C

1

) = π

P (C

2

) = 1 − π

we have likelihood function

P (t|π, μ 1

, μ 2

N !

n= 1

πN (x n

|μ 1

t n ( 1 − π)N (x n

, μ 2

( 1 −t n )

maximum likelihood, and we obtain

μ 1

N

1

N "

n= 1

t n

x n

, μ 2

N

2

N "

n= 1

( 1 − t n

)x n

N

1

N

S

1

N

2

N

S

2

, π =

N

1

N

S

i

N

i

n∈C 1

(x n

− μ i

T

(x n

− μ i

) i = 1 , .., 2