首先要提的是LibSVM是一个库,Lib很明显是library的缩写,有些人不知道怎么会认为它是一种算法。它是由中国台湾的Chih-Chung Chang和Chih-Jen Lin等人开发的,他们用多种语言实现写了LibSVM。html
我把这一篇放到Weka开发里讲,主要讲它怎么和Weka结合,Weka中并非没有SVM算法,Weka中有SMO算法的实现。java
Weka and LibSVM are two efficient software tools for building SVM classifiers. Each one of these two tools has its points of strength and weakness. Weka has a GUI and produces many useful statistics (e.g. confusion matrix, precision, recall, F-measure, and ROC scores). LibSVM runs much faster than Weka SMO and supports several SVM methods (e.g. One-class SVM, nu-SVM, and R-SVM). Weka LibSVM (WLSVM) combines the merits of the two tools. WLSVM can be viewed as an implementation of the LibSVM running under Weka environment.算法
这一段是我从拷贝来的,请注意里面有一句话,LibSVM运行的比Weka里的SMO快的多,若是你敢用SMO算法去训练大数据集,你就明白天荒地老的真实含意了。其它和Weka结合的最主要的缘由,我认为是,咱们开始的时候每每都是用别的算法去试着作实验的(或者原本就须要多种基分类器),好比Naïve Bayes(LibSVM是比SMO快的多,但是比起来Naïve Bayes,它仍是蜗牛),到最后又想试试LibSVM,这时就须要LibSVM库。dom
还有一点也是容易误解的就是Weka里的高版本,里面是有LibSVM这个分类器,但你若是直接想运行是会出错的,提示你没有设置路径。缘由是:WLSVM can be viewed as an implementation of the LibSVM running under Weka environment.大数据
先把LibSVM下载下来,上次居然有人问我在哪下载,这种问题,我真是不想回答,不就是google一下吗?网址也放上:http://www.csie.ntu.edu.tw/~cjlin/libsvm/,下载WLSVM,解压后Lib文件夹下有一个LibSVM.jar的包,用和导入Weka.jar包相同的方式导入就行了,而后使用LibSVM和使用之前任何一种分类器的方式都是同样的。ui
LibSVM classifier = new LibSVM(); classifier.buildClassifier( instances ); Evaluation evaluation = new Evaluation( ins ); evaluation.crossValidateModel(classifier, ins, 10, random ); System.out.println( "正确率为:" + ( 1 - evaluation.errorRate() ) );