本文整理汇总了Python中sklearn.linear_model.SGDClassifier.eta0方法的典型用法代码示例。如果您正苦于以下问题:Python SGDClassifier.eta0方法的具体用法?Python SGDClassifier.eta0怎么用?Python SGDClassifier.eta0使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.linear_model.SGDClassifier
的用法示例。
在下文中一共展示了SGDClassifier.eta0方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evaluate_svm
# 需要导入模块: from sklearn.linear_model import SGDClassifier [as 别名]
# 或者: from sklearn.linear_model.SGDClassifier import eta0 [as 别名]
def evaluate_svm(alpha):
# Note: n_iter gets switched to 1 by sklearn whenever you call partial_fit(). This initial
# setting is for the pretesting of eta0.
basic_svm = SGDClassifier(loss="hinge", penalty="l2", l1_ratio=0.0, random_state=31337, n_jobs=5,
n_iter=5, alpha=alpha)
learning_rate_grid = [ 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7 ]
pretest_svm = GridSearchCV(basic_svm,
{"learning_rate": ["constant"],
"eta0": learning_rate_grid}).fit(X_pretest, y_pretest)
bottou_gamma0 = pretest_svm.best_params_["eta0"]
basic_svm.eta0 = bottou_gamma0
basic_svm.learning_rate = "constant"
basic_svm = basic_svm.partial_fit(X_pretest, y_pretest, classes = np.unique(y_train))
progressive_val = []
train_score = []
for dp in range(0, X_train.shape[0], batch_size):
t = dp + n_pretest
basic_svm.eta0 = bottou_gamma0/(1 + bottou_gamma0*alpha*t)
X_batch = X_train[dp:dp+batch_size]
y_batch = y_train[dp:dp+batch_size]
progressive_val.append(basic_svm.score(X_batch, y_batch))
basic_svm = basic_svm.partial_fit(X_batch, y_batch)
train_score.append(basic_svm.score(X_batch, y_batch))
scores = progressive_val[-batches_for_cv_performance:]
return np.mean(scores), np.std(scores), basic_svm