Text classification and Naive bayes

hierarchical text classification and evaluation and text classification and sentiment analysis
WilliamsMcmahon Profile Pic
WilliamsMcmahon,United States,Professional
Published Date:20-07-2017
Your Website URL(Optional)
Introduction to Information Retrieval Introduction to Information Retrieval Text Classification; Vector space classification www.ThesisScientist.com 1Introduction to Information Retrieval Recap: Naïve Bayes classifiers  Classify based on prior weight of class and conditional parameter for what each word says:   cargmax log P(c ) log P(x c )   NB j i j cC   j  i positions   Training is done by counting and dividing: T N c x c j k j P(x c ) P(c ) k j j T N  c x  j i xV i  Don’t forget to smooth www.ThesisScientist.com 2  Introduction to Information Retrieval The rest of text classification  Today:  Vector space methods for Text Classification  Vector space classification using centroids (Rocchio)  K Nearest Neighbors  Decision boundaries, linear and nonlinear classifiers  Dealing with more than 2 classes  Later in the course  More text classification  Support Vector Machines  Text-specific issues in classification www.ThesisScientist.com 3Introduction to Information Retrieval Sec.14.1 Recall: Vector Space Representation  Each document is a vector, one component for each term (= word).  Normally normalize vectors to unit length.  High-dimensional vector space:  Terms are axes  10,000+ dimensions, or even 100,000+  Docs are vectors in this space  How can we do classification in this space? www.ThesisScientist.com 4Introduction to Information Retrieval Sec.14.1 Classification Using Vector Spaces  As before, the training set is a set of documents, each labeled with its class (e.g., topic)  In vector space classification, this set corresponds to a labeled set of points (or, equivalently, vectors) in the vector space  Premise 1: Documents in the same class form a contiguous region of space  Premise 2: Documents from different classes don’t overlap (much)  We define surfaces to delineate classes in the space www.ThesisScientist.com 5Introduction to Information Retrieval Sec.14.1 Test Document = Government Is this similarity hypothesis true in general? Government Science Arts Our main topic today is how to find good separators www.ThesisScientist.com 8Introduction to Information Retrieval Sec.14.1 Aside: 2D/3D graphs can be misleading www.ThesisScientist.com 9Introduction to Information Retrieval Sec.14.2 Using Rocchio for text classification  Relevance feedback methods can be adapted for text categorization  As noted before, relevance feedback can be viewed as 2-class classification  Relevant vs. nonrelevant documents  Use standard tf-idf weighted vectors to represent text documents  For training documents in each category, compute a prototype vector by summing the vectors of the training documents in the category.  Prototype = centroid of members of class  Assign test documents to the category with the closest prototype vector based on cosine similarity. www.ThesisScientist.com 10Introduction to Information Retrieval Sec.14.2 Illustration of Rocchio Text Categorization www.ThesisScientist.com 11Introduction to Information Retrieval Sec.14.2 Definition of centroid  1  (c) v (d)  D c dD c   Where D is the set of all documents that belong to c class c and v(d) is the vector space representation of d.   Note that centroid will in general not be a unit vector even when the inputs are unit vectors. www.ThesisScientist.com 12Introduction to Information Retrieval Sec.14.2 Rocchio Properties  Forms a simple generalization of the examples in each class (a prototype).  Prototype vector does not need to be averaged or otherwise normalized for length since cosine similarity is insensitive to vector length.  Classification is based on similarity to class prototypes.  Does not guarantee classifications are consistent with the given training data. Why not? www.ThesisScientist.com 13Introduction to Information Retrieval Sec.14.2 Rocchio Anomaly  Prototype models have problems with polymorphic (disjunctive) categories. www.ThesisScientist.com 14Introduction to Information Retrieval Sec.14.2 Rocchio classification  Rocchio forms a simple representation for each class: the centroid/prototype  Classification is based on similarity to / distance from the prototype/centroid  It does not guarantee that classifications are consistent with the given training data  It is little used outside text classification  It has been used quite effectively for text classification  But in general worse than Naïve Bayes  Again, cheap to train and test documents www.ThesisScientist.com 15Introduction to Information Retrieval Sec.14.3 k Nearest Neighbor Classification  kNN = k Nearest Neighbor  To classify a document d into class c:  Define k-neighborhood N as k nearest neighbors of d  Count number of documents i in N that belong to c  Estimate P(cd) as i/k  Choose as class argmax P(cd) = majority class c www.ThesisScientist.com 16Introduction to Information Retrieval Sec.14.3 Example: k=6 (6NN) P(science )? Government Science Arts www.ThesisScientist.com 17Introduction to Information Retrieval Sec.14.3 Nearest-Neighbor Learning Algorithm  Learning is just storing the representations of the training examples in D.  Testing instance x (under 1NN):  Compute similarity between x and all examples in D.  Assign x the category of the most similar example in D.  Does not explicitly compute a generalization or category prototypes.  Also called:  Case-based learning  Memory-based learning  Lazy learning  Rationale of kNN: contiguity hypothesis www.ThesisScientist.com 18Introduction to Information Retrieval Sec.14.3 kNN Is Close to Optimal  Cover and Hart (1967)  Asymptotically, the error rate of 1-nearest-neighbor classification is less than twice the Bayes rate error rate of classifier knowing model that generated data  In particular, asymptotic error rate is 0 if Bayes rate is 0.  Assume: query point coincides with a training point.  Both query point and training point contribute error → 2 times Bayes rate www.ThesisScientist.com 19Introduction to Information Retrieval Sec.14.3 k Nearest Neighbor  Using only the closest example (1NN) to determine the class is subject to errors due to:  A single atypical example.  Noise (i.e., an error) in the category label of a single training example.  More robust alternative is to find the k most-similar examples and return the majority category of these k examples.  Value of k is typically odd to avoid ties; 3 and 5 are most common. www.ThesisScientist.com 20Introduction to Information Retrieval Sec.14.3 kNN decision boundaries Boundaries are in principle arbitrary surfaces – but usually polyhedra Government Science Arts kNN gives locally defined decision boundaries between classes – far away points do not influence each classification www.ThesisScientist.com 21 decision (unlike in Naïve Bayes, Rocchio, etc.)Introduction to Information Retrieval Sec.14.3 Similarity Metrics  Nearest neighbor method depends on a similarity (or distance) metric.  Simplest for continuous m-dimensional instance space is Euclidean distance.  Simplest for m-dimensional binary instance space is Hamming distance (number of feature values that differ).  For text, cosine similarity of tf.idf weighted vectors is typically most effective. www.ThesisScientist.com 22