【发布时间】:2015-10-28 00:53:39
【问题描述】:
试图让class_weight 去。我知道其余的代码有效,只是 class_weight 给了我错误:
parameters_to_tune = ['min_samples_split':[2,4,6,10,15,25], 'min_samples_leaf':[1,2,4,10],'max_depth':[None,4,10,15],
^
SyntaxError: invalid syntax
这是我的代码
clf1 = tree.DecisionTreeClassifier()
parameters_to_tune = ['min_samples_split':[2,4,6,10,15,25], 'min_samples_leaf':[1,2,4,10],'max_depth':[None,4,10,15],
'splitter' : ('best','random'),'max_features':[None,2,4,6,8,10,12,14],'class_weight':{1:10}]
clf=grid_search.GridSearchCV(clf1,parameters_to_tune)
clf.fit(features,labels)
print clf.best_params_
有人发现我犯的错误吗?
【问题讨论】:
-
你能举例说明你的特征和标签是什么样的吗?
-
features 基本上是一个数字数组(浮点数),其中作为标签,是(不知道您是否也称其为数组或简单的向量)[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0.....
-
parameters_to_tune应该是一个字典或字典列表。您的初始语法是正确的。您只需要更改字典中的 'class_weight' 键值对。 (抱歉,我刚才没有看到您的更新,但您最好保留您的原始帖子并附加您的更新,否则人们不会知道原始问题。) -
而你的
class_weight应该是一个字典列表,你又犯了错误......
标签: python scikit-learn grid-search