How to represent text for classification in weka?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 03:34:16

问题


Can you please let me know how to represent attribute or class for text classification in weka. By using what attribute can I do classification? word frequency or just word? What would be possible structure of ARFF format? Can you give me several lines of example of that structure?

Thank you very much in advance.


回答1:


One of the easiest alternatives is to start with an ARFF file for a two class problem like:

@relation corpus 

@attribute text string
@attribute class {pos,neg}

@data
'long text with words ... ',pos

The text is represented as a String type and the class is a nominal with two values.

Then you could apply two filters:

  1. StringToWordVector that transforms the texts into a word vector representation. The filter uses an attribute for each word. You can tweak parameters to choose binary/frequency representation, stemming or stopwords. The best representation depends on the problem. If text are not long, usually binary representation is enough.
  2. Reorder to move the class atribute to the last position, Weka assumes it is there.

You may find more info and other approaches to transform your data in this Weka wiki page: http://weka.wikispaces.com/Text+categorization+with+WEKA




回答2:


In weka, you can choose your own attribute. In this example, we only have 2 classes and all of the unique words are used as attributes. If you choose word frequency as your attribute, then you assign '2' if that word occurs twice in your text, and '0' if not, or '1' if that word occurs only once.

Here is the example .arff format.

@RELATION anyrelation

@ATTRIBUTE word1
@ATTRIBUTE word2
...
@ATTRIBUTE wordn
@ATTRIBUTE class {class1, class2}

@DATA
1,2,....,0,class1
0,3,....,1,class2


来源:https://stackoverflow.com/questions/8313426/how-to-represent-text-for-classification-in-weka

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!