【发布时间】:2016-12-12 02:14:31
【问题描述】:
我一直在为 Gridsearchcv 苦苦挣扎。
在对我的火车数据进行矢量化后,我使用网格搜索来进行有效的参数设置,但我得到了连续的错误。
我的代码是这样的:
x = HashVectorizer().fit_transform( train_data.data )
parameters = { "c" : [0.001 , 0.01 , 0.1 , 1 , 10 , 100 , 1000]}
if __name__ == "__main__":# i recetly fixed this error
clf = GridSearchCV(LogisticRegression() , parameters , n_jobs = -1 , verbose = 1)
train = clf.fit( x , x.label)
y = HashVectorizer().transform( test_data.data )
test = clf.predict(y)# here is my PROBLEM line , the error is coming as "clf is not defined "
但我已经定义了 clf ,在检查了 gridsearchcv documentation 之后我也没有找到任何帮助。
请帮忙。
【问题讨论】:
-
奇怪;无法重现错误;当
LogisticRegression接受大写C作为参数时,可能与parameters中的小写c有关 -
我有一个 C 这只是一个错字
-
如果我不寻找参数调整我的代码运行良好@Jacquot
-
@Jacquot 我认为问题出在缩进中,如果 name == "main 中的最后两行是否必须缩进" ?
-
不能伤害,或者完全摆脱它;我承认我从来没有用过
if __name__ == "__main__":,它更像是一个软件工程的东西;也可能在clf = GridSearchCV(lr, ...)之前定义lr = LogisticRegression()
标签: python scikit-learn grid-search