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.
2014年10月27日 星期一
2014年10月17日 星期五
blog3 something about nltk
nltk stands for Natural Language Toolkit, from it's name we can know it will be of great help for natural language processing, so I am gonna write something about how to use it.
Firstly, make sure you have python installed on your computer, then you need to install some libraries under your python module to use nltk.
Step1:
install Numpy, go to numpy and download the package corresponds to your python version and operating system, then just click next, you don't need to set any variables, numpy will find python itself.
Step2:
install NLTK, go to nltk, download the right package and install it.
Step3:
install PyYAML, go to PyYAML, download the right package and install it.
Step4:
download all the data libraries of nltk, in the IDLE interface, input command like this:
Firstly, make sure you have python installed on your computer, then you need to install some libraries under your python module to use nltk.
Step1:
install Numpy, go to numpy and download the package corresponds to your python version and operating system, then just click next, you don't need to set any variables, numpy will find python itself.
Step2:
install NLTK, go to nltk, download the right package and install it.
Step3:
install PyYAML, go to PyYAML, download the right package and install it.
Step4:
download all the data libraries of nltk, in the IDLE interface, input command like this:
then you will see a window like this:
select all and click download, it will take some time to complete the downloading process, just be patient, after downloading, window will be like this:
now you can use nltk,just refer to the documentation and type some commands and try it out, an example will be like this:
see? you can break a string easily and you can get the Bi-grams of a string easily, it's pretty efficient, so just use nltk, it will save you a lot of trouble, you don't need to think about the algorithms yourself!
2014年10月15日 星期三
blog2 something about python
We need to write python in Assignment1, so I want to write something about python.
There are some structures that we can use in python. The first one is list, this is a very common structure, the elements of list can be dulplicate, so here is an example:
we create a list from the string and list includes all words of the string. The second is set, set is different from list in that the elemenst of set can not be dulplicate, so here is the example:
we can see that the duplicate words are not in the set, so set is very useful if you want to get a list that is not dulplicate. The third structure is dictionary or map, every element has a key and a value. we can create a simple dictionary like this:
so we can see that dictionary is something like a relation structure, every key is related a value.
Now I want to talk something about sorting, a method called sorted is very useful, now let's take a loot at it's basic function:
we can see that sorted will sort the element in list and return a new sorted list, but the function of sorted is much more powerful than this, suppose we have a dictionary and we want to sort it by key firstly, the sort it by value, we can do like this:
finally we get the list that has been sorted twice, first by key, then by value, but we have imported a library called operator, also, see the code that we used to gererate the original list? that is a very useful method, do a lot of things by a little code.
Ok, knowledge above is enough to solve the assignment1, but you need to design the simple algorithm yourself, I really did it using the methods above!
訂閱:
文章 (Atom)










