EPL 451 - Data Mining on the Web Web Data Mining ΕΡΓΑΣΤΗΡΙΟ 2 & 3 Prepared by Costantinos Costa Edited by George Nikolaides
Semester Project Microsoft Malware Classification Challenge (BIG 2015) More info: http://www.kaggle.com/c/malware-classification 2/13/2015 EPL 451 - Data Mining on the Web 2
Semester Project A successful submission of your project requires the following: Source code of your implementation along with instructions of how to compile and run your code. Any input data you used to solve this problem with the corresponding output files generated from your solution. A description of your project (6 pages, two columns), specifying in detail your goals, approach, milestones, evaluation methodology and experimental results. A document that describes how you did your experiments and what are your obtained results. Project presentation (15 min per team + 5 min Q/A) 2/13/2015 EPL 451 - Data Mining on the Web 3
Calculate time How to calculate the time long begin = System.currentTimeMillis(); job.waitforcompletion(true); long end = System.currentTimeMillis(); long second = (end - begin) / 1000; System.err.println(job.getJobName() + " takes " + second + " seconds"); 2/13/2015 EPL 451 - Data Mining on the Web 4
Task 1: Anagram Ένας αναγραμματισμός είναι μια λέξη που μπορεί να δημιουργηθεί με τις μετακινήσεις των γραμμάτων μιας άλλης λέξης Π.χ Refills fillers Relayed layered Rentals antlers Rebuild builder Πρέπει να βρείτε τον αναγραμματισμούς σε ένα τεράστιο αρχείο εισόδου. Πως θα το κάνατε? public static boolean isanagram(string first, String second) { // Checks that the two inputs are anagrams, by checking they have all the same characters. // Left as exercise for the user... } 2/13/2015 EPL 451 - Data Mining on the Web 5
Task 1: Anagram Hadoopifying (input) <k1, v1> map <k2, v2> combine <k2, v2> reduce <k3, v3> (output) Download http://www.puzzlers.org/pub/wordlists/unixdict.txt 2/13/2015 EPL 451 - Data Mining on the Web 6
What is Writable? void map( K1 key, V1 value, OutputCollector<K2, V2> output, Reporter reporter) K types implement WritableComparable V types implement Writable Hadoop defines its own box classes for strings (Text), integers (IntWritable), etc. All keys are instances of WritableComparable All values are instances of Writable 2/13/2015 EPL 451 - Data Mining on the Web 7
Getting Data To The Mapper Input file Input file InputSplit InputSplit InputSplit InputSplit InputFormat RecordReader RecordReader RecordReader RecordReader Mapper Mapper Mapper Mapper (intermediates) (intermediates) (intermediates) (intermediates) 2/13/2015 EPL 451 - Data Mining on the Web 8
WritableComparator Compares WritableComparable data Will call WritableComparable.compare() Can provide fast path for serialized data JobConf.setOutputValueGroupingComparator() 2/13/2015 EPL 451 - Data Mining on the Web 9
Partition And Shuffle Mapper Mapper Mapper Mapper (intermediates) (intermediates) (intermediates) (intermediates) Partitioner Partitioner Partitioner Partitioner shuffling (intermediates) (intermediates) (intermediates) Reducer Reducer Reducer 2/13/2015 EPL 451 - Data Mining on the Web 10
Reduction reduce( K2 key, Iterator<V2> values, OutputCollector<K3, V3> output, Reporter reporter) Keys & values sent to one partition all go to the same reduce task Calls are sorted by key earlier keys are reduced and output before later keys 2/13/2015 EPL 451 - Data Mining on the Web 11
Finally: Writing The Output Reducer Reducer Reducer OutputFormat RecordWriter RecordWriter RecordWriter output file output file output file 2/13/2015 EPL 451 - Data Mining on the Web 12
OutputFormat Analogous to InputFormat TextOutputFormat Writes key val\n strings to output file SequenceFileOutputFormat Uses a binary format to pack (k, v) pairs NullOutputFormat Discards output 2/13/2015 EPL 451 - Data Mining on the Web 13
Summary To Hadoop επιτρέπει στον προγραμματιστή να δημιουργήσει δικούς του τύπους κλειδιών/τιμών. Αυτό επιτρέπει τη χρήση άλλων τύπων πέραν των κλασσικών Text, IntWritable κτλ. Αυτοί οι τύποι πρέπει να υλοποιούν (implement) την διεπαφή του Hadoop Writable ή WritableComparable έτσι ώστε το Hadoop να μπορεί να διακινεί τα κλειδιά και τις τιμές στο HDFS. 2/13/2015 EPL 451 - Data Mining on the Web 14
Task 2: Inverted index Σας δίνεται ο κώδικας για το Inverted Index (αντίστροφο ευρετήριο). Ο κώδικας δημιουργεί ένα αρχείο που περιέχει τη κάθε λέξη και σε ποια αρχεία βρίσκεται. Μελετήστε τον κώδικα για να καταλάβετε πώς λειτουργεί. Αλλάξτε των κώδικα ούτος ώστε να δημιουργήσετε ένα δικό σας τύπο δεδομένων για να εξάγετε από τον mapper τα records [filename@offset] και να εισάγετε στον reducer με τη μορφή IndexMapRecordWritable (σας δίδεται η κλάση). 2/13/2015 EPL 451 - Data Mining on the Web 15
Task 3: Inverted index Αλλάξτε των κώδικα ούτος ώστε να δημιουργήσετε ένα δικό σας τύπο δεδομένων για να εξάγετε από τον reducer το τελικό αποτέλεσμα με τη μορφή IndexRecordWritable (σας δίδεται η κλάση) NOTE: You need to override the following functions: /** * Concat all the index map records */ @Override public String tostring() {} /** * Serialize the fields */ @Override public void write(dataoutput out) throws IOException {} /** * Deserialize the fields */ @Override public void readfields(datainput in) throws IOException {} 2/13/2015 EPL 451 - Data Mining on the Web 16