Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem you will complete some code to build a k-nearest neighbour classifier to classify images of handwritten digits (0-9). For this purpose we

In this problem you will complete some code to build a k-nearest neighbour classifier to classify images of handwritten digits (0-9). For this purpose we will use a famous open-source dataset of handwritten digits called the MNIST that is ubiquitously used for testing a number of classification algorithms in machine learning.

My code1:

class MNIST_import: """ sets up MNIST dataset from OpenML """ def __init__(self): df = pd.read_csv("data/mnist_784.csv") # Create arrays for the features and the response variable # store for use later y = df['class'].values X = df.drop('class', axis=1).values # Convert the labels to numeric labels y = np.array(pd.to_numeric(y)) # create training and validation sets self.train_x, self.train_y = X[:5000,:], y[:5000] self.val_x, self.val_y = X[5000:6000,:], y[5000:6000] data = MNIST_import()

My code2:

def view_digit(x, label=None): fig = plt.figure(figsize=(3,3)) plt.imshow(x.reshape(28,28), cmap='gray'); plt.xticks([]); plt.yticks([]); if label: plt.xlabel("true: {}".format(label), fontsize=16)

TO DO 1 : Display a particular digit using the above function (view_digit):

training_index = 9

#your code here

TO DO 2: Fill in the code in the following cell to determine the following quantities:

- Number of pixels in each image

- Number of examples in the training set

- Number of examples in the test set

# Here are the numbers you need to provide here: num_training_examples = num_test_examples = pixels_per_image =

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions