2014年10月27日 星期一

blog 4 something about NaiveBayesClassifier

We have learned classification before and assignment2 is about classifire, so in this blog I am going to talk about NaiveBayesClassifier, this is the classifier we are going to use in assignment2, so firstly I will try the tutorial a little bit and have a feeling of the classifier, so below is the code:










lst is the training set, it is the original data you have, it has already been classified, we can see that 'apple' belongs to the category of 'news', 'gun' belongs to the category of 'news', ect, extFeaure is the most important element in the classification, because it determines the accuracy of the classifier, we can see that it is a function, determine what features to get from the data to use as the element to classify the data, extracted is the featured training set, it is used to train the BayesClassifier, after this, a classifier can be used by us to classify data, so here is the running result:







we can see that the data has been classified, but I don't think this classifier is good, because the feature function extFeature is too simple, I searched a book and found something about how to design the feature function.

So here is what has been said in the book:
1,Selecting relevant features and deciding how to encode them for a learning method can have an enormous impact on the learning method’s ability to extract a good model. Much of the interesting work in building a classifier is deciding what features might be relevant, and how we can represent them. Although it’s often possible to get decent performance by using a fairly simple and obvious set of features, there are usually significant gains to be had by using carefully constructed features based on a thorough understanding of the task at hand.
2,Typically, feature extractors are built through a process of trial-and-error, guided byintuitions about what information is relevant to the problem. It’s common to start witha “kitchen sink” approach, including all the features that you can think of, and thenchecking to see which features actually are helpful. 
3,there are usually limits to the number of features that you should use with a
given learning algorithm—if you provide too many features, then the algorithm will have a higher chance of relying on idiosyncrasies of your training data that don’t generalize well to new examples. This problem is known as overfitting, and can be especially problematic when working with small training sets.

So now we know the most useful way to determine the feature function is to understand the elements you are trying to classify.


28 則留言:

  1. You blog is the most interesting article I have ever read, and you explain the NaiveBayesClassifier with the help of python, I think you must pay a lot of time in the class, thanks for you sharing, I learnt a lot.

    回覆刪除
    回覆
    1. Thank you for your comment, I was trying to do the assignment 2 and I did not know how to design the extFeature function, then I found a book about doing NLP using python, it told me how to design the extFeature function, the book was really useful.

      刪除
  2. Thanks for your sharing about the NaiveBayesClassifier, which I was really confused with before. After reading this blog, I have solved some problems,

    回覆刪除
    回覆
    1. Thank you for your comment, extFeature function is the key to NaiveBayesClassifier, I was also very confused about this function before, then I found a book, I learned a lot about this function from the book.

      刪除
  3. Your blog helps me a lot on assignment2. We can just use this method to work out assigment2. I tried a lot for this assignment with python, but I cannot get the right answer. After reading your blog, I think I have some new idea with this assignment. Thanks for your sharing.

    回覆刪除
    回覆
    1. Thank you for your comment, I am very happy that my blog is useful to you.

      刪除
  4. 作者已經移除這則留言。

    回覆刪除
  5. test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment

    回覆刪除
  6. test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment

    回覆刪除
  7. test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment , test comment

    回覆刪除
  8. Thank you for your sharing. I didn't know exactly how to train a NaiveBayesClassifier before, but after read your blog, I know more about it.

    回覆刪除
  9. 作者已經移除這則留言。

    回覆刪除
  10. Cool. A great blog post for mapping what we learnt and how should we code them up.

    I have done something similar.

    Below is how I map terminologies in our lectures notes to NLTK implementations.

    What NLTK classifier calculating

    P(label | features) = P(label) * P(fname*=fval*|label)

    What we are calculating

    P(Category | Word)

    Mapping between our works and NLTK

    label === Category === C
    Word = feature1 * feature2 * ... = (fname1=fval1)*(fname2=fval2)*...

    回覆刪除
  11. Your blog is cool, wish I may refer to your blog when I have trouble in programming... :-)

    回覆刪除
  12. You have shared the process of the python programming which is very helpful for me to make a comparison of my programme with your programme.Learning from each other's programme is a good way to learn as well.Thanks a lot!

    回覆刪除
  13. The blog includes details how to implement a classifier. NLTK is a powerful tool for text processing, but hide algorithm details from users. Maybe more detail about Naive Bayes Classifier can be supplemented.

    回覆刪除
  14. awesome blog,before i read your blog, i do not understand how to use this NaiveBayesClassifier very claerly, now i think i can try to use this tool by myself. It's quite efficient and functional.

    回覆刪除
  15. 作者已經移除這則留言。

    回覆刪除
  16. Thanks for your sharing. When I do my assignment, it said too many features in it. After reading your blog, I know that there is limit to set the number of features. I have tried to revise my programme without overfitting. I think some of our classmates may face this problem during doing the assignment.

    回覆刪除
  17. The most difficult part in classification is defining a classifier whoich is deciding what features might be relevant. And as the same time, defining the feature vector is a not a trivial work and It could take a lot of time, but the trial-error approach sounds interesting.

    回覆刪除
  18. Good article. In my blog article http://chushingyee-iems5723.blogspot.hk/2014/11/data-sampling-and-overfitting.html, I elaborated a little bit more on the problem of overfitting. You may have a look if you are interested.

    回覆刪除
  19. Thanks for your sharing! Very practical content. I think NLTK is really a powerful library in natural language processing. The Naive Bayes Classifier is really interesting for me who is just a starter in studying document classification. :D

    回覆刪除
  20. your blog is quite full of computer technologies which is really useful for us to put into practice. in your expression, you introduce the naivebyesclassifier whch is taught by Rosanna, which was used in our second assignment. thanks for your sharing.

    回覆刪除