Let Xp and X be the positive and negative training data, respectively, as
Xp = (1 4 3 6 4 0 1 1
6 3 8 6 6 2 2 3) and X = (10 8 0 1 0 1
8 10 7 8 1 1).
1. (5 points) Compute the class-specific means of data matrices Xp and X. Your code needs to return the mean as a column vector.
2. (5 points) Compute the class-specific covariance matrices for the data matrices Xp and X.
3. (5 points) Compute the between-class scattering matrix S.
4. (5 points) Compute the within-class scattering matrix Sw.
5. (10 points) Write your own code to compute the LDA projection by solving the generalized eigenvalue decomposition problem. [use function numpy.linalg.eig]
6. (10 points) Write your own code to compute the LDA projection for the data given in the problem setting. You should see that the second eigenvalue is zero.
7. (20 points) Collect all previous steps, write a function with the name mybLDA_train to perform binary LDA, which takes inputs of two data matrices X and X assuming column data, and return the optimal LDA projection direction as a unit vector.
8. (20 points) Write a function with the name mybLDA_classify which takes a data matrix X and a projection direction v, returns a row vector r that has size as the number of rows in X, and r_i = +1 if the i-th column of X is from the class as in X, and r_i = -1 if the i-th column in X is from the class as in X.
9. (20 points) Run your function, mybLDA_train, on the data given in the problem setting. Use your function mybLDA_classify to classify the following data set X = (1.3 2.4 6.7 2.2 3.4 3.2 8.1 7.6 2.1 1.1 0.5 7.4) and return the classification results.
CSI436/536
Homework 4
Machine Learning