如何使用libsvm进行文本分类? [英] How to use libsvm for text classification?

查看:84
本文介绍了如何使用libsvm进行文本分类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用SVM编写垃圾邮件过滤器程序,我选择libsvm作为工具.
我收到了1000封好邮件和1000封垃圾邮件,然后将它们分类为:
700个good_train邮件700个spam_train邮件
300封Good_Test邮件300封Spam_test邮件
然后我写了一个程序来计算每个文件中每个单词出现的时间,得到的结果如下:

I'd like to write a spam filter program with SVM and I choose libsvm as the tool.
I got 1000 good mails and 1000 spam mails, then I classify them into :
700 good_train mails 700 spam_train mails
300 good_test mails 300 spam_test mails
Then I wrote a program to count the time of each words occur in each file, got result like:

good_train_1.txt:  
today 3  
hello 7  
help 5  
...    

我了解到libsvm需要如下格式:

I learned that libsvm needs format like:

1 1:3 2:1 3:0
2 1:3 2:3 3:1
1 1:7 3:9

1 1:3 2:1 3:0
2 1:3 2:3 3:1
1 1:7 3:9

作为其输入.我知道1、2、1是标签,但是1:3是什么意思?
如何将我所拥有的转换为这种格式?

as its input. I know that 1, 2, 1 is the label, but what does 1:3 mean?
How could I transfer what I've got to this format?

推荐答案

同样,格式为

classLabel attribute1:count1 ... attributeN:countN

N是您的文本语料库中不同单词的总数.您将必须查看所使用工具(或其来源)的文档,以了解是否可以通过不包括计数为0的属性来使用稀疏格式.

N is the total number of different words in your text corpus. You will have to check the documentation for the tool you are using(or its sources), to see if you can use a sparser format by not including the attributes having count 0.

这篇关于如何使用libsvm进行文本分类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆