Naïve Bayes for Text Classification: Spam Detection

Slides:



Advertisements
Similar presentations
Naïve Bayes. Bayesian Reasoning Bayesian reasoning provides a probabilistic approach to inference. It is based on the assumption that the quantities of.
Advertisements

Naïve-Bayes Classifiers Business Intelligence for Managers.
CPSC 502, Lecture 15Slide 1 Introduction to Artificial Intelligence (AI) Computer Science cpsc502, Lecture 15 Nov, 1, 2011 Slide credit: C. Conati, S.
What is Statistical Modeling
Ai in game programming it university of copenhagen Statistical Learning Methods Marco Loog.
On feature distributional clustering for text categorization Bekkerman, El-Yaniv, Tishby and Winter The Technion. June, 27, 2001.
Learning for Text Categorization
Introduction to Information Retrieval Introduction to Information Retrieval Hinrich Schütze and Christina Lioma Lecture 13: Text Classification & Naive.
Bayes Rule How is this rule derived? Using Bayes rule for probabilistic inference: –P(Cause | Evidence): diagnostic probability –P(Evidence | Cause): causal.
1 Chapter 12 Probabilistic Reasoning and Bayesian Belief Networks.
Lecture 13-1: Text Classification & Naive Bayes
TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)
1 Learning Entity Specific Models Stefan Niculescu Carnegie Mellon University November, 2003.
1er. Escuela Red ProTIC - Tandil, de Abril, Bayesian Learning 5.1 Introduction –Bayesian learning algorithms calculate explicit probabilities.
Introduction to Bayesian Learning Ata Kaban School of Computer Science University of Birmingham.
Text Classification – Naive Bayes
CS276A Text Retrieval and Mining Lecture 11. Recap of the last lecture Probabilistic models in Information Retrieval Probability Ranking Principle Binary.
Naïve Bayes Classification Debapriyo Majumdar Data Mining – Fall 2014 Indian Statistical Institute Kolkata August 14, 2014.
Text Categorization Moshe Koppel Lecture 2: Naïve Bayes Slides based on Manning, Raghavan and Schutze.
CS Bayesian Learning1 Bayesian Learning. CS Bayesian Learning2 States, causes, hypotheses. Observations, effect, data. We need to reconcile.
Information extraction from bioinformatics related documents
Crash Course on Machine Learning
Advanced Multimedia Text Classification Tamara Berg.

Information Retrieval and Web Search Introduction to Text Classification (Note: slides in this set have been adapted from the course taught by Chris Manning.

Bayesian Networks. Male brain wiring Female brain wiring.
ITCS 6265 Information Retrieval and Web Mining Lecture 12: Text Classification; The Naïve Bayes algorithm.
CSCI 5417 Information Retrieval Systems Jim Martin Lecture 11 9/29/2011.
Text Classification, Active/Interactive learning.
How to classify reading passages into predefined categories ASH.
Naive Bayes Classifier
Spam Filtering. From: "" Subject: real estate is the only way... gem oalvgkay Anyone can buy real estate with no money down Stop paying rent TODAY ! There.
1 Statistical NLP: Lecture 9 Word Sense Disambiguation.
1 CS546: Machine Learning and Natural Language Discriminative vs Generative Classifiers This lecture is based on (Ng & Jordan, 02) paper and some slides.
Kansas State University Department of Computing and Information Sciences CIS 730: Introduction to Artificial Intelligence Lecture 25 Wednesday, 20 October.
Mining di dati web Classificazioni di Documenti Web Fondamenti di Classificazione e Naive Bayes A.A 2006/2007.
Text Feature Extraction. Text Classification Text classification has many applications –Spam detection –Automated tagging of streams of news articles,
Statistical NLP Winter 2009 Lecture 4: Text categorization through Naïve Bayes Roger Levy ありがとう to Chris Manning for slides.
Information Retrieval and Organisation Chapter 13 Text Classification and Naïve Bayes Dell Zhang Birkbeck, University of London.
Empirical Research Methods in Computer Science Lecture 7 November 30, 2005 Noah Smith.
WEB BAR 2004 Advanced Retrieval and Web Mining Lecture 15.
Computing & Information Sciences Kansas State University Wednesday, 22 Oct 2008CIS 530 / 730: Artificial Intelligence Lecture 22 of 42 Wednesday, 22 October.
1 Bayesian Methods. 2 Naïve Bayes New data point to classify: X=(x 1,x 2,…x m ) Strategy: – Calculate P(C i /X) for each class C i. – Select C i for which.
Bayesian Classification. Bayesian Classification: Why? A statistical classifier: performs probabilistic prediction, i.e., predicts class membership probabilities.
Classification Techniques: Bayesian Classification
CHAPTER 6 Naive Bayes Models for Classification. QUESTION????
Active learning Haidong Shi, Nanyi Zeng Nov,12,2008.
Introduction to Information Retrieval Introduction to Information Retrieval CS276: Information Retrieval and Web Search Christopher Manning and Prabhakar.
Information Retrieval and Web Search Text classification Instructor: Rada Mihalcea.
Information Retrieval Lecture 4 Introduction to Information Retrieval (Manning et al. 2007) Chapter 13 For the MSc Computer Science Programme Dell Zhang.
Statistical NLP Winter 2008 Lecture 4: Text classification through Naïve Bayes Roger Levy ありがとう to Chris Manning for slides.
Machine Learning Concept Learning General-to Specific Ordering
Web Search and Text Mining Lecture 17: Naïve BayesText Classification.
Text Classification and Naïve Bayes (Modified from Stanford CS276 slides on Lecture 10: Text Classification; The Naïve Bayes algorithm)
Naïve Bayes Classifier April 25 th, Classification Methods (1) Manual classification Used by Yahoo!, Looksmart, about.com, ODP Very accurate when.
BAYESIAN LEARNING. 2 Bayesian Classifiers Bayesian classifiers are statistical classifiers, and are based on Bayes theorem They can calculate the probability.
Introduction to Information Retrieval Introduction to Information Retrieval Lecture 15: Text Classification & Naive Bayes 1.
Naive Bayes Classifier. REVIEW: Bayesian Methods Our focus this lecture: – Learning and classification methods based on probability theory. Bayes theorem.
CS276 Information Retrieval and Web Search Lecture 12: Naïve BayesText Classification.
CS276B Text Information Retrieval, Mining, and Exploitation Lecture 4 Text Categorization I Introduction and Naive Bayes Jan 21, 2003.
MIRA, SVM, k-NN Lirong Xia. MIRA, SVM, k-NN Lirong Xia.
Naive Bayes Classifier
Lecture 15: Text Classification & Naive Bayes
Data Mining Lecture 11.
Classification Techniques: Bayesian Classification
Where did we stop? The Bayes decision rule guarantees an optimal classification… … But it requires the knowledge of P(ci|x) (or p(x|ci) and P(ci)) We.
Information Retrieval
Naive Bayes Classifier
MIRA, SVM, k-NN Lirong Xia. MIRA, SVM, k-NN Lirong Xia.
Presentation transcript:

Naïve Bayes for Text Classification: Spam Detection CIS 391 – Introduction to Artificial Intelligence (adapted from slides by Massimo Poesio which were adapted from slides by Chris Manning)

Is this spam? From: "" <takworlld@hotmail.com> Subject: real estate is the only way... gem oalvgkay Anyone can buy real estate with no money down Stop paying rent TODAY ! There is no need to spend hundreds or even thousands for similar courses I am 22 years old and I have already purchased 6 properties using the methods outlined in this truly INCREDIBLE ebook. Change your life NOW ! ================================================= Click Below to order: http://www.wholesaledaily.com/sales/nmd.htm CIS 391- Intro to AI

Categorization/Classification Given: A description of an instance, xX, where X is the instance language or instance space. Issue: how to represent text documents. A fixed set of categories: C = {c1, c2,…, cn} Determine: The category of x: c(x)C, where c(x) is a categorization function whose domain is X and whose range is C. We want to know how to build categorization functions (“classifiers”). CIS 391- Intro to AI

Document Classification “planning language proof intelligence” Test Data: (AI) (Programming) (HCI) Classes: ML Planning Semantics Garb.Coll. Multimedia GUI Training Data: learning intelligence algorithm reinforcement network... planning temporal reasoning plan language... programming semantics language proof... garbage collection memory optimization region... ... ... CIS 391- Intro to AI

A Graphical View of Text Classification NLP Graphics AI Theory Arch. CIS 391- Intro to AI

EXAMPLES OF TEXT CATEGORIZATION LABELS=BINARY “spam” / “not spam” LABELS=TOPICS “finance” / “sports” / “asia” LABELS=OPINION “like” / “hate” / “neutral” LABELS=AUTHOR “Shakespeare” / “Marlowe” / “Ben Jonson” The Federalist papers CIS 391- Intro to AI

Methods (1) Manual classification Automatic document classification Used by Yahoo!, Looksmart, about.com, ODP, Medline very accurate when job is done by experts consistent when the problem size and team is small difficult and expensive to scale Automatic document classification Hand-coded rule-based systems Reuters, CIA, Verity, … E.g., assign category if document contains a given boolean combination of words Commercial systems have complex query languages (everything in IR query languages + accumulators) Accuracy is often very high if a rule has been carefully refined over time by a subject expert Building and maintaining these rules is expensive CIS 391- Intro to AI

Classification Methods (2) Supervised learning of a document-label assignment function Many systems partly rely on machine learning (Autonomy, MSN, Verity, Enkata, Yahoo!, …) k-Nearest Neighbors (simple, powerful) Naive Bayes (simple, common method) Support-vector machines (new, more powerful) … plus many other methods No free lunch: requires hand-classified training data But data can be built up (and refined) by amateurs Note that many commercial systems use a mixture of methods CIS 391- Intro to AI

Bayesian Methods Learning and classification methods based on probability theory Bayes theorem plays a critical role Build a generative model that approximates how data is produced Uses prior probability of each category given no information about an item. Categorization produces a posterior probability distribution over the possible categories given a description of an item. CIS 391- Intro to AI

Bayes’ Rule once more CIS 391- Intro to AI

Maximum a posteriori Hypothesis As P(D) is constant CIS 391- Intro to AI

Maximum likelihood Hypothesis If all hypotheses are a priori equally likely, we only need to consider the P(D|c) term: CIS 391- Intro to AI

Naive Bayes Classifiers Task: Classify a new instance D based on a tuple of attribute values into one of the classes cj  C CIS 391- Intro to AI

Naïve Bayes Classifier: Assumption P(cj) Can be estimated from the frequency of classes in the training examples. P(x1,x2,…,xn|cj) O(|X|n•|C|) parameters Could only be estimated if a very, very large number of training examples was available. Naïve Bayes Conditional Independence Assumption: Assume that the probability of observing the conjunction of attributes is equal to the product of the individual probabilities P(xi|cj). CIS 391- Intro to AI

The Naïve Bayes Classifier Flu X1 X2 X5 X3 X4 fever sinus cough runnynose muscle-ache Conditional Independence Assumption: features are independent of each other given the class: This model is appropriate for binary variables CIS 391- Intro to AI

Learning the Model First attempt: maximum likelihood estimates C X1 X2 simply use the frequencies in the data (+ “smoothing”) CIS 391- Intro to AI

Problem with Max Likelihood Flu X1 X2 X5 X3 X4 fever sinus cough runnynose muscle-ache What if we have seen no training cases where patient had no flu and muscle aches? Zero probabilities cannot be conditioned away, no matter the other evidence! CIS 391- Intro to AI

Smoothing to Avoid Overfitting # of values of Xi overall fraction in data where Xi=xi,k Somewhat more subtle version extent of “smoothing” CIS 391- Intro to AI

Using Naive Bayes Classifiers to Classify Text: Basic method Attributes are text positions, values are words. Still too many possibilities Assume that classification is independent of the positions of the words Use same parameters for each position Result is bag of words model CIS 391- Intro to AI

Naïve Bayes: Learning From training corpus, extract Vocabulary Calculate required P(cj) and P(xk | cj) terms For each cj in C do docsj  subset of documents for which the target class is cj For each word xk in Vocabulary nk  number of occurrences of xk in all docsj CIS 391- Intro to AI

Naïve Bayes: Classifying positions  all word positions in current document which contain tokens found in Vocabulary Return cNB, where CIS 391- Intro to AI

PANTEL AND LIN: SPAMCOP Uses a Naïve Bayes classifier M is spam if P(Spam|M) > P(NonSpam|M) Method Tokenize message using Porter Stemmer Estimate P(W|C) using m-estimate (a form of smoothing) Remove words that do not satisfy certain conditions Train: 160 spams, 466 non-spams Test: 277 spams, 346 non-spams Results: ERROR RATE of 4.33% Worse results using trigrams CIS 391- Intro to AI

Naive Bayes is Not So Naive Naïve Bayes: First and Second place in KDD-CUP 97 competition, among 16 (then) state of the art algorithms Goal: Financial services industry direct mail response prediction model: Predict if the recipient of mail will actually respond to the advertisement – 750,000 records. A good dependable baseline for text classification But not the best! Optimal if the Independence Assumptions hold: If assumed independence is correct, then it is the Bayes Optimal Classifier for problem Very Fast: Learning with one pass over the data; Testing linear in the number of attributes, and document collection size Low Storage requirements CIS 391- Intro to AI

REFERENCES Mosteller, F., & Wallace, D. L. (1984). Applied Bayesian and Classical Inference: the Case of the Federalist Papers (2nd ed.). New York: Springer-Verlag. P. Pantel and D. Lin, 1998. “SPAMCOP: A Spam classification and organization program”, In Proc. Of the 1998 workshop on learning for text categorization, AAAI Sebastiani, F., 2002, “Machine Learning in Automated Text Categorization”, ACM Computing Surveys, 34(1), 1-47 CIS 391- Intro to AI

Some additional practical details that we won’t get to in class….

Underflow Prevention Multiplying lots of probabilities, which are between 0 and 1 by definition, can result in floating-point underflow. Since log(xy) = log(x) + log(y), it is better to perform all computations by summing logs of probabilities rather than multiplying probabilities. Class with highest final un-normalized log probability score is still the most probable. CIS 391- Intro to AI

Feature selection via Mutual Information We might not want to use all words, but just reliable, good discriminating terms In training set, choose k words which best discriminate the categories. One way is using terms with maximal Mutual Information with the classes: For each word w and each category c CIS 391- Intro to AI

Feature selection via MI (contd.) For each category we build a list of k most discriminating terms. For example (on 20 Newsgroups): sci.electronics: circuit, voltage, amp, ground, copy, battery, electronics, cooling, … rec.autos: car, cars, engine, ford, dealer, mustang, oil, collision, autos, tires, toyota, … Greedy: does not account for correlations between terms CIS 391- Intro to AI

Feature Selection Mutual Information Commonest terms: Clear information-theoretic interpretation May select rare uninformative terms Commonest terms: No particular foundation In practice often is 90% as good Other methods: Chi-square, etc…. CIS 391- Intro to AI