From d8c921d08e21d6da241d7521e07a19d6e7d9fa17 Mon Sep 17 00:00:00 2001 From: punndcoder28 Date: Sat, 29 Jul 2023 18:59:29 +0530 Subject: [PATCH 1/7] docs(neural_networks): add links to neural network examples --- sklearn/neural_network/_multilayer_perceptron.py | 6 ++++++ sklearn/neural_network/_rbm.py | 3 +++ sklearn/neural_network/_stochastic_optimizers.py | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/sklearn/neural_network/_multilayer_perceptron.py b/sklearn/neural_network/_multilayer_perceptron.py index 5175247204fb8..2a7b4c78acdf8 100644 --- a/sklearn/neural_network/_multilayer_perceptron.py +++ b/sklearn/neural_network/_multilayer_perceptron.py @@ -767,6 +767,12 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron): This model optimizes the log-loss function using LBFGS or stochastic gradient descent. + For an example usage and visualization of varying regularization, see + :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_alpha.py` + + For an example usage and visualization of the MLP weights on MNIST, see + :ref:`sphx_glr_auto_examples_neural_networks_plot_mnist_filters.py` + .. versionadded:: 0.18 Parameters diff --git a/sklearn/neural_network/_rbm.py b/sklearn/neural_network/_rbm.py index ec819790c5f73..f3e6c1cc8f1be 100644 --- a/sklearn/neural_network/_rbm.py +++ b/sklearn/neural_network/_rbm.py @@ -37,6 +37,9 @@ class BernoulliRBM(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstima The time complexity of this implementation is ``O(d ** 2)`` assuming d ~ n_features ~ n_components. + For an example usage, see + :ref:`sphx_glr_auto_examples_neural_networks_plot_rbm_logistic_classification.py`. + Read more in the :ref:`User Guide `. Parameters diff --git a/sklearn/neural_network/_stochastic_optimizers.py b/sklearn/neural_network/_stochastic_optimizers.py index d9fbaec0098d0..aa0daa066f291 100644 --- a/sklearn/neural_network/_stochastic_optimizers.py +++ b/sklearn/neural_network/_stochastic_optimizers.py @@ -73,6 +73,9 @@ def trigger_stopping(self, msg, verbose): class SGDOptimizer(BaseOptimizer): """Stochastic gradient descent optimizer with momentum + For example usage and comparison with Adam optimizer, see + :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` + Parameters ---------- params : list, length = len(coefs_) + len(intercepts_) @@ -198,6 +201,9 @@ def _get_updates(self, grads): class AdamOptimizer(BaseOptimizer): """Stochastic gradient descent optimizer with Adam + For example usage and comparison with SGD optimizer, see + :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` + Note: All default values are from the original Adam paper Parameters From 6fa7dd84e9d44276f166b2eea55dfb69833c2754 Mon Sep 17 00:00:00 2001 From: punndcoder28 Date: Wed, 2 Aug 2023 22:55:23 +0530 Subject: [PATCH 2/7] fix: add comment for mlp weight viz, move rbm example to examples section --- doc/modules/neural_networks_supervised.rst | 3 ++- sklearn/neural_network/_multilayer_perceptron.py | 3 --- sklearn/neural_network/_rbm.py | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/doc/modules/neural_networks_supervised.rst b/doc/modules/neural_networks_supervised.rst index 388f32e7c6925..0fa2ecaf751df 100644 --- a/doc/modules/neural_networks_supervised.rst +++ b/doc/modules/neural_networks_supervised.rst @@ -146,7 +146,8 @@ See the examples below and the docstring of .. topic:: Examples: * :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` - * :ref:`sphx_glr_auto_examples_neural_networks_plot_mnist_filters.py` + * See :ref:`sphx_glr_auto_examples_neural_networks_plot_mnist_filters.py` for + visualization of varying regularization in MLP. Regression ========== diff --git a/sklearn/neural_network/_multilayer_perceptron.py b/sklearn/neural_network/_multilayer_perceptron.py index 2a7b4c78acdf8..75e356d56bccd 100644 --- a/sklearn/neural_network/_multilayer_perceptron.py +++ b/sklearn/neural_network/_multilayer_perceptron.py @@ -770,9 +770,6 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron): For an example usage and visualization of varying regularization, see :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_alpha.py` - For an example usage and visualization of the MLP weights on MNIST, see - :ref:`sphx_glr_auto_examples_neural_networks_plot_mnist_filters.py` - .. versionadded:: 0.18 Parameters diff --git a/sklearn/neural_network/_rbm.py b/sklearn/neural_network/_rbm.py index f3e6c1cc8f1be..4e4d93ed8121f 100644 --- a/sklearn/neural_network/_rbm.py +++ b/sklearn/neural_network/_rbm.py @@ -37,9 +37,6 @@ class BernoulliRBM(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstima The time complexity of this implementation is ``O(d ** 2)`` assuming d ~ n_features ~ n_components. - For an example usage, see - :ref:`sphx_glr_auto_examples_neural_networks_plot_rbm_logistic_classification.py`. - Read more in the :ref:`User Guide `. Parameters @@ -130,6 +127,9 @@ class BernoulliRBM(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstima >>> model = BernoulliRBM(n_components=2) >>> model.fit(X) BernoulliRBM(n_components=2) + + For an example usage, see + :ref:`sphx_glr_auto_examples_neural_networks_plot_rbm_logistic_classification.py`. """ _parameter_constraints: dict = { From ba83e7f08e3644b3576d7aa9f24e815e6a8bc18e Mon Sep 17 00:00:00 2001 From: punndcoder28 Date: Wed, 16 Aug 2023 21:47:52 +0530 Subject: [PATCH 3/7] fix: moving links for examples to approriate section --- sklearn/neural_network/_multilayer_perceptron.py | 14 ++++++++++---- sklearn/neural_network/_rbm.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sklearn/neural_network/_multilayer_perceptron.py b/sklearn/neural_network/_multilayer_perceptron.py index 75e356d56bccd..d2f53713fd7cd 100644 --- a/sklearn/neural_network/_multilayer_perceptron.py +++ b/sklearn/neural_network/_multilayer_perceptron.py @@ -767,9 +767,6 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron): This model optimizes the log-loss function using LBFGS or stochastic gradient descent. - For an example usage and visualization of varying regularization, see - :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_alpha.py` - .. versionadded:: 0.18 Parameters @@ -803,6 +800,9 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron): - 'adam' refers to a stochastic gradient-based optimizer proposed by Kingma, Diederik, and Jimmy Ba + For example usage and comparison with Adam optimizer, see + :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` + Note: The default solver 'adam' works pretty well on relatively large datasets (with thousands of training samples or more) in terms of both training time and validation score. @@ -813,6 +813,9 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron): Strength of the L2 regularization term. The L2 regularization term is divided by the sample size when added to the loss. + For an example usage and visualization of varying regularization, see + :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_alpha.py` + batch_size : int, default='auto' Size of minibatches for stochastic optimizers. If the solver is 'lbfgs', the classifier will not use minibatch. @@ -1158,7 +1161,7 @@ def predict(self, X): y : ndarray, shape (n_samples,) or (n_samples, n_classes) The predicted classes. """ - check_is_fitted(self) + check_is_fitted(selfo return self._predict(X) def _predict(self, X, check_input=True): @@ -1296,6 +1299,9 @@ class MLPRegressor(RegressorMixin, BaseMultilayerPerceptron): - 'adam' refers to a stochastic gradient-based optimizer proposed by Kingma, Diederik, and Jimmy Ba + For example usage and comparison with Adam optimizer, see + :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` + Note: The default solver 'adam' works pretty well on relatively large datasets (with thousands of training samples or more) in terms of both training time and validation score. diff --git a/sklearn/neural_network/_rbm.py b/sklearn/neural_network/_rbm.py index 4e4d93ed8121f..e3814f45d3633 100644 --- a/sklearn/neural_network/_rbm.py +++ b/sklearn/neural_network/_rbm.py @@ -128,7 +128,7 @@ class BernoulliRBM(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstima >>> model.fit(X) BernoulliRBM(n_components=2) - For an example usage, see + For a more detailed example usage, see :ref:`sphx_glr_auto_examples_neural_networks_plot_rbm_logistic_classification.py`. """ From 69b5bac9b49c95419f70b6e45524295bf4eba000 Mon Sep 17 00:00:00 2001 From: punndcoder28 Date: Wed, 16 Aug 2023 22:02:38 +0530 Subject: [PATCH 4/7] fix: fix failing lint job --- sklearn/neural_network/_multilayer_perceptron.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/neural_network/_multilayer_perceptron.py b/sklearn/neural_network/_multilayer_perceptron.py index d2f53713fd7cd..959027a6aa011 100644 --- a/sklearn/neural_network/_multilayer_perceptron.py +++ b/sklearn/neural_network/_multilayer_perceptron.py @@ -1161,7 +1161,7 @@ def predict(self, X): y : ndarray, shape (n_samples,) or (n_samples, n_classes) The predicted classes. """ - check_is_fitted(selfo + check_is_fitted(self) return self._predict(X) def _predict(self, X, check_input=True): From 29dcff64bc4379c00026380481364c462ee3d12b Mon Sep 17 00:00:00 2001 From: punndcoder28 Date: Sun, 27 Aug 2023 11:31:32 +0530 Subject: [PATCH 5/7] refactor: removed redundant links to examples --- doc/modules/neural_networks_supervised.rst | 2 +- sklearn/neural_network/_stochastic_optimizers.py | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/doc/modules/neural_networks_supervised.rst b/doc/modules/neural_networks_supervised.rst index 0fa2ecaf751df..100b4105be93d 100644 --- a/doc/modules/neural_networks_supervised.rst +++ b/doc/modules/neural_networks_supervised.rst @@ -147,7 +147,7 @@ See the examples below and the docstring of * :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` * See :ref:`sphx_glr_auto_examples_neural_networks_plot_mnist_filters.py` for - visualization of varying regularization in MLP. + visualized representation of trained weights. Regression ========== diff --git a/sklearn/neural_network/_stochastic_optimizers.py b/sklearn/neural_network/_stochastic_optimizers.py index aa0daa066f291..d9fbaec0098d0 100644 --- a/sklearn/neural_network/_stochastic_optimizers.py +++ b/sklearn/neural_network/_stochastic_optimizers.py @@ -73,9 +73,6 @@ def trigger_stopping(self, msg, verbose): class SGDOptimizer(BaseOptimizer): """Stochastic gradient descent optimizer with momentum - For example usage and comparison with Adam optimizer, see - :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` - Parameters ---------- params : list, length = len(coefs_) + len(intercepts_) @@ -201,9 +198,6 @@ def _get_updates(self, grads): class AdamOptimizer(BaseOptimizer): """Stochastic gradient descent optimizer with Adam - For example usage and comparison with SGD optimizer, see - :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` - Note: All default values are from the original Adam paper Parameters From cdbe78fb6a91a67253f8162cf7fdfe753252143d Mon Sep 17 00:00:00 2001 From: punndcoder28 Date: Tue, 29 Aug 2023 21:34:05 +0530 Subject: [PATCH 6/7] docs: fixing example message links in mlp --- sklearn/neural_network/_multilayer_perceptron.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/neural_network/_multilayer_perceptron.py b/sklearn/neural_network/_multilayer_perceptron.py index 959027a6aa011..36cc519da1795 100644 --- a/sklearn/neural_network/_multilayer_perceptron.py +++ b/sklearn/neural_network/_multilayer_perceptron.py @@ -800,7 +800,7 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron): - 'adam' refers to a stochastic gradient-based optimizer proposed by Kingma, Diederik, and Jimmy Ba - For example usage and comparison with Adam optimizer, see + For a comparison between Adam optimizer and SGD, see :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` Note: The default solver 'adam' works pretty well on relatively @@ -1299,7 +1299,7 @@ class MLPRegressor(RegressorMixin, BaseMultilayerPerceptron): - 'adam' refers to a stochastic gradient-based optimizer proposed by Kingma, Diederik, and Jimmy Ba - For example usage and comparison with Adam optimizer, see + For a comparison between Adam optimizer and SGD, see :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` Note: The default solver 'adam' works pretty well on relatively From f09c0771ff7b2bcc5b737019e745fcc4f0188327 Mon Sep 17 00:00:00 2001 From: Puneeth K Date: Sat, 6 Jan 2024 09:11:38 +0530 Subject: [PATCH 7/7] fix: add missing period for docs --- sklearn/neural_network/_multilayer_perceptron.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sklearn/neural_network/_multilayer_perceptron.py b/sklearn/neural_network/_multilayer_perceptron.py index 36cc519da1795..cc419b57f2410 100644 --- a/sklearn/neural_network/_multilayer_perceptron.py +++ b/sklearn/neural_network/_multilayer_perceptron.py @@ -801,7 +801,7 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron): by Kingma, Diederik, and Jimmy Ba For a comparison between Adam optimizer and SGD, see - :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` + :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py`. Note: The default solver 'adam' works pretty well on relatively large datasets (with thousands of training samples or more) in terms of @@ -814,7 +814,7 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron): is divided by the sample size when added to the loss. For an example usage and visualization of varying regularization, see - :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_alpha.py` + :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_alpha.py`. batch_size : int, default='auto' Size of minibatches for stochastic optimizers. @@ -1300,7 +1300,7 @@ class MLPRegressor(RegressorMixin, BaseMultilayerPerceptron): Kingma, Diederik, and Jimmy Ba For a comparison between Adam optimizer and SGD, see - :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py` + :ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py`. Note: The default solver 'adam' works pretty well on relatively large datasets (with thousands of training samples or more) in terms of