Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Summer 2022 Online Assessment Instructions

ST2195 Programming for data science

Thursday 5 May 2022: 09:00 - 12:00 (BST)

Section A

This section contains six questions.  Answer all six questions.

1.  Consider the data structures that are created by running the following Python script:

A = [2,4,3]

B = {1,2,1}

C = ( 'John', 'George ',A)

D = {

"brand": "Mercedes",

"model": "B Class",

"year": 2014

}

Provide the output of the following commands if they were to be run after the Python script above. If you think the code will result in an error, just type error’.

A[1]

print(B)

C[2]

print(D["model"])

  Marks: 6

2. For each of the circumstances below do state, with yes/no answer, whether side-by-side boxplots provide an appropriate choice. All subquestions carry equal weight. One mark will be deducted for each incorrect answer. The minimum mark for this question is zero.

(a)  When we want to monitor changes in the distribution of a variable across different categories of another variable.

(b)  When we want to explore the association between two continuous variables.

(c)  When we want to compare frequencies of one variable’s categories across different categories of another variable.

(d)  When we want to study the empirical density of a single variable.

  Marks: 6

3. For each of the statements below state whether it is correct or incorrect.  All subquestions carry equal weight. One mark will be deducted for each incorrect answer. The minimum mark for this question is zero.

(a)  Random forests cannot be used for classication.

Suppose that model A has lower test error than model B, but model A has higher training error

than model B. We will choose model A.

(c)  In classication we can assess the predictive performance by looking at the sensivity.

(d)  In cross-validation all points will be selected as test points.

  Marks: 6

4. Which two of the following statements are correct? You may only give up to two answers.

(a)  R is a programming language that works only on Windows.

(b)  An active internet connection is necessary for the command library(ggplot2) to work in R (c)  Some source-code editors provide code indentation and syntax highlighting

(d)  There are only 2 source-code editors for R and 5 for Python.

(e)  There are source-code editors that can be used for both R and Python

(f)  The help le of the read.csv() function in R can be accessed by typing ?read.csv

  Marks: 6

5. Which three of the following statements are correct? You may only give up to three answers.

(a)  R notebooks is an authoring framework that combines Markdown with R (b)  Jupyter notebooks can handle Julia and Python code.

(c)  R Markdown notebooks are special Jupyter notebooks.

(d)  Jupyter notebooks were named after the rst names of its creators, Julia and Peter. (e)  R Markdown les can only be converted to HTML.

(f)  The author and date of an R Markdown le can be specied in the YAML metadata.

  Marks: 6

6. Note from which language (R or Python) each of the following code chunks is from.  Give your answer in the form question number, language”, e.g. “C11, R”.

C1. import pandas

C2. ggplot(df, aes(x = v1, y = v2))

C3. plot(log, 0, 10)

C4. typeof("a")

C5. type("a")

C6. blurp = "Coding rocks"; blurp.upper()

C7. read.table("df.csv")

C8. sapply(1:10, "-", 1)

C9. filter(df, Course == "ST2195")

C10. df[-c(1, 3, 4), ]

  Marks: 10

Section B

This section contains six questions.  Answer all six questions.

1. For each of the following statements about R, state if they are correct or not. Provide justification for your answer of no more than two sentences.

(a)  A list contains vectors of dierent lengths.

(b)  A data frame is also a matrix.

(c) A data frame is also an array.

(d) A vector is also a matrix.

(e) A matrix is also an array.

  Marks: 10

2. For each of the following statements about R, state if they are always correct or not.  Provide justification for your answer of no more than two sentences.

(a)  The rows of a table in a relational database represent attributes.

(b)  The records in a table of an SQLite database cannot be altered.

(c)  SQLite uses a separate server process to operate.

(d)  The SQL query adds the record with attributes KitKat”, “A”, and 1 in the table Products.

INSERT INTO Products VALUES("KitKat", "A", 1)

The following R code chunk nds all records in the data frames Products and Sales that have

matching values of Name, and returns only those records where Number is greater than 1 or Category is not equal to A’.

inner_join(Products, Sales, by = "Name") %>%

filter(Number > 1, Category != "A")

  Marks: 10

3. Explain in no more than 2 sentences, why the following statements are wrong.

(a)  RStudio is the IDE that R comes with.

(b)  pandas allows the removal of items in a tuple in Python.

(c)  The only way to create a Git repository is in Github.

(d)  Adding a double to a vector of doubles is not supported in R.

(e)  Base Python does not allow the creation of a list of lists.

(f)  A matrix in R is immutable.

(g)  The command git commit is used to let your collaborators know that you will make an edit. (h)  The command  [[1,2,3,4],[3,2,1]] in Python will create a matrix with 4 rows and 3 columns.

(i)  plot() in R can only be used to produce lineplot graphics. (j)  Structured data is all data that can be opened in Python.

  Marks: 10

4.  Match the commands C1-C4 with the output in O1-O4. There is no need to provide justification in this question.

C1. c(1,2,3)

C2.  [1,2,3]

C3. ifelse(-2, "A", "B")

C4. ifelse(is.character(1), "A", "B")

O1.  1 2 3

O2. A

O3. B

O4.  [1, 2, 3]

  Marks: 10

5.  Consider a data set consisting of several at sales in a city over the past year. The data contain the following variables:

•  Price: the price of the at sale

  Station:  whether a bus or a train station is nearby (1:  yes, 0:  no)

  Floor:  0:  underground, 1:  ground oor, 2:  1st oor, 3:  2nd oor or above

  Bulding_age: years since the building was rst erected.

(a)  Describe what graphs you would produce to demonstrate how the presence of a bus or train station, oor and bulding age may affect the at sale price.

(b)  How would your answer on part (a) change if Floor was considered as a continuous variable?

  Marks: 10

6.  Consider the following numerical vectors:

Temp = [12,50,70,25]

Type = [1,0,0,1]

The first vector contains temperatures whereas the second vector indicates whether these degrees are in Celsius or Fahrenheit units (0: Farhenheit, 1: Celsius). Using a for loop and a conditional statement, write a program (could be either R or Python or just the necessary steps in plain English) that transforms the vector Temp, so that it only contains Celsius degrees, and records this change into the vector Type as well. You can use the following formula for converting from Fahrenheit to

Celsius:

Celsius =  (Fahrenheit ≠ 32)

  Marks: 10