0% found this document useful (0 votes)
40 views

Homework: Prediction Methods and Machine Learning

The homework asks students to become familiar with neural networks by completing three exercises using Python and Keras: 1) Create networks to classify MNIST handwritten digits, 2) Detect digit/non-digit images, and 3) Practice on other datasets like CIFAR10 or Fashion-MNIST. Keras is recommended for its ease of implementing and manipulating neural networks. Students will develop network architectures, train models, analyze results, and summarize their work in an uploaded notebook.

Uploaded by

Hadare Idrissou
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Homework: Prediction Methods and Machine Learning

The homework asks students to become familiar with neural networks by completing three exercises using Python and Keras: 1) Create networks to classify MNIST handwritten digits, 2) Detect digit/non-digit images, and 3) Practice on other datasets like CIFAR10 or Fashion-MNIST. Keras is recommended for its ease of implementing and manipulating neural networks. Students will develop network architectures, train models, analyze results, and summarize their work in an uploaded notebook.

Uploaded by

Hadare Idrissou
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Homework: Prediction methods and Machine learning

Pierre Michel

MASTER in Economics - Track EBDS - 2nd Year (2021)

Deep learning and applications


Motivation and objectives
The aim of this homework is to become familiar with the use of neural networks to solve supervised learning
(regression, classification) and pattern recognition tasks. You will handle several types of neural networks
and several common datasets with the objective to classify handwritten digits on an image, to predict a
quantitative outcome, to perform sentiment classification. . . depending on the data you will choose.
During your work, you are strongly invited to search for information by yourself on the architectures of
networks proposed by others (deep learning is an abundant field!). Feel free to draw inspiration from existing
publications or tutorials (by citing them). Here are two useful links on neural networks:
• Hagan et al., 2017, Neural Network Design
• Stanford University course notes
At the deadline of the project you will have to submit a notebook including your results, illustrated if possible.
The format of the report is free and the notebook must be uploaded on the course webpage.

Tools you need


Python and Numpy
The use of the library numpy for high-level computations is recommended (see previous slides) for the ones
who are interested in the application of linear algebra in the development of neural networks. If you prefer to
use a more user-friendly library, I warmly recommend using the library keras.

User-friendly solution: Keras


You can use the library Keras (https://keras.io/) to implement and use different neural networks. This
high-level library allows you to create and easily manipulate neural network architectures, access to different
datasets and train neural networks in a few seconds/lines of code. You will use pip to install Keras (and
Tensorflow on which Keras is based) in Unix:
pip install --user tensorflow
pip install --user keras
The library website contains all the documentation necessary for the project to be carried out. Please refer to
the tutorial proposed on the website https://keras.io/getting_started/.
Among other things, you will need to search for information on:
• Sequential models (initialize a network, add layers, training, prediction, architecture. . . ).
• Types of layers that Keras allows to use in networks, in particular the “classical” dense layers, convolution
layers. . .
• Visualizing the architecture with a simplified schema.

1
• Different optimizers available (e.g. stochastic gradient descent “sgd”).

MNIST
The MNIST dataset is a subset of the NIST (National Institute of Standards and Technology). It is a dataset
composed of 70000 images of digits (written by a panel of people) labelled according to the digit represented.
The database is divided into a set of 60000 training images and 10000 test images. The small size of the
images (28 × 28) makes it possible to quickly train neural networks that can be up to 99% accurate.

Matplotlib
The library MatplotLib is very useful for drawing graphics and viewing images in Python. In deep learning
applications its main use is to visualize:
• images from the training games
• classifier predictions
• convolution filters learned by neural networks
• images generated by the generating networks
• etc.

Exercise 1: Classify images of handwritten digits


In this part, you will have to create a neural network that takes as input a grayscale image from the MNIST
dataset (accessible via Keras) of size 28 × 28 and which returns the label of the number present on the image.
You will have to:
• Propose an architecture A of a neural network without convolution (the activation function of the
output layer should be the softmax function).
• Propose an architecture B of a convolutional neural network.
• Implement architectures A and B, illustrate them in text form and with a diagram (use the functions
available in Keras).
• Train the neural network on the MNIST dataset (training set only).
• Visualize the evolution of the model’s accuracy (for both training and validation sets) during learning
(use the history of training, see Keras documentation).
• Visualize the prediction of the neural network for a new input image (from the test set), i.e. on the
same figure:
– View the input image
– View network predictions (probabilities of class membership)
• Evaluate network performance on the MNIST test set

Exercise 2: Detect the presence of a hand-written digit on an image


In this part, you will create a neural network capable of identifying whether a grayscale image of size 28 × 28
is a handwritten digit or not.
Warning: we will need images other than those from MNIST. To do this you will generate “random” 28 × 28
grayscale images using a function in Python that generates an image in which the pixel values are obtained
by using a uniform distribution.
• Propose an architecture for the network (the target is binary: digit/non-digit).
• Illustrate the implemented architectures with text and a diagram.
• Train the network using 30, 000 images selected randomly from MNIST and 30, 000 “randomly” generated
images. Which metrics can be computed in this example ?
• Evaluate the classifier’s performance using the 10, 000 MNIST test images and 10, 000 randomly
generated images.
• Propose a vizualization of the classifier’s predictions.

2
Exercise 3: Practice on other datasets
You will have to use the skills you have acquired in the previous exercises to perform classification tasks on
more complex data sets than MNIST. For example, use images from CIFAR10 to classify images in color
(beware of the shape of the input data!), or the images from the Fashion-MNIST dataset that allow you to
use neural networks on grayscale images with more complex content.
You can also search for other datasets, consider a task other than classification, try to detect the position of
a particular object in an image, classify or predict events from data other than images (think of text, or big
data problems for example). . . it’s up to you to define your objective!
In this context you will have to:
• Present your objective clearly: which task are you performing ?
• Present the dataset used (dimensions, predictors, target, and some descriptive statistics).
• Present the architecture of your neural network and illustrate it.
• Illustrate the prediction performance and results of your network.

Examples of datasets available in Keras


Fashion-MNIST
The Fashion-MNIST database (available via Keras) was created by the Zalando research team https:
//github.com/zalandoresearch/fashion-mnist. It brings together grayscale images of clothing. Similar to
MNIST, it contains 60000 28 × 28-sized images for training, and 10000 test images, labelled according to 10
classes of clothing.

CIFAR10
The CIFAR10 database (available via Keras) is a subset of the CIFAR100 database, collected by Alex
Krizhevsky, Vinod Nair et Geoffrey Hinton (source: https://www.cs.toronto.edu/~kriz/cifar.html). It
contains 60000 color image of size 32 × 32 labelled according to 10 classes (6000 images per class). 50000
images are used for the training set, 10000 for the test set.

You might also like