Starting from:

$25

CISC5800 -  Machine Learning -  Homework 0 - Solved

A.  Probability: 

1. Consider four multi-valued random variables A (age), O (oxygen level), S (salary), T (body temperature), and W (weight). We know that S is independent of O and T; A is independent of T. We are provided the probability tables/functions for the following six joint, marginal, and conditional probabilities. The six probabilities: 

P(S|W) 
P(A, T) 
P(S, W) 
P(S|O,W) 
P(O|T) 
P(O, T, W) 
 
 
 
 

For example, we could be told:  

P(S=$25K | W=heavy) = 0.3, P(S=$50K | W=heavy)=0.3, P(S=$75K | W=heavy)=0.25,  P(S=$25K | W=light)=0.2, etc…

 

We are not provided any other probability tables; for example, we are not given values for:  P(T=hi) or P(A=old, O=low)

 

Explain how to combine the six five probabilities from above (and the knowledge that S is independent) to compute each probability below, or write “not possible” if it is not possible. For example: P(A) = ∑𝑡 𝑃(𝐴, 𝑇 = 𝑡)  

 

a)  P(W=mid-weight|S=$50K)

b)  P(T=low, W=high)

c)   P(A=old)

d)  P(S=$50K | O=low, T=low )

e)  P(O=high, S=$75K)

f)    P(A=mid-age, S=$100K, T=medium)

 

 

             

2. Consider the following joint probability table:

A
B
C
P(A,B,C)
0
0
0
0.21
0
0
1
0.07
0
1
0
0.11
0
1
1
0.05
1
0
0
0.15
1
0
1
0.27
1
1
0
0.02
 

a)  What is P(A=1, B=1, C=0)?

b)  What is P(A=1, C=1)?

c)   What is P(A=0 or C=0)?

d)  What is P(B=0)?

e)  What is P(C=1|A=0)?

f)    If C=0, is A independent of B? In other words, does P(A,B|C=0) = P(A|C=0) P(B|C=0) ? Show your reasoning.

 

 

 

B. Algebra/Calculus 

Express x as a function of a and b, as simplified as possible.

Example question: 3a=6x+7b

3𝑎−7𝑏

Example answer: 𝑥 =   

6

 

 1. 11𝑥4   2+4𝑎−𝑥4) =6(𝑎

3𝑏2

 

   

 simplify this as much as possible, remove the summation sign, note if j=3, xj is “x cubed”

 

 

 𝑖

 

 

 

 

Consider the function 𝑓(𝑥)=exp(2𝑥3 −6𝑥)=𝑒2𝑥3−6𝑥

𝑑

4.  What is the derivative of f(x) (the derivative with respect to x,    )?

𝑑𝑥

 

 

5.  For what value(s) of x is  f’(x)=0?

 

 

6.  At the value you found above, will f(x) have its smallest possible value?

 

 

 

Consider the function g(x,y)= (Note, for example, 𝑦4 = 𝑦 × 𝑦 × 𝑦 × 𝑦 

7.  What is the value of g(x,y) when x=2, y=1?

 

 

 

8.  What is the derivative of g(x,y) with respect to y : 𝑑𝑦𝑑 𝑔(𝑥,𝑦) ?

 

 

 

C. Programming: 

Use Python to solve the following tasks.

 

 

1. Write a function called neighborClassify that takes in a 1D numpy array of numbers (the heights of unknown animals) and a 2D numpy array containing the heights of known animals. The function will return a list of 0s and 1s – a 0 for each non-giraffe input and a 1 for each giraffe input – using nearest neighbors classification (see below). Specifically, the function call must look like this:

            neighborClassify(featureArray, trainArray) 

featureArray will be a numpy array of shape (n) (where there are arbitrary number n animals to classify) and trainArray is a numpy array of shape (n,2 ) where each row contains first the height of a training animal and then its corresponding class (0 for non-giraffe,

1 for giraffe). Specifically, if featureArray=np.array([6,3,9]) and

trainArray=np.array([[0.5,0], [1.5,0], [2.5,0], [4.5,1], [5,1], 

[7.5, 0], [8,1], [9.2,1]]), the function will return the list [1, 0, 1] .  

 

Classification is done by the nearest neighbors approach. Each test input is given the label of the nearest input in the training set. Below is a graphical example of this approach.

 

  

 

 

2.                  Write a function called findPrecision that takes in a list of approximated class labels output by the classifier (threshClassify) and a list of true labels provided in the training set, and calculates the precision of the classifier (for class 1) as a number between 0 and 1. Specifically, the function call must look like this:

            findPrecision(classifierOutput, trueLabels) 

If classifierOutput=[0,1,1,0,0,1,0] and trueLabels=[1,1,0,0,0,1,1],

the function will return the number 0.6667 (2 out of 3 of the values labeled as class 1 were actually in class 1).

 

 

3.                  Write a function called removeBlanks that takes in a featureArray (n,2) numpy array and returns a (m,2) numpy array where any row with a missing value is removed from the data set.all missing values are filled in with the number 2. “Missing values” are any entry that is 0.  

 

Specifically, the function call must look like this:

            featArrayCorrected=removeBlanks(featArray) 

If featArray=np.array([[0,5],[0,3],[1,8],[10,0],[4,4]]) the function will return np.array([[1,8],[4,4]]) into featArrayCorrected

 

 

 

More products