Machine Learning Worksheet

User Generated

RevpYVF

Computer Science

Description

Please do not plagiarize.

Please refer to the attachment for questions' details

Q1 about Fitting data with PCs

Q2 about PC with images

Q3 about PCs using SVDs

Please use jupyter notebook or google colab thank you

Unformatted Attachment Preview

3. Fitting data with PCs. You are given python functions for PCA transform and a binary classifier: mu, V = PCA (X) # Finds the mean and PCs for a data matrix X clf = Classifier () clf.fit (z,y) #Fits a binary classifier from features Z and labels y yhat= clf.predict (Z) # Predicts labels from Z 1 Given a data matrix X with binary labels y, you wish to build a classifier that uses a PCA transform followed by the Classifier. Write python code that uses model validation to select the optimal number of PCA components to use. You may assume: • You use simple cross validation with one training and test split. Not You do not need to do K-fold validation. • You should use roughly 25% of the samples for test. Data shuffling before splitting is not needed. 4. PC with images. A dataset has 1000 images of size 28 x 28, represented as python array X with shape (1000, 28, 28). You are given the following python functions: # Reshapes X to a shape # Creates a PCA object Y = reshape (X, shape) pca = PCA (n_components = nc) pca. fit (Y) # Finds the mean Z = pca.transform (Y) # Find coefficients in the PC basis and PCs from training data Y Yhat = pca.inverse_transform (Z) # Invert the PC transform Write a few lines of python code to (i) fit a PC model from the first 500 images with 5 components; and (ii) create an array of approximations of the remaining 500 images. 5. PCs using SVDs. You are given a python function: U₁s, Vtr = svd(Z, full_matrices = False) which computes an "economy" SVD. Given a data matrix X, write python code that: (i) Finds the PCs and mean of the data. (ii) Finds the minimum number of PCs in order that the proportion of variance is at least 90%. (iii) Create an approximation Xhat of X using the number of PCs in part (ii).
Purchase answer to see full attachment
Explanation & Answer:
3 Questions
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

View attached ex...

Related Tags