本文整理汇总了Python中scikits.learn.grid_search.GridSearchCV.set_params方法的典型用法代码示例。如果您正苦于以下问题:Python GridSearchCV.set_params方法的具体用法?Python GridSearchCV.set_params怎么用?Python GridSearchCV.set_params使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scikits.learn.grid_search.GridSearchCV
的用法示例。
在下文中一共展示了GridSearchCV.set_params方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_grid_search_sparse_score_func
# 需要导入模块: from scikits.learn.grid_search import GridSearchCV [as 别名]
# 或者: from scikits.learn.grid_search.GridSearchCV import set_params [as 别名]
def test_grid_search_sparse_score_func():
X_, y_ = make_classification(n_samples=200, n_features=100, random_state=0)
clf = LinearSVC()
cv = GridSearchCV(clf, {'C': [0.1, 1.0]}, score_func=f1_score)
# XXX: set refit to False due to a random bug when True (default)
cv.set_params(refit=False).fit(X_[:180], y_[:180])
y_pred = cv.predict(X_[180:])
C = cv.best_estimator.C
X_ = sp.csr_matrix(X_)
clf = SparseLinearSVC()
cv = GridSearchCV(clf, {'C': [0.1, 1.0]}, score_func=f1_score)
# XXX: set refit to False due to a random bug when True (default)
cv.set_params(refit=False).fit(X_[:180], y_[:180])
y_pred2 = cv.predict(X_[180:])
C2 = cv.best_estimator.C
assert_array_equal(y_pred, y_pred2)
assert_equal(C, C2)