Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

- Naive bayes by Ashraf Uddin 25400 views
- Sentiment analysis using naive baye... by Dev Sahu 14237 views
- Tweets Classification using Naive B... by Trilok Sharma 13000 views
- Naive Bayes Presentation by chowdhury343 1919 views
- Lesson 7.1 Naive Bayes Classifier by Gladys Castillo 16256 views
- 2013-1 Machine Learning Lecture 03 ... by Dae-Ki Kang 4103 views

27,885 views

Published on

Presented on Wed Apr 27 2011 at SeaHUG in Seattle, WA.

No Downloads

Total views

27,885

On SlideShare

0

From Embeds

0

Number of Embeds

41

Shares

0

Downloads

673

Comments

0

Likes

19

No embeds

No notes for slide

- 1. Classification with Naïve Bayes<br />A Deep Dive into Apache Mahout<br />
- 2. Today’s speaker – Josh Patterson<br />josh@cloudera.com / twitter: @jpatanooga<br />Master’s Thesis: self-organizing mesh networks<br />Published in IAAI-09: TinyTermite: A Secure Routing Algorithm<br />Conceived, built, and led Hadoop integration for the openPDC project at TVA (Smartgrid stuff)<br />Led small team which designed classification techniques for time series and Map Reduce<br />Open source work at http://openpdc.codeplex.com<br />Now: Solutions Architect at Cloudera<br />2<br />
- 3. What is Classification?<br />Supervised Learning<br />We give the system a set of instances to learn from<br />System builds knowledge of some structure<br />Learns “concepts”<br />System can then classify new instances<br />
- 4. Supervised vs Unsupervised Learning<br />Supervised<br />Give system examples/instances of multiple concepts<br />System learns “concepts”<br />More “hands on”<br />Example: Naïve Bayes, Neural Nets<br />Unsupervised<br />Uses unlabled data<br />Builds joint density model<br />Example: k-means clustering<br />
- 5. Naïve Bayes<br />Called Naïve Bayes because its based on “Baye’sRule” and “naively” assumes independence given the label<br />It is only valid to multiply probabilities when the events are independent<br />Simplistic assumption in real life<br />Despite the name, Naïve works well on actual datasets<br />
- 6. Naïve Bayes Classifier<br />Simple probabilistic classifier based on <br />applying Baye’s theorem (from Bayesian statistics) <br />strong (naive) independence assumptions. <br />A more descriptive term for the underlying probability model would be “independent feature model".<br />
- 7. Naïve Bayes Classifier (2)<br />Assumes that the presence (or absence) of a particular feature of a class is unrelated to the presence (or absence) of any other feature. <br />Example: <br />a fruit may be considered to be an apple if it is red, round, and about 4" in diameter. <br />Even if these features depend on each other or upon the existence of the other features, a naive Bayes classifier considers all of these properties to independently contribute to the probability that this fruit is an apple.<br />
- 8. A Little Bit o’ Theory<br />
- 9. Condensing Meaning<br />To train our system we need<br />Total number input training instances (count)<br />Counts tuples: <br />{attributen,outcomeo,valuem} <br />Total counts of each outcomeo<br />{outcome-count}<br />To Calculate each Pr[En|H]<br />({attributen,outcomeo,valuem} / {outcome-count} )<br />…From the Vapor of That Last Big Equation<br />
- 10. A Real Example From Witten, et al<br />
- 11. Enter Apache Mahout<br />What is it?<br />Apache Mahout is a scalable machine learning library that supports large data sets<br />What Are the Major Algorithm Type?<br />Classification<br />Recommendation<br />Clustering<br />http://mahout.apache.org/<br />
- 12. Mahout Algorithms<br />
- 13. Naïve Bayes and Text<br />Naive Bayes does not model text well. <br />“Tackling the Poor Assumptions of Naive Bayes Text Classifiers”<br />http://people.csail.mit.edu/jrennie/papers/icml03-nb.pdf<br />Mahout does some modifications based around TF-IDF scoring (Next Slide)<br />Includes two other pre-processing steps, common for information retrieval but not for Naive Bayes classification<br />
- 14. High Level Algorithm<br />For Each Feature(word) in each Doc:<br />Calc: “Weight Normalized Tf-Idf”<br />for a given feature in a label is the Tf-idf calculated using standard idf multiplied by the Weight Normalized Tf<br />We calculate the sum of W-N-Tf-idf for all the features in a label called Sigma_k, and alpha_i == 1.0<br />Weight = Log [ ( W-N-Tf-Idf + alpha_i ) / ( Sigma_k + N ) ]<br />
- 15. BayesDriver Training Workflow<br />Naïve Bayes Training MapReduce Workflow in Mahout<br />
- 16. Logical Classification Process<br />Gather, Clean, and Examine the Training Data<br />Really get to know your data!<br />Train the Classifier, allowing the system to “Learn” the “Concepts”<br />But not “overfit” to this specific training data set<br />Classify New Unseen Instances<br />With Naïve Bayes we’ll calculate the probabilities of each class wrt this instance<br />
- 17. How Is Classification Done?<br />Sequentially or via Map Reduce<br />TestClassifier.java<br />Creates ClassifierContext<br />For Each File in Dir<br />For Each Line<br />Break line into map of tokens<br />Feed array of words to Classifier engine for new classification/label<br />Collect classifications as output<br />
- 18. A Quick Note About Training Data…<br />Your classifier can only be as good as the training data lets it be…<br />If you don’t do good data prep, everything will perform poorly<br />Data collection and pre-processing takes the bulk of the time<br />
- 19. Enough Math, Run the Code<br />Download and install Mahout<br />http://www.apache.org<br />Run 20Newsgroups Example<br />https://cwiki.apache.org/confluence/display/MAHOUT/Twenty+Newsgroups<br />Uses Naïve Bayes Classification<br />Download and extract 20news-bydate.tar.gz from the 20newsgroups dataset<br />
- 20. Generate Test and Train Dataset<br />Training Dataset:<br />mahout org.apache.mahout.classifier.bayes.PrepareTwentyNewsgroups <br /> -p examples/bin/work/20news-bydate/20news-bydate-train <br /> -o examples/bin/work/20news-bydate/bayes-train-input <br /> -a org.apache.mahout.vectorizer.DefaultAnalyzer<br /> -c UTF-8<br />Test Dataset:<br />mahout org.apache.mahout.classifier.bayes.PrepareTwentyNewsgroups <br /> -p examples/bin/work/20news-bydate/20news-bydate-test <br /> -o examples/bin/work/20news-bydate/bayes-test-input <br /> -a org.apache.mahout.vectorizer.DefaultAnalyzer <br /> -c UTF-8<br />
- 21. Train and Test Classifier<br />Train:<br />$MAHOUT_HOME/bin/mahout trainclassifier <br /> -i 20news-input/bayes-train-input <br /> -o newsmodel <br /> -type bayes <br /> -ng 3 <br /> -source hdfs<br />Test:<br />$MAHOUT_HOME/bin/mahout testclassifier <br /> -m newsmodel <br /> -d 20news-input <br /> -type bayes <br /> -ng 3 <br /> -source hdfs <br /> -method mapreduce<br />
- 22. Other Use Cases<br />Predictive Analytics<br />You’ll hear this term a lot in the field, especially in the context of SAS<br />General Supervised Learning Classification<br />We can recognize a lot of things with practice<br />And lots of tuning!<br />Document Classification<br />Sentiment Analysis<br />
- 23. Questions?<br />We’re Hiring!<br />Cloudera’sDistro of Apache Hadoop:<br />http://www.cloudera.com<br />Resources<br />“Tackling the Poor Assumptions of Naive Bayes Text Classifiers”<br />http://people.csail.mit.edu/jrennie/papers/icml03-nb.pdf<br />

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment