资源简介
在Libsvm中使用,结合python和gnuplot,主要是用来参数寻优
代码片段和文件信息
#!/usr/bin/env python
import os sys
import Queue
import getpass
import re
from sys import exit
from threading import Thread
from string import find split join atof
from time import sleep
is_win32 = (sys.platform == ‘win32‘)
# svmtrain and gnuplot executable
if not is_win32:
svmtrain_exe = “../svm-train“
gnuplot_exe = “/usr/bin/gnuplot“
else:
# example for windows
svmtrain_exe = r“c:\libsvm29\windows\svm-train.exe“
gnuplot_exe = r“c:\gnuplot\bin\pgnuplot.exe“
# global parameters and their default values
fold = 5
c_begin c_end c_step = -1 6 1
g_begin g_end g_step = 0 -8 -1
p_begin p_end p_step = -8 -1 1
global dataset_pathname dataset_title pass_through_string
global out_filename png_filename
# experimental
ssh_workers = []
# ssh_workers = [‘linux1‘‘linux1‘‘linux2‘‘linux2‘‘linux3‘ ‘linux4‘ ‘linux6‘‘linux7‘‘linux8‘‘linux8‘‘linux9‘‘linux10‘‘linux11‘‘linux12‘]
nr_local_worker = 1
# process command line options set global parameters
def process_options(argv=sys.argv):
global fold
global c_begin c_end c_step
global g_begin g_end g_step
global p_begin p_end p_step
global dataset_pathname dataset_title pass_through_string
global svmtrain_exe gnuplot_exe gnuplot out_filename png_filename
usage = “““\
Usage: grid.py [-log2c beginendstep] [-log2g beginendstep] [-log2p beginendstep] [-v fold]
[-svmtrain pathname] [-gnuplot pathname] [-out pathname] [-png pathname]
[additional parameters for svm-train] dataset“““
if len(argv) < 2:
print usage
sys.exit(1)
dataset_pathname = argv[-1]
dataset_title = os.path.split(dataset_pathname)[1]
out_filename = ‘%s.out‘ % dataset_title
png_filename = ‘%s.png‘ % dataset_title
pass_through_options = []
i = 1
while i < len(argv) - 1:
if argv[i] == “-log2c“:
i = i + 1
(c_beginc_endc_step) = map(atofsplit(argv[i]““))
elif argv[i] == “-log2g“:
i = i + 1
(g_beging_endg_step) = map(atofsplit(argv[i]““))
elif argv[i] == “-log2p“:
i = i + 1
(p_beginp_endp_step) = map(atofsplit(argv[i]““))
elif argv[i] == “-v“:
i = i + 1
fold = argv[i]
elif argv[i] in (‘-c‘‘-g‘):
print “Option -c and -g are renamed.“
print usage
sys.exit(1)
elif argv[i] == ‘-svmtrain‘:
i = i + 1
svmtrain_exe = argv[i]
elif argv[i] == ‘-gnuplot‘:
i = i + 1
gnuplot_exe = argv[i]
elif argv[i] == ‘-out‘:
i = i + 1
out_filename = argv[i]
elif argv[i] == ‘-png‘:
i = i + 1
png_filename = argv[i]
else:
pass_through_options.append(argv[i])
i = i + 1
pass_through_string = join(pass_through_options“ “)
assert os.path.exists(gnuplot_exe)“gnuplot executable not found“
ass
- 上一篇:meituan_room.py
- 下一篇:蒙特卡洛模拟
评论
共有 条评论