pca <- function(X) { # Run principal component analysis on the dataset X # # U,d,V <- pca(X) computes eigenvectors of the covariance matrix of X # Returns the eigenvectors in U and the eigenvalues in d as a vector # # Useful values m <- dim(X)[1] # ========================= YOUR CODE HERE ======================= # Instructions: You should first compute the covariance matrix. Then, you # should use the 'svd' function to compute the eigenvectors # and eigenvalues of the covariance matrix. # # Note: When computing the covariance matrix, remember to divide by m (the # number of examples). # # ================================================================ return(list(D = diag(svd_out$d), U = svd_out$u )) }