0% found this document useful (0 votes)
106 views4 pages

Solutions for Understanding ML Chapter 2

The document presents solutions to exercises from Chapter 2 of 'Understanding Machine Learning' by Shai Shalev-Shwartz and Shai Ben-David. It discusses the existence of a polynomial predictor based on a training set and explores concepts of binary classifiers, including the expected loss and the properties of rectangles in classification. The exercises demonstrate the application of theoretical concepts in machine learning, including the realizability assumption and the bounding of probabilities in classifiers.

Uploaded by

alinaiacob9517
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views4 pages

Solutions for Understanding ML Chapter 2

The document presents solutions to exercises from Chapter 2 of 'Understanding Machine Learning' by Shai Shalev-Shwartz and Shai Ben-David. It discusses the existence of a polynomial predictor based on a training set and explores concepts of binary classifiers, including the expected loss and the properties of rectangles in classification. The exercises demonstrate the application of theoretical concepts in machine learning, including the realizability assumption and the bounding of probabilities in classifiers.

Uploaded by

alinaiacob9517
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Solutions to

Understanding Machine Learning


by Shai Shalev-Shwartz and Shai Ben-David

Chapter 2 (A Gentle Start)

Zahra Taheri1
Feb 2020

Exercise 2.1
Let f be the labeling function. We want to show that given a training set S as follows

S = ((xi , f (xi )))m d m


i=1 ⊆ (R × {0, 1}) ,

there exists a polynomial pS such that hS (x) = 1 if and only if pS (x) ≥ 0, where hS : X → Y is the
following predictor:


 yi if ∃i ∈ [m] s. t. x = xi
hS (x) =
 0 otherwise

where [m] = {1, . . . , m} and yi = f (xi ), for all i ∈ [m].


Obviously, we have:

 1 if ∃i ∈ [m] s. t. x = xi and yi = 1
hS (x) =
 0 otherwise

It is easy to see that if yi = 0, for all i ∈ [m], then hS (x) = 0, for all x ∈ X . In this case, if
pS (x) := −1, for all x ∈ X , then the statement is obviously true.
Suppose that there exists an i in [m] such that yi = 1.
1. Let m = 1 and S = ((x1 , 1)). Then hS (x1 ) = 1 and hS (x) = 0, for all x ∈ X \ {x1 }. So we must
have pS (x1 ) ≥ 0 and pS (x) < 0, for all x ∈ X \ {x1 }. Let pS (x) := −∥x − x1 ∥2 . It is easy to see that
pS (x1 ) = 0 and pS (x) < 0, for all x ∈ X \ {x1 }.
2. Let m = 2. Then without loss of generality we may assume that S = ((x1 , 1), (x2 , 0)) or S =
((x1 , 1), (x2 , 1)).

1
[Link]
1
2

(1) If S = ((x1 , 1), (x2 , 0)), then hS (x1 ) = 1 and hS (x) = 0, for all x ∈ X \ {x1 }. So, similar to the
case (1), by defining pS (x) := −∥x − x1 ∥2 , the statement is obviously true.
(2) If S = ((x1 , 1), (x2 , 1)), then hS (x1 ) = hS (x2 ) = 1 and hS (x) = 0, for all x ∈ X \ {x1 , x2 }. So
we must have pS (x1 ) ≥ 0, pS (x2 ) ≥ 0 and pS (x) < 0, for all x ∈ X \ {x1 , x2 }. With a similar
discussion as above, let pS (x) := −(∥x − x1 ∥2 )(∥x − x1 ∥2 ). Then pS (x) is a polynomial such that
pS (x1 ) = pS (x2 ) = 0 and pS (x) < 0, for all x ∈ X \ {x1 , x2 }, and so the statement is obviously
true.

Inductively, we can generalize the obtained polynomials in cases (1) and (2) as follows:

Y
pS (x) := − ∥x − xi ∥2
i∈[m] yi =1

Then pS (x) is a polynomial such that pS (xi ) = 0, for all i ∈ [m] s. t. yi = 1, and pS (x) < 0, for all
x ∈ X \ {xi |i ∈ [m] and yi = 1}, and so the statement is obviously true.

Exercise 2.2
Let H be a class of binary classifiers over a domain X and D be a probability distribution over X . Let
f be the target hypothesis in H. Let S = ((xi , f (xi )))m
i=1 be a training set such that x1 , . . . , xm are
1 Pm
i.i.d with respect to D, denoted by S|X ∼ Dm . Fix some h ∈ H. Since LS (h) = m i=1 1h(xi )̸=f (xi ) , we

have:
m
∗ 1 X
ES|X ∼Dm [LS (h)] = Exi ∼D [1h(xi )̸=f (xi ) ]
m
i=1
m
∗∗ 1 X
= Ex∼D [1h(x)̸=f (x) ]
m
i=1
 
1
= m Px∼D [h(x) ̸= f (x)]
m
= L(D,f ) (h)

* Expectation is linear
** x1 , . . . , xm are i.i.d

Exercise 2.3
Let S = ((xi , yi ))m
i=1 be a training set.

1. Let R(S) be the rectangle returned by A and A(S) : X → Y be the corresponding hypothesis.
Since A returns the rectangle enclosing all positive examples in the training set, A(S)(xi ) = 1, for all
Solutions to Understanding Machine Learning-Chapter 2 3

i ∈ [m] such that yi = 1. On the other hand, by the realizability assumption, there exists h∗ ∈ Hrec
2

such that LS (h∗ ) = 0, and so h∗ (xi ) = 1, for all i ∈ [m] such that yi = 1. Since A returns the smallest
rectangle enclosing all positive examples, LS (A(S)) = 0 and so A is an ERM.
2. Let D be a probability distribution over X . Also let R∗ = (a∗1 , b∗1 , a∗2 , b∗2 ) be the rectangle that
generates the labels and f be its corresponding hypothesis. Suppose that R1 , . . . , R4 are defined as in
the hint of this exercise.

Figure 1.

By the definitions of R(S) and R∗ we have R(S) ⊆ R∗ . Also we have,

/ S|X and f (x) = 1}) = D(R∗ \ R(S)).


L(D,f ) (A(S)) = D({x ∈ X : A(S)(x) ̸= f (x)}) = D({x ∈ X : x ∈

Since, the probability mass of the rectangle Ri is exactly 4ε , for all i ∈ {1, 2, 3, 4}, if S contains (positive)
examples in all of the rectangles R1 , . . . , R4 , then D(R∗ \R(S)) ≤ 4( 4ε ) = ε. Therefore, L(D,f ) (A(S)) ≤ ε.
Now, we would like to upper bound Dm ({S|X : L(D,f ) (hS ) > ε}). With the discussion above, if S
contains (positive) examples in all of the rectangles R1 , . . . , R4 , then L(D,f ) (A(S)) ≤ ε. Therefore,

4
[
{S|X : L(D,f ) (hS ) > ε} = {S|X : S|X ∩ Ri = ∅}.
i=1

ε
It is easy to see that Dm ({S|X : S|X ∩ Ri = ∅}) = (1 − 4ε )m ≤ e− 4 m , for all i ∈ {1, 2, 3, 4}. With the
ε ε
discussion above and the union bound, Dm ({S|X : L(D,f ) (hS ) > ε}) ≤ 4i=1 e− 4 m = 4e− 4 m . So, the
P

4 log(4/δ)
assumption m ≥ ε completes the proof.
4

3. Similar to the definition of axis aligned rectangles in R2 , given real numbers a1 ≤ b1 , . . . , ad ≤ bd ,


define the classifier h(a1 ,b1 ,...,ad ,bd ) as follows:

 1 if ai ≤ xi ≤ bi , for all i ∈ [d]
h(a1 ,b1 ,...,ad ,bd ) (x1 , . . . , xd ) =
 0 otherwise

Also, the class of all axis aligned rectangles in Rd is defined as follows:

d
Hrec = {h(a1 ,b1 ,...,ad ,bd ) : a1 ≤ b1 , . . . , ad ≤ bd }.

For i ∈ [2d], we define rectangles Ri similar to R1 , . . . , R4 in the latter case, with the probability mass
ε
2d . By generalizing the algorithm A to the case Rd , the proofs of parts (1) and (2) are straightforward
2d log(2d/δ)
(by considering a training set of size ≥ ε ).

Common questions

Powered by AI

The minimum number of samples m is crucial because it controls the probability of the learned hypothesis A(S) exceeding a specific error threshold ε. Specifically, the bound involves ensuring that the learned hypothesis from any drawn sample is accurate enough to encapsulate the true distribution within a probabilistic error range. The sample complexity, expressed through m ≥ 4 log(4/δ) / ε, implies that as more samples are considered, the probability that the error surpasses ε diminishes exponentially based on the union bound for disjoint region errors and the ability of the hypothesis to contain enough positive examples. This ensures high reliability of learning with respect to sampling variation and error constraints .

An ERM hypothesis can guarantee zero empirical loss on a training set by ensuring that it is consistent with all positive instances in the data. For the exercise involving rectangles, the minimal rectangle enclosing all positive examples (instances with yi = 1) is returned by the algorithm A. Since A is designed to enclose all positive examples, the hypothesis A(S) results in no misclassification of these examples, hence achieving LS(A(S)) = 0. If the realizability assumption holds that such a consistent rectangle exists within the hypothesis class, the zero empirical loss is guaranteed over the training set .

Polynomials as classifiers face challenges like overfitting and computational complexity due to high-degree terms which can model complex, non-linear decision boundaries. The risk of overfitting is particularly high if the polynomial degree is large relative to the number of training samples, capturing noise rather than the underlying pattern. Machine learning addresses these challenges through regularization techniques that penalize large coefficients, thereby smoothing the decision boundary. Moreover, strategies like cross-validation, selecting simpler models, and dimensionality reduction techniques (e.g., PCA) help ensure that such polynomial functions generalize well beyond the training data .

In learning classifiers, the probability distribution D over the domain X assigns a likelihood to the occurrence of each example from X within the training data. The distribution impacts the expected loss of classifiers: the expected loss under D, or L(D,f)(h), is the probability that h misclassifies an example drawn from D. Moreover, the standard assumption is that training examples are independently drawn according to D, which is crucial for determining the generalization of classifiers from training to unseen data and ensures that analytical expressions related to expected loss are well-defined .

The class of axis-aligned rectangles generalizes by constructing classifiers using conditions on each dimension individually, i.e., h(a1,b1,...,ad,bd)(x1, ..., xd) = 1 if ai ≤ xi ≤ bi for all i ∈ [d]. This generalization implies that higher dimensional spaces require different partitioning strategies to cover the sample space effectively with rectangles. The implication for sample size is significant, as the number of samples required increases with dimensionality. Specifically, the algorithm must be fed a dataset with a size at least proportional to 2d log(2d/δ) / ε, reflecting the exponential growth of possible partition sites in higher dimensions .

Constructing a polynomial pS for a hypothesis hS that correctly classifies a training set S involves defining pS(x) in terms of the Euclidean distance to the points xi in the training set where the label yi is 1. For a dataset S = ((xi, f(xi)))m i=1, where f is the labeling function, the polynomial pS(x) could be constructed as pS(x) := - ∏{i ∈ [m] : yi = 1} ∥x - xi∥^2. This means that for any point x in the input domain, pS(x) is less than 0 if x does not coincide with any xi having yi = 1, and is exactly 0 at these points, ensuring that hS(x) = 1 if and only if pS(x) ≥ 0 .

In machine learning, hypothesis testing often involves existential quantifiers to define classifier performance by verifying the existence of specific conditions under which a model guarantees or maximizes performance. For example, the existence of a point x in the dataset where the classifier predicts correctly is tested by evaluating existential conditions in the context of binary classifiers. The approach leverages mathematical reasoning to ensure that, given a hypothesis and its polynomial construct, there exists an i such that x equals a point xi from positive instances (ones the classifier must correctly label). Through these logical constructs, performance can be mathematically assessed in scenarios concerning overfitting and underfitting potential, ensuring robust Model Verification .

The assumption that samples are independently and identically distributed (i.i.d) underlies many theoretical results in machine learning, as it simplifies the statistical analysis of learning algorithms. The i.i.d assumption enables general results on reliability and performance to be derived by ensuring that any bias variance is uniformly distributed across the sample dataset. It assures that results, such as expected losses or error bounds, hold universally across any draw from the distribution. This assumption allows practitioners to apply theoretical findings, like loss minimization bounds or PAC-learning guarantees, confidently to real-world scenarios. It additionally aids in constructing probabilistic arguments for convergence and robustness of machine learning systems .

Understanding the relationship between label functions and polynomials aids in designing classifiers by enabling a direct mapping to polynomial constructs that separate labeled instances effectively. Theoretically, this involves designing a polynomial pS such that pS maps to separation regions for binary classifications delineated by the label function f. This transforms the label-function-based decision into a numerical computation where pS evaluates as greater than or equal to zero for desired outcomes (classification label equals 1) and less elsewhere, providing a robust foundation for constructing decision boundaries. Leveraging known properties of polynomials, such as continuity and differentiability, further helps refine such classifiers for efficiency and robustness in modeling complex data distributions .

Linearity in expectation is crucial because it allows for separating the expected loss into a sum over all individual data points, thereby simplifying the analysis and computation. This property ensures that the expected empirical loss, ES[LS(h)], over independently drawn datasets is equivalent to the expected true loss (risk) over the distribution, which is essential for assessing a classifier's performance across diverse datasets consistently. It allows researchers to predict how the average loss behaves when a particular classifier is applied to a probabilistic framework—critical for deducing generalization capabilities .

You might also like