早教吧作业答案频道 -->其他-->
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...的网友还看了以下:
将打乱的字母连成词:Theninthunitisthe(e,s,t,i,e,a)oneinModu 2020-04-27 …
牛津英语6A题目:The(t,i,n,n,h)unitisthe(e,s,t,i,e,a)onei 2020-04-27 …
已知字母组合成英语单词1、e e t t i n h r 2、e e r a t w h 3、o 2020-05-14 …
考查文法:G(VT,VN,E,P) 其中,VT={+,*,(,),i},VN={E,T,F},E为开 2020-05-26 …
令文法G[E]为:E→T|E+T|E-TT→F|T*F|T/FF→(E)|i证明E+T*F是它的一 2020-07-08 …
英语单词填空1.时间状语:d-r-n-2.场所:b-s-s-o-f-r--e-a-t-e-t3.教 2020-07-14 …
matlab求解二阶导数方程,四个方程四个未知量>>symst>>E=32;G=10.81;b=2 2020-07-19 …
求100到1000之间的素数#include"stdio.h"main(){inti,j,p;fo 2020-07-23 …
三元一次方程组a*x+b*y+c*z+d=0,e*x+f*y+g*z+h=0,i*x+j*y+k* 2020-08-03 …
组合英语单词:1.r,i,v,r,d,e2.t,i,w,e,h3.a,v,e,s,4.c,t,k,e 2020-11-29 …