I assume you want to grid search over different class_weight
for the 'salary' class.
The value of class_weight
should be a list:
'class_weight':[{'salary':1}, {'salary':2}, {'salary':4}, {'salary':6}, {'salary':10}]
And you can simplify it with list comprehension:
'class_weight':[{'salary': w} for w in [1, 2, 4, 6, 10]]
The first problem is that the parameter values in the dict parameters_to_tune
should be a list, while you passed a dict. It can be fixed by passing a list of dicts as the value of class_weight
instead and each dict contains a set of class_weight
for DecisionTreeClassifier
.
But the more serious problem is that class_weight
are weights associated with classes, but in your case, 'salary' is the name of a feature. You can not assign weights to features. I misunderstood your intention at first but now I am confused about what you want.
The form of class_weight
is {class_label: weight}
, if you really mean to set class_weight
in your case, class_label
should be values like 0.0, 1.0 etc., and the syntax would be like:
'class_weight':[{0: w} for w in [1, 2, 4, 6, 10]]
If the weight for a class is large, it is more likely for the classifier to predict data to be in that class. One typical case to use class_weight
is when the data is unbalanced.
Here is an example, although the classifier is SVM.
Update:
The full parameters_to_tune
should be 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} for w in [1, 2, 4, 6, 10]]}