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.


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:

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!














2014年9月21日 星期日

Blog 1 on social media analytics

After three classes of social media analytics, I found that I am beginning to love this course, I am beginning to understand what this course is about and what I will get from this class, I can say that this course will be very useful in the practical world and the contents discussed in this course is going to be very popular.

My understanding of this course now is very basic, I think it is about collecting data, analysing data and getting conclusions, it is about doing analysis on social media, so firstly we need to get data from social media, nowadays most social media are on the web, so we need to get data from the web, a web crawler will be very useful, actually many companies like facebook, twitter are providing open APIS for developers, so getting data from them will be much easier, secondly we need great algorithm to analyse the data, until now, I have learned one method, that is NPL(natural language processing), I think it is very interesting, I am looking forward to realize it in python, the last step is to get a conclusion, what can you get from the analysing result, mostly this is the ultimate goal of the project, like predicting a stock.

Why did I say contents in this course is very useful in the practical world and it is going to be very popular? if you look at all the products nowadays, no matter what kind of products, people are putting a lot of attention on user experience, the design, the interation,for example, a cellphone, people are not just focusing on whether the function is good or not, of course, the function needs to be good, but more importantly, they are talking about the design of the cellphone, does it look good? it it easy to use? how about the user interface and the interaction? if you want to improve these, you need to do analysis on your user, pay attention to what are they talking about on your products, find out what do they like, here, social media analytics is a very useful tool, I think methods like NPL are very useful, later I will give an example of this.

I happened to know a company and I think their business model is a very good example of social media analytics. This company is collecting data from websites like Qunar.Com everyday, what kind of data? those data related to the user's feedback like comments, I think you have posted comments on one product or service before, once they got the comments, they will do analysis on these data, and their goal is to find out why user choose this service, for example, let's say a hotel, they will find out why people choose this hotel in details, which aspect attracts them most, what are the advantages and disadvantages, what can be improved, then they will sell these data to that hotel, so the hotel know what is good about their hotel and what need to improved, if you do not do analysis, it is very hard to know how to improve your service, if you just look at the comments, that is a lot of work, but here, social media analytics provides us a very good tool.

At last, I think the key in learning social media analytics is to know how to do analysis and what it can do.