Neural Networks – 2016/2017

Older editions: 2012 – 2013/2014


This page contains the material for the lab sessions that I held in the Neural Networks course taught by Prof. Aurelio Uncini for the M.Sc. in Artificial Intelligence and Robotics. For general informations about the course please refer to the original web pages.


All lab sessions require a working installation of Python 3.5 with (at least) NumPy, matplotlib, and scikit-learn (for the second and third labs). If you are starting from scratch, installing the Anaconda platform is the recommended method to have a working installation with all prerequisites. Alternatively, Canopy offers a working license by registering with the academic email. If you prefer a minimal installation, after installing Python and the pip module to manage libraries (e.g., following this guide on Ubuntu systems), you can install all prerequisites by running the following command on the console:

Lab session 1 – NumPy and linear regression

Download the code for this lab

This lab session aims at gaining some familiarity with NumPy (for linear algebra), and the basic workflow of a machine learning application. Specifically, we aim at approximating a sinusoid function starting from some values sampled with error:

f(x) = \sin(x) + \varepsilon

where the error ε follows a Gaussian distribution with fixed variance. This is obtained by fitting a linear model y = \boldsymbol{w}^T\phi(x) on the space built by taking polynomial features of x up to a given power p :

\phi(x) = \left[ x^0, \, x^1, \, \ldots, x^{p} \right]

You are encouraged to experiment what happens when varying the number of sampled values, the amount of regularization and the number of power expansions, thus obtaining different levels of underfitting/overfitting.

Lab session 2 – scikit-learn

Download the code for this lab

This lab is intended to provide some familiarity with the objects in scikit-learn. The code goes through an entire workflow applied to a classification problem, including data normalization, data splitting, model fine-tuning, and evaluation. The lab requires version 0.18.1 of scikit-learn, where neural networks and the module ‘model_selection’ were introduced (see the release history). If you have a previous version of scikit-learn, you can upgrade by running the following command on the console:

 Lab session 3 – Theano and Lasagne

Download the code for this lab

This lab introduces the Theano and Lasagne libraries. For details on the installation of Theano, please refer to the official installation guides:

On Windows with Anaconda, a basic installation (withouth CUDA support for the GPU) requires the following commands:

 On all platforms, Lasagne can be installed immediately using pip:

Leave a Reply

Your email address will not be published / Required fields are marked *