Python中SVM分类器的Class_weight

时间:2016-09-22 12:55:33

标签: python machine-learning scikit-learn svm

我有一组参数可以使用GridSearchCV为svm.SVC分类器选择最佳参数:

X=dataset.ix[:, dataset.columns != 'class']
Y=dataset['class']
X_train, X_test, Y_train, Y_test = cross_validation.train_test_split(X, Y, test_size=0.5)

clf=svm.SVC()
params=
        {'kernel':['linear', 'rbf', 'poly', 'sigmoid'],
         'C':[1, 5, 10],
         'degree':[2,3],
         'gamma':[0.025, 1.0, 1.25, 1.5, 1.75, 2.0],
         'coef0':[2, 5, 9],
         'class_weight': [{1:10}, 'balanced']}

searcher = GridSearchCV(clf, params, cv=9, n_jobs=-1, scoring=f1)
searcher.fit(X_train, Y_train)

我收到错误:ValueError: class_weight must be dict, 'auto', or None, got: 'balanced' 为什么我有这个,如果在svm参数的说明中有'balanced',而不是'auto'

1 个答案:

答案 0 :(得分:0)

'balanced'应该正常工作,如第51或74行https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/utils/class_weight.py

所示

执行sklearn.__version__以检查您正在运行的版本。