diff --git a/doc/conf.py b/doc/conf.py index f749b188b3274..dbe4213505918 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -502,6 +502,9 @@ def add_js_css_files(app, pagename, templatename, context, doctree): "auto_examples/linear_model/plot_ols_ridge_variance": ( "auto_examples/linear_model/plot_ols_ridge" ), + "auto_examples/linear_model/plot_sgd_comparison": ( + "auto_examples/linear_model/plot_sgd_loss_functions" + ), } html_context["redirects"] = redirects for old_link in redirects: diff --git a/doc/modules/sgd.rst b/doc/modules/sgd.rst index d1f2211bca8d8..9703146fb2de5 100644 --- a/doc/modules/sgd.rst +++ b/doc/modules/sgd.rst @@ -194,7 +194,6 @@ algorithm, available as a solver in :class:`LogisticRegression`. - :ref:`sphx_glr_auto_examples_linear_model_plot_sgd_separating_hyperplane.py` - :ref:`sphx_glr_auto_examples_linear_model_plot_sgd_iris.py` - :ref:`sphx_glr_auto_examples_linear_model_plot_sgd_weighted_samples.py` -- :ref:`sphx_glr_auto_examples_linear_model_plot_sgd_comparison.py` - :ref:`sphx_glr_auto_examples_svm_plot_separating_hyperplane_unbalanced.py` (See the Note in the example) diff --git a/examples/linear_model/plot_sgd_comparison.py b/examples/linear_model/plot_sgd_comparison.py deleted file mode 100644 index c24ad14a79532..0000000000000 --- a/examples/linear_model/plot_sgd_comparison.py +++ /dev/null @@ -1,70 +0,0 @@ -""" -================================== -Comparing various online solvers -================================== -An example showing how different online solvers perform -on the hand-written digits dataset. -""" - -# Authors: The scikit-learn developers -# SPDX-License-Identifier: BSD-3-Clause - -import matplotlib.pyplot as plt -import numpy as np - -from sklearn import datasets -from sklearn.linear_model import ( - LogisticRegression, - PassiveAggressiveClassifier, - Perceptron, - SGDClassifier, -) -from sklearn.model_selection import train_test_split - -heldout = [0.95, 0.90, 0.75, 0.50, 0.01] -# Number of rounds to fit and evaluate an estimator. -rounds = 10 -X, y = datasets.load_digits(return_X_y=True) - -classifiers = [ - ("SGD", SGDClassifier(max_iter=110)), - ("ASGD", SGDClassifier(max_iter=110, average=True)), - ("Perceptron", Perceptron(max_iter=110)), - ( - "Passive-Aggressive I", - PassiveAggressiveClassifier(max_iter=110, loss="hinge", C=1.0, tol=1e-4), - ), - ( - "Passive-Aggressive II", - PassiveAggressiveClassifier( - max_iter=110, loss="squared_hinge", C=1.0, tol=1e-4 - ), - ), - ( - "SAG", - LogisticRegression(max_iter=110, solver="sag", tol=1e-1, C=1.0e4 / X.shape[0]), - ), -] - -xx = 1.0 - np.array(heldout) - -for name, clf in classifiers: - print("training %s" % name) - rng = np.random.RandomState(42) - yy = [] - for i in heldout: - yy_ = [] - for r in range(rounds): - X_train, X_test, y_train, y_test = train_test_split( - X, y, test_size=i, random_state=rng - ) - clf.fit(X_train, y_train) - y_pred = clf.predict(X_test) - yy_.append(1 - np.mean(y_pred == y_test)) - yy.append(np.mean(yy_)) - plt.plot(xx, yy, label=name) - -plt.legend(loc="upper right") -plt.xlabel("Proportion train") -plt.ylabel("Test Error Rate") -plt.show()