Ass1 Solns
Ass1 Solns
Policies:
For all multiple-choice questions, note that multiple correct answers may exist. However, selecting
an incorrect option will cancel out a correct one. For example, if you select two answers, one
correct and one incorrect, you will receive zero points for that question. Similarly, if the number
of incorrect answers selected exceeds the correct ones, your score for that question will be zero.
Please note that it is not possible to receive negative marks.
While the syllabus initially indicated the need to submit a paragraph explaining the use of AI or
other resources in your assignments, this requirement no longer applies as we are now utilizing
eClass quizzes instead of handwritten submissions. Therefore, you are not required to submit any
explanation regarding the tools or resources (such as online tools or AI) used in completing this
quiz.
This PDF version of the questions has been provided for your convenience should you wish to print
them and work offline.
Only answers submitted through the eClass quiz system will be graded. Please do not
submit a written copy of your responses.
Question 1. [1 mark]
Is the following True or False. (R2 ) × R is a set.
Solution:
True. A Cartesian product is always a set. It is defined as (R2 ) × R = {((x1 , x2 ), y)|x1 , x2 , y ∈ R},
which is a set of tuples where each tuple has an element from R2 and an element from R.
Question 2. [1 mark]
Is the following True or False. (((1, 2), 3), ((1/2, 1/3), 1/4)) is a tuple.
Solution:
True. Since parentheses are used at the outermost level, this is a tuple. It doesn’t matter what the
elements of the tuple are; as long as they are enclosed in parentheses, it is a tuple. It is also clear
that it is not an open interval, since an open interval would have exactly two elements and would
be written as (a, b) where a ∈ R, b ∈ R, and a < b.
Question 3. [1 mark]
Is the following True or False. A tuple can have duplicates.
Solution:
True. Tuples are ordered collections of elements, and they can contain duplicates.
Question 4. [1 mark]
Which of the following is an element of N4 ?
1/15
Fall 2024 CMPUT 267: Basics of Machine Learning
a. (1, 2, 3, 4)
b. (1, 2, 3)
c. (1, 2, 3, 4, 5)
d. (1, 2, 3, π)
Solution:
The correct answer is:
• a. (1, 2, 3, 4)
Explanation:
N4 represents the set of all 4-tuples where each element is a natural number (N).
Question 5. [1 mark]
Which of the following is an element of X × Y where X = R3 and Y = R?
a. (1, 2, 3)
c. ((1, 2, 3), 4)
Solution:
The correct answer is:
• c. ((1, 2, 3), 4)
Explanation:
An element of X × Y is an ordered pair (x, y) where x ∈ R3 and y ∈ R.
b. ((1, 2, 3), (1, 2, 3)): Incorrect. Both elements are in R3 ; the second should be in R.
c. ((1, 2, 3), 4): Correct. The first element is in R3 and the second is in R.
2/15
Fall 2024 CMPUT 267: Basics of Machine Learning
Question 6. [1 mark]
Let D = ((x1 , y1 ), . . . , (xn , yn )) where xi ∈ Rd and yi ∈ {0, 1} for all i ∈ {1, . . . , n}. Then, how
would you write the set of all possible D?
Solution:
The correct answers are:
Explanation:
We need to represent all sequences D of n pairs (xi , yi ) with xi ∈ Rd and yi ∈ {0, 1}.
a. ((Rd ) × {0, 1})n : Correct. This set includes all n-tuples of pairs (xi , yi ) where xi ∈ Rd and
yi ∈ {0, 1}.
b. (X × Y)n where X = Rd and Y = {0, 1}: Correct. This is equivalent to option a., using
variable names.
c. {(z1 , . . . , zn ) | zi ∈ Rd × R, i ∈ {1, . . . , n}}: Incorrect. Here, yi can be any real number, but
it should be restricted to {0, 1}.
Question 7. [1 mark]
Suppose you wanted to keep information of houses being sold. You decide to use two features to
represent each house and to keep track of the price (an element of [0, ∞)) it was sold at. The
first feature was the number of rooms (a natural number), the second feature was age (an element
of [0, ∞)). How would you write the set of all possible houses that are represented in this way?
Elements of this set should look like ((x1 , x2 ), y) where x1 represents the number of rooms, x2
represents the age, and y represents the price.
b. N × [0, ∞) × [0, ∞)
c. (N × [0, ∞)) × N
d. R2 × [0, ∞)
3/15
Fall 2024 CMPUT 267: Basics of Machine Learning
Solution:
The correct answers are:
Explanation:
Each house is represented as ((x1 , x2 ), y) where:
• x1 ∈ N (number of rooms)
• x2 ∈ [0, ∞) (age)
• y ∈ [0, ∞) (price)
b. N × [0, ∞) × [0, ∞): Incorrect. An element of this set would look like (x1 , x2 , y), not
((x1 , x2 ), y).
Question 8. [1 mark]
Let f : (R3 ) × (R3 ) → Y be such that f (x, w) = x> w, where x, w are vectors. If x = (1, 4, 2)> and
w = (1, 2, 3)> , then what is f (x, w)?
Solution:
The correct answer is:
• 15
Explanation:
To find f (x, w), we compute the dot product of x and w:
Question 9. [1 mark]
Let f : R → Y be such that f (x) = 4 + x2 . What is the range of f , and what is a valid codomain
Y?
4/15
Fall 2024 CMPUT 267: Basics of Machine Learning
Solution:
The correct answers are:
Explanation:
f (x) = 4 + x2 is a quadratic function that achieves a minimum value of 4 when x = 0 and increases
without bound as |x| increases. Therefore, the range is [4, ∞).
d. Incorrect. While R is a valid codomain, the range is not all of R; it is restricted to [4, ∞).
a. {f : R → R | f (x) = a0 + a1 x + a2 x2 + a3 x3 and a0 , a1 , a2 , a3 ∈ R}
b. {f : R → R | f (x) = a0 + a1 x + a2 x2 + a3 x3 and a0 , a1 , a2 , a3 ∈ N}
c. {f : R → R | f (x) = a0 + a1 x + a2 x2 and a0 , a1 , a2 ∈ R}
d. {f : R → R | f (x) = a0 + a1 x + a2 x2 + a3 x3 + a4 x4 and a0 , a1 , a2 , a3 , a4 ∈ R}
Solution:
The correct answer is:
• a. {f : R → R | f (x) = a0 + a1 x + a2 x2 + a3 x3 , a0 , a1 , a2 , a3 ∈ R}
Explanation:
b. Incorrect. This set has coefficients as only natural numbers, whereas the definition restricts
coefficients to R.
d. Incorrect. This set includes polynomials of degree up to 4, which exceeds the specified degree.
5/15
Fall 2024 CMPUT 267: Basics of Machine Learning
where n = 2?
Solution:
The correct answers are:
Explanation:
The function A should map input tuples to functions of the form f (x) = xw, where w ∈ R.
a. Incorrect. f (x) = ax + b includes a constant term b, which does not fit the required form
f (x) = xw.
c. Incorrect. f (x) = ax + d includes a constant term d, which does not fit the required form.
ab+cd
d. Incorrect. f (x) = a2 +b2
x is undefined when a = 0 and b = 0.
a. x
b. w
c. x + w
d. 1
Solution:
The correct answer is:
• a. x
6/15
Fall 2024 CMPUT 267: Basics of Machine Learning
Explanation:
The function f (x, w) = xw is a linear function in w. To find the partial derivative of f with respect
to w, we treat x as a constant:
∂f ∂
= (xw) = x
∂w ∂w
Therefore, the partial derivative is x.
a. 2(ŷ − y)
b. (ŷ − y)
c. 2ŷ
d. −2y
Solution:
The correct answer is:
• a. 2(ŷ − y)
Explanation:
Given `(ŷ, y) = (ŷ − y)2 , the partial derivative with respect to ŷ is:
∂`
= 2(ŷ − y)
∂ ŷ
b. (ŷ − y): Incorrect. Missing the factor of 2 from the power rule.
7/15
Fall 2024 CMPUT 267: Basics of Machine Learning
a. 2x(xw − y)
b. 2(xw − y)
c. x
d. 2xw
Solution:
The correct answer is:
• a. 2x(xw − y)
Explanation:
First, express `(f (x, w), y):
∂
`(f (x, w), y) = 2(xw − y) · x = 2x(xw − y)
∂w
a. 2x(xw − y): Correct. Applies the chain rule correctly.
b. 2(xw − y): Incorrect. Missing the multiplication by x.
c. x: Incorrect. This is the partial derivative of f (x, w) with respect to w, not of `.
d. 2xw: Incorrect. This ignores the y term and the product rule.
Solution:
The correct answer is:
• 2
Explanation:
First, compute the sum:
X
x=1+2+3=6
x∈X
Then,
1X 6
x= =2
3 3
x∈X
8/15
Fall 2024 CMPUT 267: Basics of Machine Learning
Pn
a. i=1 xi
Q
b. x∈X x
R
c. X x dx
P
d. x∈X x
Solution:
The correct answers are:
Pn
• a. i=1 xi
• d.
P
x∈X x
Explanation:
When X = {x1 , . . . , xn }, the sum over all x ∈ X is written as:
X n
X
x1 + x2 + · · · + xn = x= xi
x∈X i=1
Pn
a. i=1 xi : Correct.
Q
b. x∈X x: Incorrect. This represents the product, not the sum.
R
c. X x dx: Incorrect. This represents an integral, which is not applicable for finite sums.
P
d. x∈X x: Correct.
b. w ni=1 xi
P
Pn
c. x=1 w
d. w ni=1 xi
Q
Solution:
The correct answers are:
Pn
• a. i=1 xi w
Pn
• b. w i=1 xi
9/15
Fall 2024 CMPUT 267: Basics of Machine Learning
Explanation:
The sum of f (x, w) = xw over all x ∈ X is:
X n
X n
X
f (x, w) = xi w = w xi
x∈X i=1 i=1
Pn
a. i=1 xi w: Correct. Direct substitution of f (xi , w).
Pn
b. w i=1 xi : Correct. Factor w out of the sum.
Pn
c. x=1 w: Incorrect. This sums w n times, ignoring xi .
Qn
d. w i=1 xi : Incorrect. This represents w multiplied by the product of all xi , not the sum.
Solution:
The correct answer is:
Pn
• b. i=1 (xi w − yi )
2
Explanation:
Given D = ((x1 , y1 ), . . . , (xn , yn )), the sum is:
X n
X n
X
2
`(f (x, w), y) = ( xi w −yi ) = (xi w − yi )2
|{z}
(x,y)∈D i=1 f (x ,w) i=1
i
Pn
a. i=1 (ŷi − yi )2 : Incorrect. ŷi is not defined in this context.
Pn
b. i=1 (xi w − yi )2 : Correct. Direct substitution of f (xi , w).
Pn
c. i=1 xi wyi : Incorrect. This represents a different operation, not the squared loss.
Qn
d. i=1 (xi w − yi )2 : Incorrect. This represents the product of squared losses, not the sum.
10/15
Fall 2024 CMPUT 267: Basics of Machine Learning
2 Pn
a. n i=1 xi (xi w − yi )
Pn
b. i=1 xi (xi w − yi )
1 Pn
c. n i=1 2(xi w − yi )
Pn
d. 2 i=1 xi w
Solution:
The correct answer is:
• a. n2 ni=1 xi (xi w − yi )
P
Explanation:
First, express L(`(f (x1 , w), y1 ), . . . , `(f (xn , w), yn )):
n n
1X 1X
L= `(f (xi , w), yi ) = (xi w − yi )2
n n
i=1 i=1
To find the partial derivative with respect to w:
n n
∂L 1X 2X
= 2(xi w − yi ) · xi = xi (xi w − yi )
∂w n n
i=1 i=1
2 Pn 1
a. n i=1 xi (xi w − yi ): Correct. Applies the chain rule and factor of n.
Pn 2
b. i=1 xi (xi w − yi ): Incorrect. Missing the factor n.
1 Pn
c. n i=1 2(xi w − yi ): Incorrect. Missing multiplication by xi .
Pn
d. 2 i=1 xi w: Incorrect. This does not account for the yi terms.
a. 6x
b. 6
c. 6y
d. x
Solution:
The correct answer is:
11/15
Fall 2024 CMPUT 267: Basics of Machine Learning
• a. 6x
Explanation:
We are asked to compute the sum:
X X
f (x, y) = xy
y∈Y y∈{1,2,3}
b. 6: Incorrect. This would be the sum if x = 1, but x is a variable and not necessarily equal
to 1.
c. 6y: Incorrect. The sum results in 6x, not 6y. y is a variable within the summation and does
not factor out.
d. x: Incorrect. This would be the case if the sum had only one term, but there are three
terms being summed.
Solution:
The correct answer is:
• a. 75
Explanation:
First, compute the sum inside the integral:
X X
f (x, y) = xy = x × 1 + x × 2 + x × 3 = x + 2x + 3x = 6x
y∈Y y∈{1,2,3}
12/15
Fall 2024 CMPUT 267: Basics of Machine Learning
a. 4x
b. 6x
c. 2x
d. x
Solution:
The correct answer is:
• a. 4x
Explanation:
Compute the integral: Z Z 3
f (x, y) dy = xy dy
Y 1
Since x is treated as a constant with respect to y, factor it out of the integral:
Z 3 Z 3
xy dy = x y dy
1 1
13/15
Fall 2024 CMPUT 267: Basics of Machine Learning
Solution:
The correct answer is:
• a. 50
Explanation:
First, compute the inner integral:
3 3 3
y2
Z Z Z
9 1
f (x, y) dy = xy dy = x y dy = x =x − = x × 4 = 4x
Y 1 1 2 1 2 2
Solution:
The correct answer is:
• b. 1
2
Explanation:
Since X is uniformly distributed over {3, 5, 7, 9}, each outcome has an equal probability of 14 .
The event X is either 5 or 9 is represented as the set {5, 9}. Therefore,
1 1 1
P(X ∈ {5, 9}) = p(5) + p(9) = + =
4 4 2
Thus, the probability is 12 , which corresponds to option b.
14/15
Fall 2024 CMPUT 267: Basics of Machine Learning
Solution:
The correct answer is:
• b. 3
8
Explanation:
For a continuous uniform distribution over [a, b], the probability that Y lies between c and d (where
a ≤ c < d ≤ b) is calculated as:
Z d
P(c ≤ Y ≤ d) = p(y) dy = p(y) × (d − c)
c
Given:
a=2
b = 10
1
p(y) =
8
c=4
d=7
15/15