FRTN65
Exercise 1 (out of 14)
Skip To Content
Dashboard
  • Login
  • Dashboard
  • Calendar
  • Inbox
  • History
  • Help
Close
  • My dashboard
  • FRTN65
  • Assignments
  • Exercise 1 (out of 14)
2023 HT/Autumn
  • Home
  • Modules
  • Quizzes
  • Assignments
  • Syllabus

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).

However, it will also be useful for you to install some software tools that are used in the course. This allows you to run code on your own computer and learn to handle such tool infrastructure. The installation procedure depends on which OS you are running, but you can easily find good installation instructions for Unix, macOS, and Windows, and we will help you with installation on the exercise if you have problems. One recommendation is to install Conda (Anaconda/Miniconda), which is a tool for handling virtual environments and packages in Python.

Some additional notes/instructions on working with Conda virtual environments in Python can be found here: virtual_environment_intro.pdf Download virtual_environment_intro.pdf (virtual_environment_intro.md Download virtual_environment_intro.md)

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 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 LaTeX: y_{\textrm{true}} = \cos(1.5\pi x) + \sin(3\pi x)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  Assume we have a linear dynamical system satisfying

LaTeX: y(t) +a_1y(t-1) + \ldots + a_n y(t-n) = b_1u(t-1)+\ldots+b_nu(t-n)+e(t)y(t)+a1y(t−1)+…+any(t−n)=b1u(t−1)+…+bnu(t−n)+e(t)

where LaTeX: yy is a measured output, LaTeX: uu a known input, and LaTeX: ee an unknown disturbance. Describe how estimation of system parameters LaTeX: a_1,\ldots, a_na1,…,an and LaTeX: b_1,\ldots, b_nb1,…,bncan be formulated as a linear regression problem as on Lecture 1. (We will return to dynamical system identification later in the course.)

 

Exercise 1.5 We will prove the formula for the optimal parameter when ridge regression (=Tikhonov regularisation) is used for least squares optimization:

Introduce the matrix  LaTeX: \overline{X} := \begin{pmatrix} X \\ \gamma^{1/2} I_p\end{pmatrix}¯X:=(Xγ1/2Ip) and vector LaTeX: \overline{y} := \begin{pmatrix} y \\ 0_p\end{pmatrix}¯y:=(y0p).

a) Show that LaTeX: \Vert \overline{y}-\overline{X}\theta  \Vert_2^2  =\Vert y-X\theta  \Vert_2^2 + \gamma \Vert \theta \Vert_2^2‖¯y−¯Xθ‖22=‖y−Xθ‖22+γ‖θ‖22. (Hint: Use the matrix result that LaTeX: \Vert \begin{pmatrix} u \\ v\end{pmatrix} \Vert_2^2 = \Vert  u \Vert_2^2 + \Vert  v \Vert_2^2 ‖(uv)‖22=‖u‖22+‖v‖22)

b) Show that solving the (extended) least squares problem  LaTeX: \textrm{argmin}_{\theta}\; \Vert \overline{y}-\overline{X}\theta  \Vert_2^2 argminθ‖¯y−¯Xθ‖22 shows that

LaTeX: \textrm{argmin}_{\theta}\; \Vert y-X\theta  \Vert_2^2 + \gamma \Vert \theta \Vert_2^2 =\left(X^TX+\gamma I\right)^{-1}X^Tyargminθ‖y−Xθ‖22+γ‖θ‖22=(XTX+γI)−1XTy

 

The left hand side can be rewritten as a traditional LS problem LaTeX: \textrm{argmin}_{\theta}\; \Vert \bar y-\bar X\theta  \Vert_2^2 argminθ‖ˉy−ˉXθ‖22 by clever choice of extended matrices  LaTeX: \bar y \textrm{ and  }\bar Xˉy and ˉX. Then use the old LS-formula LaTeX: \widehat{\theta} = \left(\bar X^T\bar X\right)^{-1}\bar X^T\bar y = ...ˆθ=(ˉXTˉX)−1ˉXTˉy=... and simplify the result.

Solutions: sol1.pdf Download sol1.pdf

0
Please include a description
Additional Comments:
Rating max score to > pts
Please include a rating title

Rubric

Find Rubric
Please include a title
Find a Rubric
Title
You've already rated students with this rubric. Any major changes could affect their assessment results.
 
 
 
 
 
 
 
     
Can't change a rubric once you've started using it.  
Title
Criteria Ratings Pts
This criterion is linked to a Learning Outcome Description of criterion
threshold: 5 pts
Edit criterion description Delete criterion row
5 to >0 pts Full Marks blank
0 to >0 pts No Marks blank_2
This area will be used by the assessor to leave comments related to this criterion.
pts
  / 5 pts
--
Additional Comments
This criterion is linked to a Learning Outcome Description of criterion
threshold: 5 pts
Edit criterion description Delete criterion row
5 to >0 pts Full Marks blank
0 to >0 pts No Marks blank_2
This area will be used by the assessor to leave comments related to this criterion.
pts
  / 5 pts
--
Additional Comments
Total Points: 5 out of 5
Previous
Next
Lecture 1. Supervised Learning 1Next Module:
Week 2