首先要提的是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() ) );