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

COMP4103-E1

A LEVEL 4 MODULE, SPRING SEMESTER 2021-2022

Big Data

Question 1: Introduction and MapReduce

a.   List two advantages of scale-out over scale-up when dealing with Big Data. Briefly explain your answer.

[2 marks]

b.  Why do we say that Big Data has many faces? Briefly explain your answer providing an example of one of those faces of Big Data.

[2 marks]

c.  To count the word frequency of a 26GB text file, you are given two options:

Option 1 : 1 computer, 32GB of RAM, 4 cores, 1TB drive

Option 2: 2 computers, 24GB of RAM each, 2 cores each, 1TB drive each

Which option would you choose?  Briefly explain the advantage(s) and disadvantage(s) of one option over the other.

[2 marks]

d.   In your own words,  briefly explain what is the role of Combiners in the MapReduce paradigm and why do they usually use the same code of the reduce function?

[2 marks]

e.  Why is making our applications fault-tolerant so important in Big Data?  Briefly explain your answer.

[2 marks]

f.  The following two questions are all about MapReduce. You are asked to define how to use it to solve two problems at a conceptual level, so that, no code is expected/needed here. For each one of them, you have to:

Draw the MapReduce workflow, indicating input and output key/values at each stage (map, shuffle, and reduce).

• Briefly explain how the map and reduce functions could be implemented, using pseudo- code.

You can use multiple MapReduce stages if you consider it necessary.

i. It might be interesting to analyse how different websites are linked with each other. In particular, we are interested in obtaining a list of mutually linked URLs. That is, we want to know which URLs are mutually linking each other in their webpage content.

You are asked to design a MapReduce solution for this, assuming that the input is a big file that contains for each URL the list of URLs that are linked within its content.         Input: A file with the following format: URL -> List of URLs.

URL_1 -> URL_2 URL_4

URL_2 -> URL_1 URL_3 URL_4 URL_5 URL_6

URL_3 -> URL_2 URL_5 URL_6

URL_4 -> URL_2 URL_3 URL_5

URL_5 -> URL_2 URL_3 URL_4

URL_6 -> URL_2 URL_4

Output: (pair of mutually linked URLs)

(URL_1

(URL_2

(URL_2

(URL_2

(URL_2

(URL_3

(URL_4

URL_2)

URL_3)

URL_4)

URL_5)

URL_6)

URL_5)

URL_5)

[6 marks]

ii. You are asked to design the map and reduce functions to find the index of the nearest neighbour of an input vector within a set of vectors. You can assume that to compute

the similarity between vectors you have a function dist(a, b) that calculates the Euclidean distance between two vectors a and b, both of length N .

Input: A set of vectors as key-value pairs, where the key is the index and value the vector. Also, an input vector for which we want to find its nearest neighbour in the set. You can assume that this vector is available in all the worker nodes.

Set of vectors:

(0, (1, 2))

(1, (1, 1))

(2, (2, 1))

(3, (0, 1))

Input vector: (0, 0.5)

Output:  index of the most similar vector to the input one (the one with the lowest distance) and the distance.

(3, 0.25)  # index 3 corresponds to vector (0,1) in the above set.

[4 marks]

End of Question 1: Total 20 marks

Question 2: Big Data Frameworks

a.   List the two main components/modules of Apache Hadoop. Briefly explain your answer. [2 marks]

b.   Indicate whether the following statements about Hadoop are True or False. Briefly explain your answer.

i. Hadoop follows a scale-up strategy, so that, it cant add new computing nodes.

ii. In YARN, the Application Master is usually run in the master/driver node of a cluster.

iii. You cannot run more than one MapReduce job at the same time on a Hadoop Cluster.

iv. Hadoop uses the concept of virtualisation to provide isolation of resources.

[2 marks]

c.   Indicate whether the following statements about the Hadoop Distributed File System (HDFS) are True or False. Briefly explain your answer.

i. The HDFS is good at reading big files, but not so good at making/writing random changes in the data.

ii. The HDFS was designed to have a very low latency.

iii. The concept of block is important in HDFS to provide fault tolerance.

iv. The Namenode knows about the whereabouts of all the files on a HDFS.

[2 marks]

d.   Briefly explain the difference(s) between a transformation and an action in Apache Spark. [2 marks]

e.   Indicate whether the following statements about Spark are True or False. Briefly explain your answer.

i. Spark is not only a data processing engine as it does come with its own distributed file system.

ii. Spark provides a fault tolerant mechanism for RDDs but not for DataFrames.

iii. Spark SQL is generally faster when using the Scala API compared to the Python API .

iv. Spark extended the MapReduce programming model with additional operations.

[2 marks]

f.   Spark does not necessarily need to use HDFS to run an application. However, most cluster of computing nodes will use HDFS.  Briefly explain why that is the case.

[2 marks]

g.  You are given a file containing numbers in each line. We have to perform three transforma- tions: (1) filter negative numbers, (2) then multiply each element by two, (3) and finally group them by key (e.g. to differentiate between odd and even numbers). Indicate and explain what kind of dependencies are associated to those 3 transformations.

[2 marks]

h.  What are the outputs of the following pyspark programs? Briefly explain your answer.

i. rdd = sc.parallelize([1,2,3,-1,-2,-3])

rdd.filter(lambda x: x >= 0)\

.map(lambda x: (1,x) if x%2 == 0 else (2,x))\

.reduceByKey(lambda x,y: x+y).collect()

ii. a = rdd.toDF() a.count()

[4 marks]

Some lines may have no output or trigger an error.  In the latter case, specify what the reason of the error is.  Note that some instructions may depend on the result of previous lines. For example, in ii) the content of rdd comes from i).

i.   Indicate whether or not the following instructions are lazy.

i. rdd = sc.parallelize([('COMP4103', 54), ('COMP4103', 64), ('COMP4008',87)])

ii. df = rdd.toDF(['module','mark'])

iii. print(df.collect())

iv. df2 = df.groupBy('module').count()

[4 marks] j.  We have the following rdd that contains tuples with names and exam marks for our TAs.

= sc.parallelize([('Lam',45),

('Tim', 64),

('Alexi',69),

('Kavan', 87),

('Rebecca',95)])

Using the RDD API, write a Spark program that will transform the rdd  converting the numerical marks into degree classifications. That is, anything less than 50 is a fail; in the [50,59] interval is a Pass; in the [60,69] interval is a Merit; and in the [70,100] interval is a Distinction. When collecting the new RDD, it should return a list like this:

[('Lam', 'Fail'),

('Tim', 'Merit'),

('Alexi', 'Merit'),

('Kavan', 'Distinction'),

('Rebecca', 'Distinction')]

[4 marks]

k.   Using the original rdd  from the previous exercise with numeric marks, do the following operations:

i. Create a DataFrame df with the same content of rdd .

[2 marks]

ii. Write a Spark program  to transform that df to add a column with the degree classi- fication. Note that there isn’t a function in SparkSQL that you could use here. You are asked to solve this in two different ways:

• Using the underlying RDD, and then transform it back to DataFrame.

[2 marks]

• Using a User Defined Function. In case you forgot the syntax for this, here is an example of a UDF to compute the length of each element of a column:

slen = udf(lambda s: len(s), IntegerType())

df.select(df.name,slen(df.name).alias('slen')).show()

[2 marks]

iii. Write a Spark program  to group by classification degree and count how many stu- dents fall into each category. The content of the resulting DataFrame should be like this:

>> df.show()

+--------------+-----+

|classification|count|

+--------------+-----+

|         Fail |    1 |

|        Merit |   2 |

|  Distinction |   2 |

+--------------+-----+

[2 marks]

l.   Using the RDD API, you are asked to implement a function mutually_linked(file_path) that reads a file that contains for each URL the list of URLs that are linked within its content and computes the pairs of websites that are mutually linked. The format of the expected input and output follow the same format as in Question 1.f.a. Note : if you can’t remember a particular detail with Python, use pseudo-code to explain your solution.

[6 marks]

End of Question 2: Total 40 marks

Question 3: Machine Learning with Big Data

a.   Indicate whether the following statements are True or False.  Briefly explain your an- swer.

i. The MLlib follows a global approach in most of its implementations.

ii. The test phase of a machine learning model in Big Data is usually not parallelised.

iii. Local models are usually faster in both training and test phases.

iv. The accuracy performance of a global model is independent of the number of partitions.

[4 marks]

b.   I run the Decision Tree from the MLLib on a relatively small dataset, and I have got quite a different result from what I got using the scikit-learn library.  Briefly explain why this might be happening.

[3 marks]

c.  You are using your own laptop to run the Logistic Regression from the MLlib, and you are testing it in pseudo-distributed mode (i.e. option local[*]). You test the accuracy and you are happy with it, however, it takes 3 days to train the model. If you were to use a real’ cluster of computing nodes (e.g. 10 nodes), would you expect the accuracy to remain the same? Briefly explain your answer.

[3 marks]

d.  After the previous experiment, you decide to implement your own local-based solution for Logistic Regression.

i. Briefly explain how the training and test phases would be designed.

[3 marks]

ii. Using the same data as before, you run it on your own laptop in pseudo-distributed mode (i.e.  option local[*]), would you also expect to take around 3 days to train a model? Briefly explain your answer.

[3 marks] iii. When testing it in the real’ cluster, would you expect the accuracy to remain the same?

Briefly explain your answer.

[2 marks]

e.   I want to build a local model that performs the testing phase directly. I have managed to produce the following code:

df = spark.read.csv("data.csv") # We read a file in CSV format as a DataFrame

train,test = df.randomSplit([0.8,0.2]) # split into training and test

# we define a function that receives two arguments, a partition

# of the training data and the test.

def my_ml_method(partition,test):

# this method uses the sklearn library to fit a model and aims to predict the test

# we use this function within `mapPartitions`

train.rdd.mapPartitions(lambda partition : my_ml_method(partition, test))

However, this doesn’t seem to work.  Explain why, and provide a solution for it.  Note that the output of the randomSplit function is two Spark DataFrames, train and test.

[6 marks]

f.  The k-nearest neighbour algorithm classifies a new instance based on the Euclidean Dis- tance of that instance against the entire training set, that is, it doesn’t perform any training.

Then, the labels of the k  nearest instances in the training set are used to determine the class of the input test instance.  You are asked to design a Big Data solution to par- allelise the processing of the k-nearest neighbours to classify a single test instance. The input instance would look like:

[feature 1, feature 2, ...., feature N], unknown class

And the training data would have a large number of instances:

instance 1: [feature 1, feature 2, ...., feature N], class X

...

instance M:  [feature 1, feature 2, ...., feature N], class X

Your design should take these two as input, together with k, the number of nearest neigh- bours considered, and provide the predicted class.  For full marks, your implementation should allow for an arbitrary number of neighbours k .

>> nearest_neighbour_BIG(training data, input instance, k=3)

Predicted Class

i. Draw a MapReduce-like diagram explaining how you would design a solution for this. Indicate any key-values if needed.

[4 marks]

ii. Write down some pseudo-code (Spark-like) that explains how the solution would work. You can assume you have functions to compute the k  nearest neighbours and their distances sequentially (e.g. from the scikit-learn library).

[4 marks] iii. Briefly discuss the expected advantages and disadvantages of your design.

[4 marks]

iv. If instead of a single input test instance, we wanted to classify a relatively small set of test instances, briefly explain what changes would you make to your solution (if any)?

[4 marks]

End of Question 3: Total 40 marks