Exercise 1 (out of 14)
- Due No Due Date
- Points None
Getting started with supervised learning, incl. installation of some tools.
We will use Google Colab Links to an external site., which allows you to run (small) notebook examples. This requires no installation on your computer (though you need to have a google account).
It will however be useful for you to install some software tools that are useful for the course. This allows you to run on your own computer and learn to handle such tool infrastructure. The installation procedure depends on which OS you are running, but you will easily find good installation instructions for unix, mac and windows, and we will help you with installation on the exercise if you have problems. One recommendation is to install Anaconda which comes with its own python environment and many of these tools preinstalled.
Exercise 1.1 Install the following tools (if you have problems, proceed to the next exercise)
- Anaconda Links to an external site. a distribution of python with many data science tools ready to go
- Scikit-learn Links to an external site. a machine learning library for Python
- Pandas Links to an external site. a library providing easy-to-use data structures and data analysis tools
- matplotlib Links to an external site. a 2D-plotting library for python
- seaborn Links to an external site. a Python data visualization library based on matplotlib
- jupyter Links to an external site. which allows you to run jupyter notebooks in your browser
Be mentally prepared to run into some software issues that might require some work to resolve. Unfortunately, this is something you have to get used to in this line of work.
You can also use the discussion forum to ask questions, and help other students out if you think you know the answer.
If you get stuck with the installation and need help, you can move on and use google colab for the moment.
Exercise 1.2 Run the notebook ex3_python_intro.ipynb Links to an external site. either on google colab or on your local jupyter installation. It will go through some basics in a few of the packages we will be using.
(Hint: Start by copying the file to your own Google Drive (assuming you have such). This will allow you to save changes you make to the code. )
Exercise 1.3 On the lecture we studied overfitting and cross-validation, see ex3_cosinus.ipynb
Links to an external site.. In the code, replace the function used with ytrue=cos(1.5πx)+sin(3πx), n_sample=50, leave-on-out cross-validation (cv=50), and replace the x-range from [0,1] to [-1,1]. Fit polynomials of order 1,...,20 and evaluate the true MSE and compare with the estimate you get from cross-validation. Try different values of the random seed and study how stable the result is
Exercise 1.4 Prove the formula for the optimal parameter when ridge regression (Tikhonov regularisation) is used for least squares optimization, i.e. show that argminθ‖
Hint: The left hand side can be rewritten as a traditional LS problem \textrm{argmin}_{\theta}\; \Vert \bar y-\bar X\theta \Vert_2^2 by clever choice of extended matrices
\bar y \textrm{ and }\bar X. Then use the old LS-formula
\widehat{\theta} = \left(\bar X^T\bar X\right)^{-1}\bar X^T\bar y = ... and simplify the result.
Exercise 1.5 Assume we have a linear dynamical system satisfying
y(t) +a_1y(t-1) + \ldots + a_n y(t-n) = b_1u(t-1)+\ldots+b_nu(t-n)+e(t)
where y is a measured output,
u a known input, and
e an unknown disturbance. Describe how estimation of system parameters
a_1,\ldots, a_n and
b_1,\ldots, b_ncan be formulated as a linear regression problem as on Lecture 1. (We will return to dynamical system identification later in the course.)
Solutions: sol1.pdf Download sol1.pdf