Question: Exercise 2: Support Vector Machines Write a scikit-learn based application to classify MNIST digits using a Support Vectors Machine (SVM) model. The dataset is from

Exercise 2: Support Vector Machines Write a scikit-learn based application to classify MNIST digits using a Support Vectors Machine (SVM) model. The dataset is from http://yann.lecun.com/exdb/mnist/. You must use a tensorflow function to just fetch the data. The description about this tensorflow function is in this page: https://www.tensorflow.org/api_docs/python/tf/keras/datasets/mnist/load_data Rest of the functionality must be accomplished using scikit-learn library. Train the model using the top 60 rows out of 60000 rows of the training data (present in x_train; see below how to obtain the training data in x_train). Test the model using top 10 rows out of 10000 rows of test data (present in x_test; see below how to obtain the test data in x_test). Evaluate the accuracy of the model.

Note: If you go down the aforementioned webpage you will see an example usage of the method keras.datasets.mnist.load_data. It returns four objects of type ndarray. Those four objects are x_train, x_test, y_train, y_test. The shape of x_train is (60000, 28, 28) implying 60000 rows of images, each image consists of 28 rows of pixels, 28 columns of pixels. You need to reshape x_train to (60000, 784) so that it becomes a matrix of 60000 rows and 784 columns, thereby enabling it to be used by methods of sklearn models. Similarly, the shape of x_test is (10000, 28, 28). You need to reshape x_test to (10000, 784) so that it can be used by sklearn methods. Note that the integer 784 = 28 * 28. (For an analogy, you may recall that the sklearn method sklearn.datasets.load_digits returns an object of type Bunch. The Bunch object in turn has an attribute named data that stores a ndarray or a dataframe of shape (1797, 64). This shape implies that the ndarray object or the dataframe object contains 1797 rows and 64 columns. Note that the integer 64 = 8 * 8.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!