本文整理汇总了Python中sklearn.grid_search方法的典型用法代码示例。如果您正苦于以下问题:Python sklearn.grid_search方法的具体用法?Python sklearn.grid_search怎么用?Python sklearn.grid_search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn
的用法示例。
在下文中一共展示了sklearn.grid_search方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fit_new_classifier
# 需要导入模块: import sklearn [as 别名]
# 或者: from sklearn import grid_search [as 别名]
def fit_new_classifier(problem, train_idx):
"""
References:
http://leon.bottou.org/research/stochastic
http://blog.explainmydata.com/2012/06/ntrain-24853-ntest-25147-ncorrupt.html
http://scikit-learn.org/stable/modules/svm.html#svm-classification
http://scikit-learn.org/stable/modules/grid_search.html
"""
print('[problem] train classifier on %d data points' % (len(train_idx)))
data = problem.ds.data
target = problem.ds.target
x_train = data.take(train_idx, axis=0)
y_train = target.take(train_idx, axis=0)
clf = sklearn.svm.SVC(kernel=str('linear'), C=.17, class_weight='balanced',
decision_function_shape='ovr')
# C, penalty, loss
#param_grid = {'C': [1e3, 5e3, 1e4, 5e4, 1e5],
# 'gamma': [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.1], }
#param_grid = {'C': [1e3, 5e3, 1e4, 5e4, 1e5],
# 'gamma': [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.1], }
#clf = GridSearchCV(SVC(kernel='rbf', class_weight='balanced'), param_grid)
#clf = clf.fit(X_train_pca, y_train)
clf.fit(x_train, y_train)
return clf