scikit-learn GridSearchCV弃用警告

时间:2014-01-29 18:28:11

标签: python scikit-learn

我正在使用来自scikit-learn 0.14的GridSearchCV,但总是收到以下警告:

  

/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/sklearn/grid_search.py​​:706:DreprecationWarning:忽略GridSearchCV的其他参数! params参数将在0.15中删除。     DeprecationWarning)

有谁确切知道哪些参数被忽略了?

代码(从文件中读取x和y):

def balanced_accuracy (ground_truth, predictions):
    f00 = 1. * ((ground_truth == 1) & (predictions == 1)).sum() / (ground_truth == 1).sum()
    f11 = 1. * ((ground_truth == 2) & (predictions == 2)).sum() / (ground_truth == 2).sum()
    return 0.5* (f00 + f11)

bc_score = make_scorer(balanced_accuracy, greater_is_better=True)

C_range = 10. ** np.arange(-3, 3)
gamma_range = 10. ** np.arange(-3, 3)
r_range = np.concatenate((np.array([0]), 10.0 ** np.arange(-1, 3)))
kernel = "poly"
deg = 2
cw = "auto"

param_grid = dict(C=C_range, coef0 = r_range, gamma=gamma_range)
ss = ShuffleSplit(len(y), 10, test_size = 1000, train_size = 1000)

grid = GridSearchCV(svm.SVC(kernel = kernel, max_iter = 1000000, degree = deg, class_weight = cw), param_grid=param_grid, cv=ss, scoring = bc_score)
grid.fit (x, y, sample_weight = sw)

提前致谢!

1 个答案:

答案 0 :(得分:2)

sample_weight的{​​{1}}参数已弃用。这在文档中都是明显的,并且通过查看0.14.X release branch of scikit-learn's source

在这种情况下,在0.14版本中也会忽略sample_weight,因此grid.fit等同于grid.fit(x, y sample_weight=sw)

作为旁注,根据pep-8写一个好主意。