早教吧作业答案频道 -->其他-->
python程序gridregression.py运行出错:NameError:globalname'outfilename'isnotdefined错误如下:Traceback(mostrecentcalllast):File"D:\huigui\libsvm\Python24\gridregression.py",line281,in?resultfile=open(outfilename
题目详情
python程序gridregression.py运行出错: NameError: global name 'out_filename' is not defined 错误如下:
Traceback (most recent call last):
File "D:\huigui\libsvm\Python24\gridregression.py", line 281, in ?
result_file = open(out_filename,'w',0)
NameError: global name 'out_filename' is not defined
部分程序代码如下:
#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 begin,end,step] [-log2g begin,end,step] [-log2p begin,end,step] [-v fold]
[-svmtrain pathname] [-gnuplot pathname] [-out pathname] [-png pathname]
[additional parameters for svm-train] dataset"""
def main():
# set parameters
process_options()
# gather results
done_jobs = {}
result_file = open(out_filename,'w',0)
db = []
best_mse = 100000000
for line in jobs:
for (c,g,p) in line:
while not done_jobs.has_key((c,g,p)):
(worker,c1,g1,p1,mse) = result_queue.get()
done_jobs[(c1,g1,p1)] = mse
result_file.write('%s %s %s %s\n' %(c1,g1,p1,mse))
result_file.flush()
print "[%s] %s %s %s %s" % (worker,c1,g1,p1,mse),
if mse < best_mse:
best_mse = mse
best_c = 2.0**c1
best_g = 2.0**g1
best_p = 2.0**p1
print " (best c=%s, g=%s, p=%s, mse=%s)" % \
(best_c, best_g, best_p, best_mse)
# db.append((c,g,r,done_jobs[(c,g,r)]))
job_queue.put((WorkerStopToken,None,None))
print "%s %s %s %s" % (best_c, best_g, best_p, best_mse)
main()
Traceback (most recent call last):
File "D:\huigui\libsvm\Python24\gridregression.py", line 281, in ?
result_file = open(out_filename,'w',0)
NameError: global name 'out_filename' is not defined
部分程序代码如下:
#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 begin,end,step] [-log2g begin,end,step] [-log2p begin,end,step] [-v fold]
[-svmtrain pathname] [-gnuplot pathname] [-out pathname] [-png pathname]
[additional parameters for svm-train] dataset"""
def main():
# set parameters
process_options()
# gather results
done_jobs = {}
result_file = open(out_filename,'w',0)
db = []
best_mse = 100000000
for line in jobs:
for (c,g,p) in line:
while not done_jobs.has_key((c,g,p)):
(worker,c1,g1,p1,mse) = result_queue.get()
done_jobs[(c1,g1,p1)] = mse
result_file.write('%s %s %s %s\n' %(c1,g1,p1,mse))
result_file.flush()
print "[%s] %s %s %s %s" % (worker,c1,g1,p1,mse),
if mse < best_mse:
best_mse = mse
best_c = 2.0**c1
best_g = 2.0**g1
best_p = 2.0**p1
print " (best c=%s, g=%s, p=%s, mse=%s)" % \
(best_c, best_g, best_p, best_mse)
# db.append((c,g,r,done_jobs[(c,g,r)]))
job_queue.put((WorkerStopToken,None,None))
print "%s %s %s %s" % (best_c, best_g, best_p, best_mse)
main()
▼优质解答
答案和解析
你好:
这是全局变量的用法;
要想在一个函数里面用全局函数:
需要现在外面声明一下;
然后在函数里面使用:global声明
这是全局变量的用法;
要想在一个函数里面用全局函数:
需要现在外面声明一下;
然后在函数里面使用:global声明
看了 python程序gridre...的网友还看了以下:
已知⊙O过点D(4,3),点H与点D关于x轴对称,过H作⊙O的切线交x轴于点A.(1)求sin∠H 2020-05-13 …
下图是一个等边三角形木框,甲虫P在边框AC上爬行(A,C端点除外),设甲虫P到另外两边的距离之和为 2020-05-13 …
某二叉树结点的前序序列为F,C,A,D,B,E,G,H,P,对称序序列为A,C,B,D,F,E, H 2020-05-23 …
某二叉树结点的前序序列为F,C,A,D,B,E,G,H,P,对称序序列为A,C,B,D,F,E,H, 2020-05-24 …
三角形ABC是等边三角形,AM⊥BC于M,PD⊥AD于D,PE⊥AC于E,PD=h1,PE=h2, 2020-06-04 …
(2006•南宁)如图是一个等边三角形木框,甲虫P在边框AC上爬行(A,C端点除外),设甲虫P到另 2020-07-12 …
推断题:现有如下反应(反应条件均不给),推断物质⑴A→B+C+D⑵C+E→C+F+D⑶D+G→H⑷ 2020-07-30 …
redefinition;differentbasictypes以下程序在Vc6.0编译时出了问题# 2020-11-23 …
喷灌是一种先进的田间灌溉技术,雾化指标h是它的技术要素之一,当喷嘴的直径为dmm,喷头的工作压强为p 2020-12-17 …
3.y=a(x-h+p)+k4.y=a(x-h-f)+k又没有详解?y=a(x-h)+k移动后的解析 2021-02-05 …