Question

In: Computer Science

Question. Programming question: Dimension Reduction In this question, you are asked to run Singular Value Decomposition...

Question. Programming question: Dimension Reduction
In this question, you are asked to run Singular Value Decomposition (SVD) on Fashion-MNIST data set, interpret the output and train generative classifiers for multi- nomial classification of 10 classes. For the Fashion-MNIST data set, you can find more details in the original GitHub website or Kaggle website. In this assignment, you are allowed to use a library implementation of SVD. For python users, we recommend scikit-learn’s implementation TruncatedSVD.

Tasks:

?Load the training and test data sets from fashion-mnist train.csv and fashion- mnist test.csv. Each row uses a vector of dimension 784 with values between 0 (black) and 255 (white) on the gray color scale.

?Guidelines:
In this homework, you are allowed to use scikit-learn’s implementations Multinomial Logistic Regression, Naive Bayes, and KNN directly

Solutions

Expert Solution

Structure of my ans:

1. Have provided the images of the jupyter notebook.

2. At the end entire code is provided in single code cell.

Jupyter notebook Images:

The data was downloaded from kaggle.

The data needs to be normalized to speed to training.

Note: n_component should be treated as a hyperparameter. The elbow method is used to determine the optimal value. Lower the value the model might miss on important features.

A value above 500 reduces nb accuracy so a I have stuck with 300.

Training models :

value of n_neighbours can be played with to measure the models performance.

Code:

from sklearn.decomposition import TruncatedSVD 
import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB

train_data = pd.read_csv('fashion_mnist/fashion-mnist_train.csv')
test_data = pd.read_csv('fashion_mnist/fashion-mnist_test.csv')
train_data.head()

y = train_data.iloc[:,0].values
y.shape

x = train_data.iloc[:,1:].values
x.shape

# loading test data
y_test = test_data.iloc[:,0].values
x_test = test_data.iloc[:,1:].values
y_test.shape,x_test.shape

x = x / 255.0
x_test = x_test / 255.0

svd  = TruncatedSVD(n_components=300)
svd.fit(x)

x_new = svd.transform(x)

x_test_new = svd.transform(x_test)
x_test_new.shape

#### training models 

clf = LogisticRegression(C = 10,max_iter = 500)
clf.fit(x_new,y)
print(f'accuracy on test data = {clf.score(x_test_new,y_test)}')

clf = GaussianNB()
clf.fit(x_new,y)
print(f'accuracy on test data = {clf.score(x_test_new,y_test)}')

clf = KNeighborsClassifier(n_neighbors=7,n_jobs=-1)
clf.fit(x_new,y)
print(f'accuracy on test data = {clf.score(x_test_new,y_test)}')

Please UpVote if you find this helpful.


Related Solutions

Question. Programming question: Dimension Reduction In this question, you are asked to run Singular Value Decomposition...
Question. Programming question: Dimension Reduction In this question, you are asked to run Singular Value Decomposition (SVD) on Fashion-MNIST data set, interpret the output and train generative classifiers for multi-nomial classification of 10 classes. For the Fashion-MNIST data set, you can find more details in the original GitHub website or Kaggle website. Kaggle: https://www.kaggle.com/zalando-research/fashionmnist GetHub: https://github.com/zalandoresearch/fashion-mnist Tasks: ?Load the training and test data sets from fashion-mnist train.csv and fashion- mnist test.csv. Each row uses a vector of dimension 784 with...
Find the singular value decomposition of A = [ (3 2 2), (2 3 2) ]...
Find the singular value decomposition of A = [ (3 2 2), (2 3 2) ] and determine the angle of rotation induced by U and V . Also, write the rank 1 decomposition of A in terms of the columns of U and rows of V . Can we do dimensionality reduction in this case?
Find a singular value decomposition for the matrix A = [ 1 0 -1, -1 1...
Find a singular value decomposition for the matrix A = [ 1 0 -1, -1 1 0] (that means 1 0 -1 is the first row and -1 1 0 is the second) If you could provide a step-by-step tutorial on how to complete this I'd greatly appreciate it.
How can Singular Value Decomposition be used on image compression and its limitation?
How can Singular Value Decomposition be used on image compression and its limitation?
You are asked to investigate the use of mathematical programming in accounting: applications and you decide...
You are asked to investigate the use of mathematical programming in accounting: applications and you decide to depend on secondary data sources. What search tools might you use? Which do you think would be the most useful?                                                                                                                                    [5 Marks] What problems of secondary data quality must researchers face?       [10 Mark] How can the researchers overcome problems of secondary data quality?                                                                                                              [10 Marks]
In Programming Challenge 12 of Chapter 3, you were asked to write a program that converts...
In Programming Challenge 12 of Chapter 3, you were asked to write a program that converts a Celsius temperature to Fahrenheit. Modify that program so it uses a loop to display a table of the Celsius temperatures 0–20, and their Fahrenheit equivalents. Display table on screen and it a .txt file. c++
C++ Programming Enum - Structure - Array You are asked to develop software for HR department...
C++ Programming Enum - Structure - Array You are asked to develop software for HR department to calculate employee’s weekly salary. The program should contain the following information about a student by declaring a struct: Name (string of characters)        Employee ID (string of characters)        Level (ENGINEER, MANGER, DIRECTOR)        Hourly Rate (floating-point number)        Working Hours (floating-point number)        Weekly Salary (floating-point number) Your program will read an employee data and print the information of employee’s Name, Employee...
You are asked to run a chromatographic column for separation of a mixture of compounds: CH3CH2OCH3,...
You are asked to run a chromatographic column for separation of a mixture of compounds: CH3CH2OCH3, CH3(CH2)3OH, CH3CO2H, CH3(CH2)8CH3. Two solvents have been provided i.e. acetone and hexane. Which eluting solvent would you use first and predict the order of elution for the compounds.
Using the table below, you are asked to calculate perform three-factor ROE decomposition (i.e. calculate ROE...
Using the table below, you are asked to calculate perform three-factor ROE decomposition (i.e. calculate ROE and its components) for all three of the following companies. What would you advise each company to do to improve its ROE? Discuss the specific component that needs to be improved and present an example of how it could done. Please round your answers to two decimal places. MTR TKO NRM Sales 6,900 2,600 1,900 Net income 200 100 100 Average Assets 4,000 4,800...
Question Objective: The objective of this lab exercise is to give you practice in programming with...
Question Objective: The objective of this lab exercise is to give you practice in programming with one of Python’s most widely used “container” data types -- the List (commonly called an “Array” in most other programming languages). More specifically you will demonstrate how to: Declare list objects Access a list for storing (i.e., writing) into a cell (a.k.a., element or component) and retrieving (i.e., reading) a value from a list cell/element/component Iterate through a list looking for specific values using...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT