原文

http://pwwang.com/technology/svm/libsvm-288中文文档tools/

=================================================

 

 這個目錄中包括一些有用的程式:
1. 
子集選擇工具
2. 
參數選擇工具
3. LIBSVM
格式檢查工具 

第一部分子集選擇工具

介紹
==============

訓練大量的資料需要消耗大量的時間有時你需要先對一個小的子集進行訓練. python腳本subset.py可以隨機地選擇一個特定數目的樣本對於分類資料我們提供一個分層選擇來保證相同的類在一個子集中.

用法: subset.py [options] dataset number [output1] [output2]

這個腳本從給定的資料集中選擇一個子集.

選項:
-s method: 
選擇的方式(預設 0)
 0 — 
分層選擇(只用於分類)
 1 — 
隨機選擇
 
output1: 
子集(可選)
output2: 
餘下的數據(可選)

如果output1未選那麼子集將在螢幕上列印出來.

例子
===============

>python subset.py heart_scale 100 file1 file2

heart_scale中隨機選擇100個樣本保存到file1,而剩餘的實例保存到file2.

第二部分參數選擇工具

介紹
===============

grid.py是一個參數選擇工具這個工具是用於採用RBF(徑向基函數)核的C-SVM分類的它採用CV(交叉驗證)技術來估計特定範圍內每一個聯合參數的準確性並且幫助你選擇一個適合你問題的最佳參數.

grid.py為交叉驗證直接執行libsvm二進位檔案(不需要python的結合)並且用gnuplot來畫CV準確性的輪廓在使用之前你必須事先安裝libsvmgnuplot. gnuplot可以在這裡下載: http://www.gnuplot.info/

在蘋果系統中預編譯的gnuplot檔需要Aquarterm庫的支援這個庫也需要安裝另外這個版本的gnuplot不支持png, 所以你需要修改"set term png transparent small"並使用其他圖片格式例如你可以設定為"set term pbm small color".

用法: grid.py [-log2c begin,end,step] [-log2g begin,end,step] [-v fold]
       [-svmtrain pathname] [-gnuplot pathname] [-out pathname] [-png pathname]
       [additional parameters for svm-train] dataset

這個程式處理v-fold交叉驗證的時候採用的參數C(gamma) = 2^begin, 2^(begin+step), …, 2^end.

你可以採用-svmtrain-gnuplot參數來指定libsvmgnuplot的位置.

對於windows用戶請使用gnuplot.exe. 如果你正在使用gnuplot 3.7.1版本請升級到3.7.3或更高版本. 3.7.1有一個bug. 如果你使用的是windows下的
cygwin, 
請使用gunplot-x11.

例子
===============

> python grid.py -log2c -5,5,1 -log2g -4,0,1 -v 5 -m 300 heart_scale

使用者(特別是MS Windows使用者)可能需要指定可執行檔的路徑你既可以在grid.py的開頭修改路徑,也可以在命令列中指定它們例如,

> grid.py -log2c -5,5,1 -svmtrain c:\libsvm\windows\svm-train.exe -gnuplot c:\tmp\gnuplot\bin\pgnuplot.exe -v 10 heart_scale

Output: 兩個文件
dataset.png: gnuplot
生成的CV準確性輪廓圖
dataset.out: 
每一個(log2(C),log2(gamma))CV準確性

並行網格搜索
===============

把工作分離到一個共用相同檔案系統的電腦集群你可以處理一個並行的網格搜索首先grid.py中添加機器名字:

ssh_workers = ["linux1", "linux5", "linux5"]

然後設定你的ssh, 使得授權工作不需要詢問密碼.

如果一台機器有多個CPU或者更多的RAM, 相同的機器(例如這裡的linux5)可以列出不只一次如果本地機器是最好的你也可以擴大nr_local_worker, 例如,

nr_local_worker = 2

例子:

> python grid.py heart_scale
[local] -1 -1 78.8889  (best c=0.5, g=0.5, rate=78.8889)
[linux5] -1 -7 83.3333  (best c=0.5, g=0.0078125, rate=83.3333)
[linux5] 5 -1 77.037  (best c=0.5, g=0.0078125, rate=83.3333)
[linux1] 5 -7 83.3333  (best c=0.5, g=0.0078125, rate=83.3333)
.
.
.

如果 -log2c, -log2g,  -v 沒有指定則使用預設值.

如果你的系統使用telnet代替ssh, 你應該把你的機器名字在telnet_workers列出.

第三部分: LIBSVM格式檢查工具

介紹
=================

`svm-train’只是對輸入資料進行簡單的檢查要做更詳細的檢查我們提供一個python腳本 `checkdata.py’.

用法: checkdata.py dataset

這個工具的作者是臺灣大學的Rong-En Fan.

例子
==================

> cat bad_data
1 3:1 2:4
> python checkdata.py bad_data
line 1: feature indices must be in an ascending order, previous/current features 3:1 2:4
Found 1 lines with error.

 

創作者介紹
創作者 kendoit 的頭像
kendoit

kendoit

kendoit 發表在 痞客邦 留言(0) 人氣( 12 )