Welcome to the practicals for the course aDAV. In the practicals we will get hands-on experience with the materials in the lectures by doing theoretical exercises, programming in
R, and completing assignments. This is the first practical. In this practical, we will start with a exercise on the distinction between supervised and unsupervised learning, and then proceed with
R. We will briefly introduce how we are going to work with
RStudio for the remainder of the course, and get to know (some of) the datasets that we are going to work with.
From these practicals, nothing needs to be handed in. You are doing these practicals to get experience with the material from the lectures and to practice for the assignments (which do need to be handed in).
Supervised and unsupervised learning
In the lecture and reading material for this week we have seen that machine learning can be classified on the characteristics of the data and the tasks it aims to solve. A main distinction to be made is that between supervised and unsupervised learning:
In this exercise, we will practice this distinction using 10 examples.
A biologist friend of yours asks you to assess the phylogenetic relation between different species of birds using genetic information (traits). The outcome of your analysis is a phylogenetic tree in which species that diverged more recently are closely linked together. Phylogenetic tree of life built using ribosomal RNA sequences, after Karl Woese. Image credit: Modified from Eric Gaba, Wikimedia Commons.
A pharmaceutical company is developing a drug to treat certain type of cancer. The first step is looking for targets: they ask you to analyse data consisting on the differential expression of 10,000 genes in micro-RNA chips from different tissues. You want to uncover groups of genes that display similar expression patterns in each of the tissues.
R projects and Markdown files
We assume that you are already familiar with R and Rstudio, as outlined in the entry requirements of the course. In addition, we assume you are familiar with using Rstudio projects and R Markdown files, as outlined in the course Preparation. If you haven’t completed the course preparation tab on the website yet, please do so before next class. If you feel you still lack some R skills, there are some sources mentioned under Preparation.
In this course we will always work in a project. During this practical, we will work in the project
01_R_intro_students.Rprojin RStudio and run the following code in the console. Do you know where the file “sometext.txt” is located on your disk?
In addition, we will make extensive use of
.Rmd files, R Markdown files. With R Markdown files, we can easily create documents which seamlessly combine text, code, and plots. The document you are reading right now was generated from an R Markdown file.
r_introduction_stu.Rmdfrom the Files pane in RStudio.
Knit > Knit to HTMLon top of the source pane.
The assignments in week 3 and week 8 need to be handed in as an
R project folder with data, a
.Rmd file, and the
.html file generated from it.
From practical 2 onwards, we will always start by opening the
R project and do the assignments directly in the R Markdown file. Under each assignment, you can insert an
R chunk and input your code there. If you prefer, you may also work directly in a
.R file for the practicals. Note that if you do this, you will still have to work with an
.Rmd file for the assignments.
Datasets from the ISLR package
The first book we are using in this course is Introduction to Statistical Learning, abbreviated as ISLR. The authors use several datasets throughout the book which are packaged in the
ISLR. The datasets are: Auto, Caravan, Carseats, College, Credit, Default, Hitters, Khan, NCI60, OJ, Portfolio, Smarket, Wage, Weekly.
Rby running the following in the console
You only need to install packages once. When they are installed on your system, you can always load them in your environment using
library(). Let’s have a closer look at some of the datasets we will be working with.
head()to look at the first few rows of the
Hittersdataset. What data does this dataset contain? What are the variable types? Hint: to get more information on what each column represents, this dataset comes with a neat help file that can be accessed through
Bostondataset, contained in the
MASSlibrary. What data does this dataset contain? What are the variable types? Hint: also this dataset comes with a neat help file that can be accessed through
summary()to create a summary of the
Bostondataset. What is the range and median per capita crime rate by town? And what is the range of the average number of rooms per dwelling?
Throughout this course, try to maintain a consistent and legible style for your code. This is very important as it will make your collaborators, as well as future you happy. Being able to read and understand your own code after a year of not looking at it is possible if you use consistent style and informative comments where necessary.
Try to adhere to this style for your assignments, too. Tip: in RStudio, you can display a vertical line at 80 characters to know when your code exceeds this. You can do this at Tools > Global Options > Code > Display > Show margin.
If you have followed this practical, you are all set for the remainder of this course! Next week, we will have a closer look at the Visualization using ggplot.