QUESTION 1 [4 marks]:
Answer: Part 1)
Purchase 20
Marginal Probability 0.3
Copyright By PowCoder代写 加微信 powcoder
0.7 Total= 100/100
Male Gender Female
Marginal Probability
0.12 0.28 0.4
0.18 0.42 0.6
All joint probabilities equal the multiplication of respective marginal probabilities. Therefore, gender and purchase are independent. For example:
• p(male) x p(purchase=10) =0.3 x 0.4=0.12 = p(Gender=male & purchase=10)
• p(male) x p(purchase=20) =0.3 x 0.6=0.18 = p(Gender=male & purchase=20)
• p(female) x p(purchase=10) =0.7 x 0.4=0.28 = p(Gender=female & purchase=10)
• p(female) x p(purchase=20) =0.7 x 0.6=0.42 = p(Gender=female & purchase=20)
Short answer (acceptable): As we observed in part 1 that gender and purchase are independent, there is no relationship between them. The covariance and correlation coefficient between gender and purchase are both 0. The interpretation is that knowing the gender associated to an observation, does not provide any information about the amount of purchase (and vice versa).
Long answer:
We can assign 0 and 1 (or other numeric values) to male and female for arithmetic calculation. Mean(gender)=0.7
Mean(purchase)=16
Cov(gender,purchase)=
p(Gender=male & purchase=10) x (-0.7) x (-6) +
p(Gender=male & purchase=20) x (-0.7) x (4) +
p(Gender=female & purchase=10) x (0.3) x (-6) +
p(Gender=female & purchase=20) x (0.3) x (4) +
= 0.504 – 0.504 – 0.504 + 0.504 = 0
Correlation coefficient between gender and purchase will be zero too because its numerator is zero. Therefore, there is no relationship between the relative changes of the two variables. The interpretation is that knowing the gender associated to an observation, does not provide any information about the amount of purchase (and vice versa).
QUESTION 2 [4 marks]:
We should find a function g(n) that bounds f(n)=Log(n!) according to the definition of big O.
f(n)=Log(n!) = Log[n(n-1) (n-2) …1] = Log(n) + Log(n-1) + Log(n-2) + … + Log(1) =< Log(n) + Log(n) + Log(n) + ... + Log(n) = nLog(n) = 1nLog(n)
The above chain of equalities and inequalities implies that f(n)=Log(n!) grows at most as fast as g(n)=nLog(n). More formally: Log(n!) =< C nLog(n) for all natural n>n0 (n0=1 and C=1) which proves the statement Log(n!) is O(nLog(n)).
QUESTION 3 [4 marks]:
The bias and the variance are two components which make up the Mean Squared Error – MSE (the reducible error) for our machine learning model. We roughly use the two components and their variability to draw the line for MSE for each plot:
Typically, as the flexibility of a model increases, its bias decreases and its variance increases. So, choosing the flexibility (model selection) based on minimizing the MSE calculated for validation data amounts to a bias-variance trade-off (see 2.9 Model Selection in Hastie et al Elements of Statistical Learning for more info).
The most suitable level of flexibility is where the MSE is the lowest. Accordingly, the lowest points for MSE are determined below which indicate the suitable level of model flexibility (complexity) for reducing the reducible error as much as possible. Note that these lowest points are not necessarily the intersection points of bias and variance. This distinction is more visible in the left plot where bias does not vary with flexibility and the suitable level of flexibility is visibly far from the intersection of bias and variance.
QUESTION 4 [5 marks]:
return y[np.argmin(distance)]
QUESTION 5 [3 marks]:
The average running time for array A will be linearithmic (linear-logarithmic). We do not know anything special about the array A and its elements are distinct. Therefore, the average running time for array A is O(n log(n)) according to the 10% argument (from Lecture 2) that says as long as the pivot ends up on average 10% away from either edges, we get a tree structure and the total number of elementary operations will be O(nh) and the height of the tree, h, grows with O(log(n)). Therefore, the average running time of quicksort is O(n log(n)).
The average running time for array B will be quadratic (The average running time will be O(n2)) because the left-most element selected as the pivot does not move (throughout the algorithm) and the size of the array only decreases by 1 in each step. There will be n steps; and each step takes linear time based on the size of the subarray (Hoare’s method for linear time partitioning) leading to f(n)=n+(n-1)+(n- 2)+…+1=n(n+1)/2 elementary operations for the complete execution of quicksort on array B. f(n) is O(n2).
The average running time for array C will be quadratic too (The average running time will be O(n2)) because the left-most element selected as the pivot moves to the other side of the array (throughout the algorithm) and the size of the array only decreases by 1 in each step. There will be n steps; and each step takes linear time based on the size of the subarray (Hoare’s method for linear time partitioning) leading to f(n)=n+(n-1)+(n-2)+…+1=n(n+1)/2 elementary operations for the complete execution of quicksort on array C. f(n) is O(n2).
distance = np.sum((X – Q)**2, axis=1)
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com