From c09a47fc8de40047e6104200df2f77d12977842c Mon Sep 17 00:00:00 2001 From: MattiM Date: Mon, 2 Jun 2025 11:06:37 -0400 Subject: [PATCH 1/2] DOC: Add link to plot_sparse_coding.py in DictionaryLearning and MiniBatchDictionaryLearning docstrings --- sklearn/decomposition/_dict_learning.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sklearn/decomposition/_dict_learning.py b/sklearn/decomposition/_dict_learning.py index ae40e28e9f013..ad498c3b6c310 100644 --- a/sklearn/decomposition/_dict_learning.py +++ b/sklearn/decomposition/_dict_learning.py @@ -1596,6 +1596,10 @@ class DictionaryLearning(_BaseSparseCoding, BaseEstimator): >>> X_hat = X_transformed @ dict_learner.components_ >>> np.mean(np.sum((X_hat - X) ** 2, axis=1) / np.sum(X ** 2, axis=1)) np.float64(0.056) + + See the example: + :ref:`sphx_glr_auto_examples_decomposition_plot_sparse_coding.py` + """ _parameter_constraints: dict = { @@ -1955,6 +1959,10 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator): >>> X_hat = X_transformed @ dict_learner.components_ >>> np.mean(np.sum((X_hat - X) ** 2, axis=1) / np.sum(X ** 2, axis=1)) np.float64(0.052) + + See the example: + :ref:`sphx_glr_auto_examples_decomposition_plot_sparse_coding.py` + """ _parameter_constraints: dict = { From 6a858ffa713b58b843e346cd9f71f87683d37fd8 Mon Sep 17 00:00:00 2001 From: Marciles Matti Date: Thu, 5 Jun 2025 17:52:50 -0400 Subject: [PATCH 2/2] DOC: Clarify example reference for sparse coding in DictionaryLearning and MiniBatchDictionaryLearning --- sklearn/decomposition/_dict_learning.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sklearn/decomposition/_dict_learning.py b/sklearn/decomposition/_dict_learning.py index ad498c3b6c310..4f22f877a0c75 100644 --- a/sklearn/decomposition/_dict_learning.py +++ b/sklearn/decomposition/_dict_learning.py @@ -1597,9 +1597,11 @@ class DictionaryLearning(_BaseSparseCoding, BaseEstimator): >>> np.mean(np.sum((X_hat - X) ** 2, axis=1) / np.sum(X ** 2, axis=1)) np.float64(0.056) - See the example: - :ref:`sphx_glr_auto_examples_decomposition_plot_sparse_coding.py` + .. note:: + The example :ref:`sphx_glr_auto_examples_decomposition_plot_sparse_coding.py` + demonstrates sparse coding with a precomputed dictionary using `SparseCoder`. + This complements `DictionaryLearning`, which learns the dictionary from data. """ _parameter_constraints: dict = { @@ -1963,6 +1965,12 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator): See the example: :ref:`sphx_glr_auto_examples_decomposition_plot_sparse_coding.py` + .. note:: + + The example :ref:`sphx_glr_auto_examples_decomposition_plot_sparse_coding.py` + demonstrates sparse coding with a precomputed dictionary using `SparseCoder`. + While this class learns the dictionary incrementally, the example is useful for + understanding how sparse codes relate to fixed dictionaries. """ _parameter_constraints: dict = {