Practical 1-2com
Practical 1-2com
BIG-DATA ANALYSIS(203105348)
B.Tech CSE 4th Year 7th Semester
7th SEMESTER
7A9 (CSE)
Name: Aashutosh.S.yadav
Year/Sem: 4th
2203051057108 1
Faculty OfEngineering& Technology
BIG-DATA ANALYSIS(203105348)
B.Tech CSE 4th Year 7th Semester
CERTIFICATE
Mr./Ms..............................................................................................................
with enrolment no. ................................................................ has
successfully completed his/her laboratory experiments in the Big Data
Analytics (203105348) From the Department of
...................................................................................................
2203051057108 2
Faculty OfEngineering& Technology
BIG-DATA ANALYSIS(203105348)
B.Tech CSE 4th Year 7th Semester
INDEX
2203051057108 3
Faculty OfEngineering& Technology
BIG-DATA ANALYSIS(203105348)
B.Tech CSE 4th Year 7th Semester
Practical:1
AIM: To understand the overall programming architecture using Map Reduce API.
The MapReduce task is mainly divide into into two phase map phase and Reduce Phase.
1. Map(), filter(), and reduce() in python.
2. These functions are most commonly used with lambda function.
1.Map():
“A map function execute certain instructions or functionality provided to it on every item of an
iterable could be a list, tuple, set, etc.
SYNTAX:
Map(function,iterable)
EXAMPLE:
items=[1,2,3,4,5]
a=list(map((lambda x: x **3), items))
print(a)
2.Filter():-
“A filter function in python tests a specific user-defined confition for a function and returns an
iterable for the elements and values that satisfy the condition or, in other words, return true.”
2203051057108 4
Faculty OfEngineering& Technology
BIG-DATA ANALYSIS(203105348)
B.Tech CSE 4th Year 7th Semester
SYNTAX:
Filter(function, iterable)
EXAMPLE:
a=[1,2,3,4,5]
b=[2,5,0,7,3]
c=list(filter(lambda x: x in a,b))
print(c)# prints out[2,5,3]
3.Reduce():
“Reduce function apply a function to every item of an iterable and gives back a single value as a
resultant”.
We have to import the reduce function from functools module using the statement.
SYNTAX:
reduce(function, iterable)
EXAMPLE:
from functools import reduce
a=reduce((lambda x, y: x*y),[1,2,3,4,])
print(a)
2203051057108 5
Faculty OfEngineering& Technology
BIG-DATA ANALYSIS(203105348)
B.Tech CSE 4th Year 7th Semester
2203051057108 6
Faculty OfEngineering& Technology
BIG-DATA ANALYSIS(203105348)
B.Tech CSE 4th Year 7th Semester
Practical-2
Map
Map
Input data set is split into independent blocks – processed in parallel. Each input split is
converted in Key Value pairs. Mapper logic processes each key value pair and produces and
intermediate key value pairs based on the implementation logic. Resultant key value pairs can
be of different type from that of input key value pairs. The output of Mapper is passed to the
reducer. Output of Mapper function is the input for Reducer. Reducer sorts the intermediate
2203051057108 7
Faculty OfEngineering& Technology
BIG-DATA ANALYSIS(203105348)
B.Tech CSE 4th Year 7th Semester
key value pairs. Applies reducer logic upon the key value pairs and produces the output in
desired format.Output is stored in HDFS.
Python Code
import urllib.request
import random
import_word = {}
import_count = 0
story = 'http://sixty-north.com/c/t.txt'
2203051057108 8
Faculty OfEngineering& Technology
BIG-DATA ANALYSIS(203105348)
B.Tech CSE 4th Year 7th Semester
request =urllib.request.Request(story)
response = urllib.request.urlopen(request)
each_word = []
words = 1
same_words = {}
word = []
line_words = line.split()
each_word.append(word)
same_words[words.lower()] = 1
else:
same_words[words.lower()] =same_words[words.lower()]= +1
2203051057108 9
Faculty OfEngineering& Technology
BIG-DATA ANALYSIS(203105348)
B.Tech CSE 4th Year 7th Semester
Output:-
2203051057108 10