![Page 1: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/1.jpg)
Hadoop Technical Workshop
Module III: MapReduce Algorithms
![Page 2: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/2.jpg)
Algorithms for MapReduce
• Sorting• Searching• Indexing• Classification• Joining• TF-IDF• PageRank• Clustering
![Page 3: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/3.jpg)
MapReduce Jobs
• Tend to be very short, code-wise– IdentityReducer is very common
• “Utility” jobs can be composed• Represent a data flow, more so than
a procedure
![Page 4: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/4.jpg)
Sort: Inputs
• A set of files, one value per line.• Mapper key is file name, line number• Mapper value is the contents of the
line
![Page 5: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/5.jpg)
Sort Algorithm
• Takes advantage of reducer properties: (key, value) pairs are processed in order by key; reducers are themselves ordered
• Mapper: Identity function for value(k, v) (v, _)
• Reducer: Identity function (k’, _) -> (k’, “”)
![Page 6: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/6.jpg)
Sort: The Trick
• (key, value) pairs from mappers are sent to a particular reducer based on hash(key)
• Must pick the hash function for your data such that k1 < k2 => hash(k1) < hash(k2)
M1 M2 M3
R1 R2
Partition and
Shuffle
![Page 7: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/7.jpg)
Final Thoughts on Sort
• Used as a test of Hadoop’s raw speed• Essentially “IO drag race”• Highlights utility of GFS
![Page 8: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/8.jpg)
Search: Inputs
• A set of files containing lines of text• A search pattern to find
• Mapper key is file name, line number• Mapper value is the contents of the
line• Search pattern sent as special
parameter
![Page 9: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/9.jpg)
Search Algorithm
• Mapper:– Given (filename, some text) and
“pattern”, if “text” matches “pattern” output (filename, _)
• Reducer:– Identity function
![Page 10: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/10.jpg)
Search: An Optimization
• Once a file is found to be interesting, we only need to mark it that way once
• Use Combiner function to fold redundant (filename, _) pairs into a single one– Reduces network I/O
![Page 11: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/11.jpg)
Indexing: Inputs
• A set of files containing lines of text
• Mapper key is file name, line number• Mapper value is the contents of the
line
![Page 12: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/12.jpg)
Inverted Index Algorithm
• Mapper: For each word in (file, words), map to (word, file)
• Reducer: Identity function
![Page 13: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/13.jpg)
Index: MapReducemap(pageName, pageText):
foreach word w in pageText: emitIntermediate(w, pageName);done
reduce(word, values):foreach pageName in values: AddToOutputList(pageName);doneemitFinal(FormattedPageListForWord);
![Page 14: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/14.jpg)
Index: Data Flow
This page contains so much text
My page contains text
too
Page A
Page B
My: Bpage : Bcontains: Btext: Btoo: B
This : Apage : Acontains: Aso : Amuch: Atext: A
contains: A, Bmuch: AMy: Bpage : A, Bso : Atext: A, BThis : Atoo: B
Reduced output
A map output
B map output
![Page 15: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/15.jpg)
An Aside: Word Count
• Word count was described in module I
• Mapper for Word Count is (word, 1) for each word in input line– Strikingly similar to inverted index– Common theme: reuse/modify existing
mappers
![Page 16: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/16.jpg)
Bayesian Classification
• Files containing classification instances are sent to mappers
• Map (filename, instance) (instance, class)
• Identity Reducer
![Page 17: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/17.jpg)
Bayesian Classification
• Existing toolsets exist to perform Bayes classification on instance– E.g., WEKA, already in Java!
• Another example of discarding input key
![Page 18: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/18.jpg)
Joining
• Common problem: Have two data types, one includes references to elements of the other; would like to incorporate data by value, not by reference
• Solution: MapReduce Join Pass
![Page 19: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/19.jpg)
Join Mapper
• Read in all values of joiner, joinee classes
• Emit to reducer based on primary key of joinee (i.e., the reference in the joiner, or the joinee’s identity)
![Page 20: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/20.jpg)
Join Reducer
• Joinee objects are emitted as-is• Joiner objects have additional fields
populated by Joinee which comes to the same reducer as them.– Must do a secondary sort in the reducer
to read the joinee before emitting any objects which join on to it
![Page 21: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/21.jpg)
TF-IDF
• Term Frequency – Inverse Document Frequency– Relevant to text processing– Common web analysis algorithm
![Page 22: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/22.jpg)
The Algorithm, Formally
•| D | : total number of documents in the corpus • : number of documents where the term ti appears (that is ).
![Page 23: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/23.jpg)
Information We Need
• Number of times term X appears in a given document
• Number of terms in each document• Number of documents X appears in• Total number of documents
![Page 24: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/24.jpg)
Job 1: Word Frequency in Doc
• Mapper– Input: (docname, contents)– Output: ((word, docname), 1)
• Reducer– Sums counts for word in document– Outputs ((word, docname), n)
• Combiner is same as Reducer
![Page 25: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/25.jpg)
Job 2: Word Counts For Docs
• Mapper– Input: ((word, docname), n)– Output: (docname, (word, n))
• Reducer– Sums frequency of individual n’s in
same doc– Feeds original data through– Outputs ((word, docname), (n, N))
![Page 26: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/26.jpg)
Job 3: Word Frequency In Corpus
• Mapper– Input: ((word, docname), (n, N))– Output: (word, (docname, n, N, 1))
• Reducer– Sums counts for word in corpus– Outputs ((word, docname), (n, N, m))
![Page 27: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/27.jpg)
Job 4: Calculate TF-IDF
• Mapper– Input: ((word, docname), (n, N, m))– Assume D is known (or, easy MR to find
it)– Output ((word, docname), TF*IDF)
• Reducer– Just the identity function
![Page 28: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/28.jpg)
Working At Scale
• Buffering (doc, n, N) counts while summing 1’s into m may not fit in memory– How many documents does the word
“the” occur in?
• Possible solutions– Ignore very-high-frequency words– Write out intermediate data to a file– Use another MR pass
![Page 29: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/29.jpg)
Final Thoughts on TF-IDF
• Several small jobs add up to full algorithm• Lots of code reuse possible
– Stock classes exist for aggregation, identity
• Jobs 3 and 4 can really be done at once in same reducer, saving a write/read cycle
• Very easy to handle medium-large scale, but must take care to ensure flat memory usage for largest scale
![Page 30: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/30.jpg)
PageRank: Random Walks Over The Web
• If a user starts at a random web page and surfs by clicking links and randomly entering new URLs, what is the probability that s/he will arrive at a given page?
• The PageRank of a page captures this notion– More “popular” or “worthwhile” pages
get a higher rank
![Page 31: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/31.jpg)
PageRank: Visually
www.cnn.com
en.wikipedia.org
www.nytimes.com
![Page 32: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/32.jpg)
PageRank: Formula
Given page A, and pages T1 through Tn linking to A, PageRank is defined as:
PR(A) = (1-d) + d (PR(T1)/C(T1) + ... + PR(Tn)/C(Tn))
C(P) is the cardinality (out-degree) of page Pd is the damping (“random URL”) factor
![Page 33: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/33.jpg)
PageRank: Intuition
• Calculation is iterative: PRi+1 is based on PRi
• Each page distributes its PRi to all pages it links to. Linkees add up their awarded rank fragments to find their PRi+1
• d is a tunable parameter (usually = 0.85) encapsulating the “random jump factor”
PR(A) = (1-d) + d (PR(T1)/C(T
1) + ... + PR(T
n)/C(T
n))
![Page 34: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/34.jpg)
Graph Representations
• The most straightforward representation of graphs uses references from each node to its neighbors
![Page 35: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/35.jpg)
Direct References
• Structure is inherent to object
• Iteration requires linked list “threaded through” graph
• Requires common view of shared memory (synchronization!)
• Not easily serializable
class GraphNode{ Object data; Vector<GraphNode> out_edges; GraphNode iter_next;}
![Page 36: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/36.jpg)
Adjacency Matrices
• Another classic graph representation. M[i][j]= '1' implies a link from node i to j.
• Naturally encapsulates iteration over nodes
01014
00103
11012
10101
4321
![Page 37: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/37.jpg)
Adjacency Matrices: Sparse Representation
• Adjacency matrix for most large graphs (e.g., the web) will be overwhelmingly full of zeros.
• Each row of the graph is absurdly long
• Sparse matrices only include non-zero elements
![Page 38: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/38.jpg)
Sparse Matrix Representation
1: (3, 1), (18, 1), (200, 1)2: (6, 1), (12, 1), (80, 1), (400, 1)3: (1, 1), (14, 1)…
![Page 39: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/39.jpg)
Sparse Matrix Representation
1: 3, 18, 2002: 6, 12, 80, 4003: 1, 14…
![Page 40: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/40.jpg)
PageRank: First Implementation
• Create two tables 'current' and 'next' holding the PageRank for each page. Seed 'current' with initial PR values
• Iterate over all pages in the graph, distributing PR from 'current' into 'next' of linkees
• current := next; next := fresh_table();• Go back to iteration step or end if
converged
![Page 41: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/41.jpg)
Distribution of the Algorithm
• Key insights allowing parallelization:– The 'next' table depends on 'current', but
not on any other rows of 'next'– Individual rows of the adjacency matrix
can be processed in parallel– Sparse matrix rows are relatively small
![Page 42: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/42.jpg)
Distribution of the Algorithm
• Consequences of insights:– We can map each row of 'current' to a list
of PageRank “fragments” to assign to linkees
– These fragments can be reduced into a single PageRank value for a page by summing
– Graph representation can be even more compact; since each element is simply 0 or 1, only transmit column numbers where it's 1
![Page 43: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/43.jpg)
Map step: break page rank into even fragments to distribute to link targets
Reduce step: add together fragments into next PageRank
Iterate for next step...
![Page 44: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/44.jpg)
Phase 1: Parse HTML
• Map task takes (URL, page content) pairs and maps them to (URL, (PRinit, list-of-urls))– PRinit is the “seed” PageRank for URL– list-of-urls contains all pages pointed to
by URL
• Reduce task is just the identity function
![Page 45: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/45.jpg)
Phase 2: PageRank Distribution
• Map task takes (URL, (cur_rank, url_list))– For each u in url_list, emit (u, cur_rank/|
url_list|)– Emit (URL, url_list) to carry the points-to
list along through iterations
PR(A) = (1-d) + d (PR(T1)/C(T
1) + ... + PR(T
n)/C(T
n))
![Page 46: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/46.jpg)
Phase 2: PageRank Distribution
• Reduce task gets (URL, url_list) and many (URL, val) values– Sum vals and fix up with d– Emit (URL, (new_rank, url_list))
PR(A) = (1-d) + d (PR(T1)/C(T
1) + ... + PR(T
n)/C(T
n))
![Page 47: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/47.jpg)
Finishing up...
• A subsequent component determines whether convergence has been achieved (Fixed number of iterations? Comparison of key values?)
• If so, write out the PageRank lists - done!
• Otherwise, feed output of Phase 2 into another Phase 2 iteration
![Page 48: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/48.jpg)
PageRank Conclusions• MapReduce runs the “heavy lifting” in
iterated computation• Key element in parallelization is
independent PageRank computations in a given step
• Parallelization requires thinking about minimum data partitions to transmit (e.g., compact representations of graph rows)– Even the implementation shown today
doesn't actually scale to the whole Internet; but it works for intermediate-sized graphs
![Page 49: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/49.jpg)
Clustering
• What is clustering?
![Page 50: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/50.jpg)
Google News
• They didn’t pick all 3,400,217 related articles by hand…
• Or Amazon.com
• Or Netflix…
![Page 51: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/51.jpg)
Other less glamorous things...
• Hospital Records• Scientific Imaging
– Related genes, related stars, related sequences
• Market Research– Segmenting markets, product positioning
• Social Network Analysis• Data mining• Image segmentation…
![Page 52: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/52.jpg)
The Distance Measure
• How the similarity of two elements in a set is determined, e.g.– Euclidean Distance– Manhattan Distance– Inner Product Space– Maximum Norm – Or any metric you define over the
space…
![Page 53: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/53.jpg)
• Hierarchical Clustering vs.• Partitional Clustering
Types of Algorithms
![Page 54: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/54.jpg)
Hierarchical Clustering
• Builds or breaks up a hierarchy of clusters.
![Page 55: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/55.jpg)
Partitional Clustering
• Partitions set into all clusters simultaneously.
![Page 56: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/56.jpg)
Partitional Clustering
• Partitions set into all clusters simultaneously.
![Page 57: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/57.jpg)
K-Means Clustering • Simple Partitional Clustering
• Choose the number of clusters, k• Choose k points to be cluster centers• Then…
![Page 58: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/58.jpg)
K-Means Clustering
iterate { Compute distance from all points to all k- centers Assign each point to the nearest k-center Compute the average of all points assigned to all specific k-centers
Replace the k-centers with the new averages}
![Page 59: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/59.jpg)
But!
• The complexity is pretty high: – k * n * O ( distance metric ) * num
(iterations)
• Moreover, it can be necessary to send tons of data to each Mapper Node. Depending on your bandwidth and memory available, this could be impossible.
![Page 60: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/60.jpg)
Furthermore
• There are three big ways a data set can be large:– There are a large number of elements in
the set.– Each element can have many features.– There can be many clusters to discover
• Conclusion – Clustering can be huge, even when you distribute it.
![Page 61: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/61.jpg)
Canopy Clustering
• Preliminary step to help parallelize computation.
• Clusters data into overlapping Canopies using super cheap distance metric.
• Efficient• Accurate
![Page 62: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/62.jpg)
Canopy Clustering
While there are unmarked points { pick a point which is not strongly marked call it a canopy centermark all points within some threshold of
it as in it’s canopystrongly mark all points within some
stronger threshold }
![Page 63: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/63.jpg)
After the canopy clustering…
• Resume hierarchical or partitional clustering as usual.
• Treat objects in separate clusters as being at infinite distances.
![Page 64: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/64.jpg)
MapReduce Implementation:
• Problem – Efficiently partition a large data set (say… movies with user ratings!) into a fixed number of clusters using Canopy Clustering, K-Means Clustering, and a Euclidean distance measure.
![Page 65: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/65.jpg)
The Distance Metric
• The Canopy Metric ($)
• The K-Means Metric ($$$)
![Page 66: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/66.jpg)
Steps!
• Get Data into a form you can use (MR)• Picking Canopy Centers (MR)• Assign Data Points to Canopies (MR)• Pick K-Means Cluster Centers• K-Means algorithm (MR)
– Iterate!
![Page 67: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/67.jpg)
Selecting Canopy Centers
![Page 68: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/68.jpg)
![Page 69: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/69.jpg)
![Page 70: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/70.jpg)
![Page 71: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/71.jpg)
![Page 72: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/72.jpg)
![Page 73: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/73.jpg)
![Page 74: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/74.jpg)
![Page 75: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/75.jpg)
![Page 76: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/76.jpg)
![Page 77: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/77.jpg)
![Page 78: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/78.jpg)
![Page 79: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/79.jpg)
![Page 80: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/80.jpg)
![Page 81: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/81.jpg)
![Page 82: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/82.jpg)
![Page 83: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/83.jpg)
Assigning Points to Canopies
![Page 84: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/84.jpg)
![Page 85: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/85.jpg)
![Page 86: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/86.jpg)
![Page 87: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/87.jpg)
![Page 88: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/88.jpg)
![Page 89: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/89.jpg)
K-Means Map
![Page 90: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/90.jpg)
![Page 91: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/91.jpg)
![Page 92: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/92.jpg)
![Page 93: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/93.jpg)
![Page 94: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/94.jpg)
![Page 95: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/95.jpg)
![Page 96: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/96.jpg)
![Page 97: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/97.jpg)
Elbow Criterion• Choose a number of clusters s.t.
adding a cluster doesn’t add interesting information.
• Rule of thumb to determine what number of Clusters should be chosen.
• Initial assignment of cluster seeds has bearing on final model performance.
• Often required to run clustering several times to get maximal performance
![Page 98: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/98.jpg)
Clustering Conclusions
• Clustering is slick• And it can be done super efficiently• And in lots of different ways
![Page 99: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/99.jpg)
Conclusions
• Lots of high level algorithms• Lots of deep connections to low-level
systems
![Page 101: Hadoop Technical Workshop Module III: MapReduce Algorithms](https://reader030.vdocument.in/reader030/viewer/2022033108/56649d385503460f94a120ac/html5/thumbnails/101.jpg)