1 / 48

Mining di dati web

Mining di dati web. Classificazioni di Documenti Web Fondamenti di Classificazione e Naive Bayes A.A 2006/2007. Categorization / Classification. Given: A description of an instance, x  X , where X is the instance language or instance space . E.g: how to represent text documents.

arich
Télécharger la présentation

Mining di dati web

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mining di dati web Classificazioni di Documenti Web Fondamenti di Classificazione e Naive Bayes A.A 2006/2007

  2. Categorization / Classification • Given: • A description of an instance, xX, where X is the instance language or instance space. • E.g: 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.

  3. Classification Task • Input: a training set of tuples, each labeled with one class label • Output: a model (classifier) that assigns a class label to each tuple based on the other attributes • The model can be used to predict the class of new tuples, for which the class label is missing or unknown

  4. What is Classification • Data classification is a two-step process • first step: a model is built describing a predetermined set of data classes or concepts. • second step: the model is used for classification. • Each tuple is assumed to belong to a predefined class, as determined by one of the attributes, called the class label attribute. • Data tuples are also referred to as samples, examples, or objects.

  5. Train and test • The tuples (examples, samples) are divided into training set + test set • Classification model is built in two steps: • training - build the model from the training set • test - check the accuracy of the model using test set

  6. Train and test • Kind of models: • if - then rules • logical formulae • decision trees • Accuracy of models: • the known class of test samples is matched against the class predicted by the model • accuracy rate = % of test set samples correctly classified by the model

  7. Training step Classification algorithm training data Classifier (model) if age < 31 or Car Type =Sports then Risk = High

  8. Test Step Classifier (model) test data

  9. Classification (Prediction) Classifier (model) new data

  10. Classification vs. Prediction • There are two forms of data analysis that can be used to extract models describing data classes or to predict future data trends: • classification: predict categorical labels • prediction: models continuous-valued functions

  11. Comparing Classification Methods (1) • Predictive accuracy: this refers to the ability of the model to correctly predict the class label of new or previously unseen data • Speed: this refers to the computation costs involved in generating and using the model • Robustness: this is the ability of the model to make correct predictions given noisy data or data with missing values

  12. Comparing Classification Methods (2) • Scalability: this refers to the ability to construct the model efficiently given large amount of data • Interpretability: this refers to the level of understanding and insight that is provided by the model • Simplicity: • decision tree size • rule compactness • Domain-dependent quality indicators

  13. Problem Formulation • Given records in a database with a class label - find a model for each class. Age < 31 Car Type is sports High High Low

  14. Classifier Accuracy • The accuracy of a classifier on a given test set of samples is defined as the percentage of test samples correctly classified by the classifier, and it measures the overall performance of the classifier. • Note that the accuracy of the classifier is not estimated on the training dataset, since it would not be a good indicator of the future accuracy on new data. • The reason is that the classifier generated from the training dataset tends to overfit the training data, and any estimate of the classifier's accuracy based on that data will be overoptimistic.

  15. Classifier Accuracy • In other words, the classifier is more accurate on the data that was used to train the classifier, but very likely it will be less accurate on independent set of data. • To predict the accuracy of the classifier on new data, we need to asses its accuracy on an independent dataset that played no part in the formation of the classifier. • This dataset is called the test set • It is important to note that the test dataset should not to be used in any way to built the classifier.

  16. Classifier Accuracy • There are several methods for estimating classifier accuracy. The choice of a method depends on the amount of sample data available for training and testing. • If there are a lot of sample data, then the following simple holdoutmethod is usually applied. • The given set of samples is randomly partitioned into two independent sets, a training set and a test set (typically, 70% of the data is used for training, and the remaining 30% is used for testing) • Provided that both sets of samples are representative, the accuracy of the classifier on the test set will give a good indication of accuracy on new data.

  17. Classifier Accuracy • In general, it is difficult to say whether a given set of samples is representative or not, but at least we may ensure that the random sampling of the data set is done in such a way that the class distribution of samples in both training and test set is approximately the same as that in the initial data set. • This procedure is called stratification

  18. Testing - Large Datasets Available examples 30% 70% Divide randomly Training Set Test Set used to develop one model check accuracy

  19. Classifier Accuracy • If the amount of data for training and testing is limited, the problem is how to use this limited amount of data for training to get a good classifier and for testing to obtain a correct estimation of the classifier accuracy? • The standard and very common technique of measuring the accuracy of a classifier when the amount of data is limited is k-fold cross-validation • In k-fold cross-validation, the initial set of samples is randomly partitioned into k approximately equal mutually exclusive subsets, called folds, S_1, S_2, ..., S_k.

  20. Classifier Accuracy • Training and testing is performed k times. At each iteration, one fold is used for testing while remainder k-1folds are used for training. So, at the end, each fold has been used exactly once for testing and k-1 for training. • The accuracy estimate is the overall number of correct classifications from k iterations divided by the total number of samples N in the initial dataset. • Often, the k-fold cross-validation technique is combined with stratification and is called stratified k-fold cross-validation.

  21. Testing - Small Datasets * cross-validation Repeat 10 times Available examples 10% 90% Training Set Test Set used to develop 10 different models check accuracy

  22. Classifier Accuracy • There are many other methods of estimating classifier accuracy on a particular dataset • Two popular methods are leave-one-out cross-validation and the bootstrapping • Leave-one-out cross-validation is simply N-fold cross-validation, where N is the number of samples in the initial dataset • At each iteration, a single sample from the dataset is left out for testing, and remaining samples are used for training. The result of testing is either success or failure. • The results of all N evaluations, one for each sample from the dataset, are averaged, and that average represents the final accuracy estimate.

  23. Classifier Accuracy • Bootstrappingis based on the sampling with replacement • The initial dataset is sampled N times, where N is the total number of samples in the dataset, with replacement, to form another set of N samples for training. • Since some samples in this new "set" will be repeated, so it means that some samples from the initial dataset will not appear in this training set. These samples will form a test set. • Both mentioned estimation methods are interesting especially for estimating classifier accuracy for small datasets. In practice, the standard and most popular technique of estimating a classifier accuracy is stratified tenfold cross-validation

  24. 85% of all email!! Text Classification This concerns you as a patient. Our medical records indicate you have had a history of illness. We are now encouraging all our patients to use this highly effective and safe solution. Proven worldwide, feel free to read the many reports on our site from the BBC & ABC News. We highly recommend you try this Anti-Microbial Peptide as soon as possible since its world supply is limited. The results will show quickly. Regards, http://www.superbiograde.us/bkhog/

  25. 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

  26. Methods (1) • Manual 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, … • Commercial systems have complex query languages (everything in IR query languages + accumulators)

  27. Methods (2) • Supervised learning of document-label assignment function: Autonomy, Kana, MSN, Verity, … • Naive Bayes (simple, common method) • k-Nearest Neighbors (simple, powerful) • Support-vector machines (new, more powerful) • … plus many other methods • No free lunch: requires hand-classified training data • But can be built (and refined) by amateurs

  28. 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.

  29. Bayes’ Rule

  30. Maximum a posteriori Hypothesis

  31. Maximum likelihood Hypothesis If all hypotheses are a priori equally likely,we only need to consider the P(D|h) term:

  32. Naive Bayes Classifiers Task: Classify a new instance based on a tuple of attribute values

  33. Naïve Bayes Classifier: Assumptions • P(cj) • Can be estimated from the frequency of classes in the training examples. • P(x1,x2,…,xn|cj) • Need very, very large number of training examples  Conditional Independence Assumption: Assume that the probability of observing the conjunction of attributes is equal to the product of the individual probabilities.

  34. Flu X1 X2 X3 X4 X5 runnynose sinus cough fever muscle-ache The Naïve Bayes Classifier • Conditional Independence Assumption: features are independent of each other given the class:

  35. C X1 X2 X3 X4 X5 X6 Learning the Model • Common practice:maximum likelihood • simply use the frequencies in the data

  36. 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

  37. Text Classification Algorithms: Learning • From training corpus, extract Vocabulary • Calculate required P(cj)and P(xk | cj)terms • For each cj in Cdo • docsjsubset of documents for which the target class is cj • Textj single document containing all docsj • for each word xkin Vocabulary • nk number of occurrences ofxkin Textj

  38. Text Classification Algorithms: Classifying • positions  all word positions in current document which contain tokens found in Vocabulary • Return cNB, where

  39. Naïve Bayes Posterior Probabilities • Classification results of naïve Bayes (the class with maximum posterior probability) are usually fairly accurate. • However, due to the inadequacy of the conditional independence assumption, the actual posterior-probability numerical estimates are not. • Output probabilities are generally very close to 0 or 1.

  40. Feature selection via Mutual Information • We might not want to use all words, but just reliable, good discriminators • In training set, choose k words which best discriminate the categories. • One way is in terms of Mutual Information: • For each word w and each category c

  41. Other Approaches to Feature Selection • T-TEST • CHI SQUARE • TF/IDF (CFR. IR lectures) • Yang & Pedersen 1997: eliminating features leads to improved performance

  42. 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 Robust to Irrelevant Features Irrelevant Features cancel each other without affecting results Instead Decision Trees & Nearest-Neighbor methods can heavily suffer from this. • Very good in Domains with many equally important features Decision Trees suffer from fragmentation in such cases – especially if little data • 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 • Handles Missing Values

  43. 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

  44. K-Nearest Neighbor Classifiers • Nearest neighbor classifier belongs to instance-based learning methods. • Instance-based learning methods differ from other classification methods discussed earlier in that they do not build a classifier until a new unknown sample needs to be classified. • Each training sample is described by n-dimensional vector representing a point in an n-dimensional space called pattern space. When a new unknown sample has to be classified, a distance function is used to determine a member of the training set which is closest to the unknown sample.

  45. K-Nearest Neighbor Classifiers • Once the nearest training sample is located in the pattern space, its class label is assigned to the unknown sample. • The main drawback of this approach is that it is very sensitive to noisy training samples. • The common solution to this problem is to adopt the k-nearest neighbor strategy. • When a new unknown sample has to be classified, the classifier searches the pattern space for the k training samples which are closest to the unknown sample. These k training samples are called the k "nearest neighbors" of the unknown sample andthe most common class label among k "nearest neighbors" is assigned to the unknown sample. • To find the k "nearest neighbors" of the unknown sample a multidimensional index is used (e.g. R-tree, Pyramid tree, etc.).

  46. K-Nearest Neighbor Classifiers • Two different issues need to be addressed regarding k-nearest neighbor method: • the distance function, and • the transformation from a sample to a point in the pattern space. • The first issue is to define the distance function. If the attributes are numeric, most k-nearest neighbor classifiers use Euclidean distance. • Instead of the Euclidean distance, we may also apply other distance metrics like Manhattan distance, maximum ofdimensions, or Minkowski distance.

  47. K-Nearest Neighbor Classifiers • The second issue is how to transform a sample to a point in the pattern space. • Note that different attributes may have different scales and units, and different variability. Thus, if the distance metric is used directly, the effects of some attributes might be dominated by other attributes that have larger scale or higher variability. • A simple solution to this problem is to weight the various attributes. One common approach is to normalize all attribute values into the range [0, 1].

  48. 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

More Related