Description

(PCA using MSE and population covariance matrix^{1}) Assume that x is a zeromean p dimensional random vector (E[x] = 0) with covariance matrix: (10 pts)

= E[xx^{T} ]
We wish to estimate x with M p principal directions as:
M
X
x^ = _{i}e_{i} = ^{T} e
i=1
where e_{i}’s are the orthonormal eigenvectors of the covariance matrix R and = [ _{1}; : : : ; _{p}]^{T} . Show that the minimization of the mean squared error:
J = E[kx x^k^{2}]
with respect to _{1}; : : : ; _{m} yields:
_{i} = e^{T}_{i} x; i = 1; 2; : : : ; M
as the principal component, that is, the projection of the data vector x onto the eigenvector e_{i}.

Let p(xj!_{i}) be arbitrary densities with means _{i} and covariance matrices _{i}  not necessarily normal  for i = 1; 2. Let y= w^{T} x be a projection, and let the induced onedimensional densities p(yj!_{i}) have means _{i} and variances _{i}^{2}. (15 pts)


Show that the criterion function








J_{1}(w) =
(_{1 2})^{2}
_{1}^{2}+ _{2}^{2}






is maximized by
w = ( _{1} + _{2}) ^{1}( _{1} _{2})
(b) If P (!_{i}) is the prior probability for !_{i}, show that the criterion function
(_{1} _{2})^{2}
^{J}^{2}^{(w) =} P (!_{1}) _{1}^{2} + P (!_{2}) _{2}^{2}
is maximized by
w = (P (!_{1}) _{1} + P (!_{2}) _{2}) ^{1}( _{1} _{2})

Explain which of J(w_{1}) and J(w_{2}) is \closer” to the criterion that is used by Fisher’s LDA.
^{1}Using the population covariance matrix instead of the scatter matrix simpli es the formulation here
Homework 5 EE 559, Instructor: Mohammad Reza Rajati

Time Series Classi cation Part 1: Feature Creation/Extraction
Important Note: You will NOT submit this part with Homework 5. It was the programming assignment of Homework 4. However, you may want to submit the code for Homework 4 with Homework 5 again, since it might need the feature creation code. .
An interesting task in machine learning is classi cation of time series. In this problem, we will classify the activities of humans based on time series obtained by a Wireless Sensor Network.


Download the AReM data from: https://archive.ics.uci.edu/ml/datasets/ Activity+Recognition+system+based+on+Multisensor+data+fusion+\%28AReM\ %29 . The dataset contains 7 folders that represent seven types of activities. In each folder, there are multiple les each of which represents an instant of a human performing an activity.^{2} Each le containis 6 time series collected from activities of the same person, which are called avg rss12, var rss12, avg rss13, var rss13, vg rss23, and ar rss23. There are 88 instances in the dataset, each of which contains 6 time series and each time series has 480 consecutive values.



Keep datasets 1 and 2 in folders bending1 and bending 2, as well as datasets 1, 2, and 3 in other folders as test data and other datasets as train data.



Feature Extraction

Classi cation of time series usually needs extracting features from them. In this problem, we focus on timedomain features.



Research what types of timedomain features are usually used in time series classi cation and list them (examples are minimum, maximum, mean, etc).





Extract the timedomain features minimum, maximum, mean, median, standard deviation, rst quartile, and third quartile for all of the 6 time series in each instance. You are free to normalize/standardize features or use them directly.^{3}


Your new dataset will look like this:



Instance
min_{1}
max_{1}
mean_{1}
median_{1}
1st quart_{6}
3rd quart_{6}
1
2
3
.
.
.
.
.
.
.
.
.
.
.
.
. . .
.
.
.
.
.
.
.
.
.
88


where, for example, 1st quart_{6}, means the rst quartile of the sixth time series in each of the 88 instances.

Estimate the standard deviation of each of the timedomain features you extracted from the data. Then, use Python’s bootstrapped or any other method to build a 90% bootsrap con dence interval for the standard deviation of each feature.
^{2}Some of the data les need very minor cleaning. You can do it by Excel or Python.
^{3}You are welcome to experiment to see if they make a di erence.
Homework 5 EE 559, Instructor: Mohammad Reza Rajati



Use your judgement to select the three most important timedomain features (one option may be min, mean, and max).





Assume that you want to use the training set to classify bending from other activities, i.e. you have a binary classi cation problem. Depict scatter plots of the features you speci ed in 3(c)iv extracted from time series 1, 2, and 6 of each instance, and use color to distinguish bending vs. other activities. (See p. 129 of the ISLR textbook).^{4}



Time Series Classi cation Part 2: Binary and Multiclass Classi cation


Binary Classi cation Using Logistic Regression^{5}




Break each time series in your training set into two (approximately) equal length time series. Now instead of 6 time series for each of the training instances, you have 12 time series for each training instance. Repeat the experiment in 3(c)v, i.e depict scatter plots of the features extracted from both parts of the time series 1,2, and 12. Do you see any considerable di erence in the results with those of 3(c)v? (5 pts)





Break each time series in your training set into l 2 f1; 2; : : : ; 20g time series of approximately equal length and use logistic regression^{6} to solve the binary classi cation problem, using timedomain features. Remember that breaking each of the time series does not change the number of instances. It only changes the number of features for each instance. Calculate the pvalues for your logistic regression parameters in each model corresponding to each value of l and re t a logistic regression model using your pruned set of features.^{7} Alternatively, you can use backward selection using sklearn.feature selection or glm in R. Use 5fold crossvalidation to determine the best value of the pair (l; p), where p is the number of features used in recursive feature elimination. Explain what the right way and the wrong way are to perform crossvalidation in this problem.^{8} Obviously, use the right way! Also, you may encounter the problem of class imbalance, which may make some of your folds not having any instances of the rare class. In such a case, you can use strati ed cross validation. Research what it means and use it if needed. (15 pts)


In the following, you can see an example of applying Python’s Recursive
^{4}You are welcome to repeat this experiment with other features as well as with time series 3, 4, and 5 in each instance.
^{5}Some logistic regression packages have a builtin L_{2} regularization. To remove the e ect of L_{2} regularization, set = 0 or set the budget C ! 1 (i.e. a very large value).

If you encountered instability of the logistic regression problem because of linearly separable classes, modify the MaxIter parameter in logistic regression to stop the algorithm immaturely and prevent from its instability.
^{7}R calculates the pvalues for logistic regression automatically. One way of calculating them in Python is to call R within Python. There are other ways to obtain the pvalues as well.
^{8}This is an interesting problem in which the number of features changes depending on the value of the parameter l that is selected via cross validation. Another example of such a problem is Principal Component Regression, where the number of principal components is selected via cross validation.
Homework 5 EE 559, Instructor: Mohammad Reza Rajati
Feature Elimination, which is a backward selection algorithm, to logistic regression.



# R e c u r s i v e F e a t u r e E l i m i n a t i o n
from
s k l e a r n import
d a t a s e t s
from
s k l e a r n . f e a t u r e
s e l e c t i o n import RFE
from
s k l e a r n . l i n e a r
m o d e l import L o g i s t i c R e g r e s s i o n





# l o a d t h e i r i s d a t a s e t s
d a t a s e t = d a t a s e t s . l o a d
i r i s ( )
# c r e a t e
a b a s e
c l a s s i f i e r
used t o e v a l u a t e a s u b s e t o f a t t r i b u t e s
model =
L o g i s t i c R e g r e s s i o n ( )
# c r e a t e
t h e RFE
model and
s e l e c t
3 a t t r i b u t e s
r f e
= RFE( model ,
3 )
r f e
= r f e . f i t ( d a t a s e t . data ,
d a t a s e t . t a r g e t )
# summarize t h e
s e l e c t i o n o f t h e
a t t r i b u t e s
p r i n t ( r f e . s u p p o r t
)
p r i n t ( r f e . r a n k i n g
)




Report the confusion matrix and show the ROC and AUC for your classi er on train data. Report the parameters of your logistic regression _{i}’s as well as the pvalues associated with them. (10 pts)



Test the classi er on the test set. Remember to break the time series in your test set into the same number of time series into which you broke your training set. Remember that the classi er has to be tested using the features extracted from the test set. Compare the accuracy on the test set with the crossvalidation accuracy you obtained previously. (10 pts)



Do your classes seem to be wellseparated to cause instability in calculating logistic regression parameters?



From the confusion matrices you obtained, do you see imbalanced classes? If yes, build a logistic regression model based on casecontrol sampling and adjust its parameters. Report the confusion matrix, ROC, and AUC of the model. (10 pts)


Binary Classi cation Using L_{1}penalized logistic regression


Repeat 4(a)ii using L_{1}penalized logistic regression,^{9} i.e. instead of using pvalues for variable selection, use L_{1} regularization. Note that in this problem, you have to crossvalidate for both l, the number of time series into which you break each of your instances, and , the weight of L_{1} penalty in your logistic regression objective function (or C, the budget). Packages usually perform crossvalidation for automatically.^{10} (15 pts)



Compare the L_{1}penalized with variable selection using pvalues. Which one performs better? Which one is easier to implement? (5 pts)


Multiclass Classi cation (The Realistic Case)

For L_{1}penalized logistic regression, you may want to use normalized/standardized features
^{10}Using the package Liblinear is strongly recommended.
Homework 5 EE 559, Instructor: Mohammad Reza Rajati
i. Find the best l in the same way as you found it in 4(b)i to build an L_{1}penalized multinomial regression model to classify all activities in your training set.^{11} Report your test error. Research how confusion matrices and ROC curves are de ned for multiclass classi cation and show them for this problem if possible.^{12} (10 pts)

Repeat 4(c)i using a Na ve Bayes’ classi er. Use both Gaussian and Multinomial pdfs and compare the results. (10 pts)

Create p Principal Components from features extracted from features you extracted from l time series. Cross validate on the (l; p) pair to build a Na ve Bayes’ classi er based on the PCA features to classify all activities in your data set. Report your test error and plot the scatterplot of the classes in your training data based on the rst and second principal components you found from features extracted from l time series, where l is the value you found using crossvalidation. Show confusion matrices and ROC curves. (10 pts)

Which method is better for multiclass classi cation in this problem? (5 pts)
^{11}New versions of scikit learn allow using L_{1}penalty for multinomial regression.

For example, the pROC package in R does the job.
5