How does the training and validation accuracy change

Assignment Help Python Programming
Reference no: EM133353199

Convolutional Neural Network (CNN)

In this question, the goal is to train a Convolutional Neural Network (CNN) to classify images of handwritten digits from the MNIST dataset using Google Colab. The MNIST dataset is a well-known benchmark dataset for image classification tasks, consisting of 60,000 training images and 10,000 test images of handwritten digits (0-9) in grayscale, each with a resolution of 28x28 pixels. The goal of the task is to train a CNN model that can accurately classify each image in the test set according to its correct digit label. Follow the provided instructions step-by-step to load the MNIST dataset and preprocess the data by normalizing the pixel values to be between 0 and 1, and then train a CNN model using Keras API in TensorFlow. Afterward, answer the questions which involve evaluating the model's performance on the test set.

1. First, open your web browser and navigate to the Google Colab website

2. If you are not already signed into your Google account, click the "Sign in" button in the top-right corner of the screen and enter your Google credentials. Once you are signed in, you can create a new Colab notebook by clicking the "New Notebook" button on the home screen. This will open a new notebook with a blank Python code cell. You can write and execute Python code in the code cell just as you would in a local Python environment. To execute a cell, click the "Run" button to the left of the cell, or press the "Shift + Enter" keyboard shortcut.

3. To save your work in Google Colab, you can either use the keyboard shortcut "Ctrl + S" or click on "File" in the menu bar and then select "Save" or "Save a copy in Drive". If you choose "Save a copy in Drive", a copy of the notebook will be saved to your Google Drive account. If you choose "Save", the notebook will be saved in the Colab environment. If you want to download the notebook to your local machine, you can click on "File" in the menu bar and then select "Download .ipynb". This will download the notebook file in Jupyter notebook format to your local machine.

4. Copy and paste the following code at the first cell of your code:

This code imports the necessary TensorFlow and Keras libraries for building and training the CNN model.

5. Next, load the MNIST dataset by adding the following code:

This code loads the MNIST dataset, which consists of 60,000 training images and 10,000 test images of handwritten digits. x_train and x_test are the images as the input and y_train and y_test are their labels as the output.

6. Show one of the images in the dataset with its label using the following code:

You can try different images by changing 0 to a random number in img and label.

7. Normalize the pixel values of the images by adding the following code:

This code scales the pixel values of each image to be between 0 and 1, which can improve the performance of the model.

8. Build the CNN model by adding the following code:

This code defines a simple CNN model with a convolutional layer, a pooling layer, and two fully connected layers. The input shape of the model is (28, 28, 1), which corresponds to the shape of the MNIST images. The convolutional layer has 32 filters with a kernel size of 3x3 and uses the ReLU activation function. The pooling layer reduces the spatial dimensions of the output by a factor of 2. The first fully connected layer has 128 units and uses the ReLU activation function, while the output layer has 10 units and uses the SoftMax activation function to produce a probability distribution over the 10 possible digit classes.

9. Compile the model by adding the following code:

This code specifies the optimizer, loss function, and evaluation metrics for the model. The Adam optimizer is a popular choice for training CNNs, and the sparse categorical cross entropy loss function is appropriate for multi-class classification problems like MNIST.

10. Train the model by adding the following code:

This code trains the model on the MNIST training data for 10 epochs, using the validation data to monitor the performance of the model during training.

Now, it's time to evaluate the model on the test data.

Question 1) Plot the training and validation accuracy curves over the 10 epochs of training. You can use the history.history attribute which contains information about the training history of the model, including the values of the training and validation metrics at each epoch. For example,

training_accuracy = history.history['accuracy'] plt.plot(training_accuracy, label='Training Accuracy')

How does the training and validation accuracy change over time?

Question 2) Plot the training and validation loss curves over the 10 epochs of training. How does the training and validation loss change over time?

Question 3) Show five example images from the test set with their predicted labels. To predict the labels you can use the model.predict method to predict the labels for a set of input images. Also, in order to get the more probable label for each image, you can use the np.argmax method. For example:

import numpy as np
y_pred = model.predict(np.reshape(x_test[‘sample_number'], (1,28,28))) print(y_pred)
y_label = np.argmax (y_pred) print(y_label)

np.reshape() is used to change the shape of the x_test to an appropriate format. You can change
‘sample_number' into five different samples you want.

Question 4) Calculate the overall test accuracy of the model using "model.evaluate" which computes the loss and metrics for the test data.

test_loss, test_acc = model.evaluate(x_test, y_test)

Question 5) What is your suggestion to improve the overall test accuracy?

Submission:

Submit two files:

1. A PDF file containing the solutions and the requested figures/explanations. Save your file as
FirstName-LastName.PDF.

2. Download your code as "Assignment_3_ FirstName-LastName.ipynb". Create and upload a .zip file of your code, called code.zip.

Attachment:- Convolutional Neural Network.rar

Reference no: EM133353199

Questions Cloud

Make bad economic and fiscal decisions : Is it ethical for the IMF to bail out countries that repeatedly make bad economic and fiscal decisions?
What is your current definition of self care : After completing the 40-Day Practice assignment, (I did an exercise for 40 days) what is your current definition of self care and what does self-care have
Implementing legislation to protect entire industry : Example of dumping activities that have led to a country's government implementing legislation to protect the entire industry involved.
What is gendered speech communities : What is Gendered Speech Communities? Include at least three characteristics each of Feminine and Masculine Speech Communities and summarize
How does the training and validation accuracy change : How does the training and validation accuracy change over time and Plot the training and validation loss curves over the 10 epochs of training
What is the problem with healthcare amongst lgbtq+ : What is the problem with healthcare amongst LGBTQ+ individuals?
What is the relation between mental health issues : What is the relation between mental health issues with the education institution and medicine institution? Could you please provide a concise and details
How is the principle of social comparison involved : how is the principle of social comparison involved? How were the results of social comparison different for White girls and Black girls? This study claims
What form of social control in your view : What form of social control (formal or informal) in your view will be useful in addressing the above social issues? Explain.

Reviews

Write a Review

Python Programming Questions & Answers

  Apply struct for reading packet data

Topic: Python 3 - PCAP file analysis - Apply struct for reading packet's data, extract and hash the ICMP data portion of the packet

  Input a temperature as a floating point

Your program should input a temperature as a floating point number with an appended unit letter. It should then print the temperature in all four of the units above

  Simulate a simple banking interface

ITECH1400 – Foundations of Programming - Assignment – FedUni Banking - The ability to view the balance of the bank account and to deposit and withdraw virtual

  Write a function called overlap that takes a set of integers

Write a function called overlap that takes a set of integers and a list of integers as parameters and that returns a new set containing values that appear.

  The difference between a chained conditional and a nested

You need some help in finding out the difference between a chained conditional and a nested conditional. Can you please give an example of each?

  Calculate the average miles per gallon obtained on a trip

Write a program that will calculate the average miles per gallon obtained on a trip. Input the amount of gas used and the number of miles driven.

  Use python code allows the user to use a menu to select

You need to use python code allows the user to use a menu to select and then generate pick-3 or pick-4 lottery number generator.

  Create a count-controlled while loop to generate

Create a count-controlled while loop to generate and append 1,000 random integers to the list. Each integer should be between 1 and 100, including 1 and 100.

  How education records are protected

Discuss the similarities and the differences in how education records are protected compared to how health information records are protected.

  Build a program to store water usage data of 4 customers

Build a program to store water usage data of 4 customers in a text file. The program asks the user to enter account number, customer type.

  Prompt the user to input five pairs of numbers

This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team.

  Write a program to determine the coefficients of expanded

Write a program to determine the coefficients of expanded form of (aX+bY+c)n. Every line in bold is questions to ask whoever runs the program to enter values or commands (y or n) at the console.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd