@@ -60,9 +60,28 @@ gnuplot does not support png, so you need to change "set term png
6060transparent small" and use other image formats. For example, you may
6161have "set term pbm small color".
6262
63- Usage: grid.py [-log2c begin,end,step] [-log2g begin,end,step] [-v fold]
64- [-svmtrain pathname] [-gnuplot pathname] [-out pathname] [-png pathname]
65- [additional parameters for svm-train] dataset
63+ Usage: grid.py [grid_options] [svm_options] dataset
64+
65+ grid_options :
66+ -log2c {begin,end,step | "null"} : set the range of c (default -5,15,2)
67+ begin,end,step -- c_range = 2^{begin,...,begin+k*step,...,end}
68+ "null" -- do not grid with c
69+ -log2g {begin,end,step | "null"} : set the range of g (default 3,-15,-2)
70+ begin,end,step -- g_range = 2^{begin,...,begin+k*step,...,end}
71+ "null" -- do not grid with g
72+ -v n : n-fold cross validation (default 5)
73+ -svmtrain pathname : set svm executable path and name
74+ -gnuplot {pathname | "null"} :
75+ pathname -- set gnuplot executable path and name
76+ "null" -- do not plot
77+ -out {pathname | "null"} : (default dataset.out)
78+ pathname -- set output file path and name
79+ "null" -- do not output file
80+ -png pathname : set graphic output file path and name (default dataset.png)
81+ -resume [pathname] : resume the grid task using an existing output file (default pathname is dataset.out)
82+ Use this option only if some parameters have been checked for the SAME data.
83+
84+ svm_options : additional options for svm-train
6685
6786The program conducts v-fold cross validation using parameter C (and gamma)
6887= 2^begin, 2^(begin+step), ..., 2^end.
@@ -74,6 +93,17 @@ For windows users, please use pgnuplot.exe. If you are using gnuplot
74933.7.1, please upgrade to version 3.7.3 or higher. The version 3.7.1
7594has a bug. If you use cygwin on windows, please use gunplot-x11.
7695
96+ If the task is terminated accidentally or you would like to change the
97+ range of parameters, you can apply '-resume' to save time by re-using
98+ previous results. You may specify the output file of a previous run
99+ or use the default (i.e., dataset.out) without giving a name. Please
100+ note that the same condition must be used in two runs. For example,
101+ you cannot use '-v 10' earlier and resume the task with '-v 5'.
102+
103+ The value of some options can be "null." For example, `-log2c -1,0,1
104+ -log2 "null"' means that C=2^-1,2^0,2^1 and g=LIBSVM's default gamma
105+ value. That is, you do not conduct parameter selection on gamma.
106+
77107Example
78108=======
79109
@@ -89,6 +119,10 @@ Output: two files
89119dataset.png: the CV accuracy contour plot generated by gnuplot
90120dataset.out: the CV accuracy at each (log2(C),log2(gamma))
91121
122+ The following example saves running time by loading the output file of a previous run.
123+
124+ > python grid.py -log2c -7,7,1 -log2g -5,2,1 -v 5 -resume heart_scale.out heart_scale
125+
92126Parallel grid search
93127====================
94128
@@ -123,6 +157,33 @@ If -log2c, -log2g, or -v is not specified, default values are used.
123157If your system uses telnet instead of ssh, you list the computer names
124158in telnet_workers.
125159
160+ Calling grid in Python
161+ ======================
162+
163+ In addition to using grid.py as a command-line tool, you can use it as a
164+ Python module.
165+
166+ >>> rate, param = find_parameters(dataset, options)
167+
168+ You need to specify `dataset' and `options' (default ''). See the following example.
169+
170+ > python
171+
172+ >>> from grid import *
173+ >>> rate, param = find_parameters('../heart_scale', '-log2c -1,1,1 -log2g -1,1,1')
174+ [local] 0.0 0.0 rate=74.8148 (best c=1.0, g=1.0, rate=74.8148)
175+ [local] 0.0 -1.0 rate=77.037 (best c=1.0, g=0.5, rate=77.037)
176+ .
177+ .
178+ [local] -1.0 -1.0 rate=78.8889 (best c=0.5, g=0.5, rate=78.8889)
179+ .
180+ .
181+ >>> rate
182+ 78.8889
183+ >>> param
184+ {'c': 0.5, 'g': 0.5}
185+
186+
126187Part III: LIBSVM format checking tools
127188
128189Introduction
0 commit comments