python - Sklearn GridSearchCV, class_weight not working for unknown reason :( -
trying class_weight
going . know rest of code works, class_weight
gives me error:
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
here code
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_
does spot mistake making ?
i assume want grid search on different class_weight
'salary' class.
the value of class_weight
should list:
'class_weight':[{'salary':1}, {'salary':2}, {'salary':4}, {'salary':6}, {'salary':10}]
and can simplify list comprehension:
'class_weight':[{'salary': w} w in [1, 2, 4, 6, 10]]
the first problem parameter values in dict parameters_to_tune
should list, while passed dict. can fixed passing list of dicts value of class_weight
instead , each dict contains set of class_weight
decisiontreeclassifier
.
but more serious problem class_weight
weights associated classes, in case, 'salary' name of feature. can not assign weights features. misunderstood intention @ first confused want.
the form of class_weight
{class_label: weight}
, if mean set class_weight
in case, class_label
should values 0.0, 1.0 etc., , syntax like:
'class_weight':[{0: w} w in [1, 2, 4, 6, 10]]
if weight class large, more classifier predict data in class. 1 typical case use class_weight
when data unbalanced.
here example, although classifier svm.
update:
the full parameters_to_tune
should like:
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':[{0: w} w in [1, 2, 4, 6, 10]]}
Comments
Post a Comment