Skip to content

Commit 40169b9

Browse files
Merge pull request scikit-learn#4658 from Titan-C/sphx-glr
[MRG+2] Sphinx-gallery use
2 parents 2a9492b + acef8cd commit 40169b9

File tree

73 files changed

+2204
-1656
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2204
-1656
lines changed

doc/conf.py

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,18 @@
2424
sys.path.insert(0, os.path.abspath('sphinxext'))
2525

2626
from github_link import make_linkcode_resolve
27+
import sphinx_gallery
2728

2829
# -- General configuration ---------------------------------------------------
2930

30-
# Try to override the matplotlib configuration as early as possible
31-
try:
32-
import gen_rst
33-
except:
34-
pass
35-
3631
# Add any Sphinx extension module names here, as strings. They can be
3732
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
38-
extensions = ['gen_rst',
39-
'sphinx.ext.autodoc', 'sphinx.ext.autosummary',
40-
'sphinx.ext.pngmath', 'numpy_ext.numpydoc',
41-
'sphinx.ext.linkcode', 'sphinx.ext.doctest',
42-
]
43-
44-
autosummary_generate = True
33+
extensions = [
34+
'sphinx.ext.autodoc', 'sphinx.ext.autosummary',
35+
'sphinx.ext.pngmath', 'numpy_ext.numpydoc',
36+
'sphinx.ext.linkcode', 'sphinx.ext.doctest',
37+
'sphinx_gallery.gen_gallery',
38+
]
4539

4640
autodoc_default_flags = ['members', 'inherited-members']
4741

@@ -230,20 +224,46 @@
230224
trim_doctests_flags = True
231225

232226

233-
def generate_example_rst(app, what, name, obj, options, lines):
234-
# generate empty examples files, so that we don't get
235-
# inclusion errors if there are no examples for a class / module
236-
examples_path = os.path.join(app.srcdir, "modules", "generated",
237-
"%s.examples" % name)
238-
if not os.path.exists(examples_path):
239-
# touch file
240-
open(examples_path, 'w').close()
227+
sphinx_gallery_conf = {
228+
'doc_module': 'sklearn',
229+
'reference_url': {
230+
'sklearn': None,
231+
'matplotlib': 'http://matplotlib.org',
232+
'numpy': 'http://docs.scipy.org/doc/numpy-1.6.0',
233+
'scipy': 'http://docs.scipy.org/doc/scipy-0.11.0/reference',
234+
'nibabel': 'http://nipy.org/nibabel'}
235+
}
236+
237+
238+
# The following dictionary contains the information used to create the
239+
# thumbnails for the front page of the scikit-learn home page.
240+
# key: first image in set
241+
# values: (number of plot in set, height of thumbnail)
242+
carousel_thumbs = {'sphx_glr_plot_classifier_comparison_001.png': 600,
243+
'sphx_glr_plot_outlier_detection_003.png': 372,
244+
'sphx_glr_plot_gpr_co2_001.png': 350,
245+
'sphx_glr_plot_adaboost_twoclass_001.png': 372,
246+
'sphx_glr_plot_compare_methods_001.png': 349}
247+
248+
249+
def make_carousel_thumbs(app, exception):
250+
"""produces the final resized carousel images"""
251+
if exception is not None:
252+
return
253+
print('Preparing carousel images')
254+
255+
image_dir = os.path.join(app.builder.outdir, '_images')
256+
for glr_plot, max_width in carousel_thumbs.items():
257+
image = os.path.join(image_dir, glr_plot)
258+
if os.path.exists(image):
259+
c_thumb = os.path.join(image_dir, glr_plot[:-4] + '_carousel.png')
260+
sphinx_gallery.gen_rst.scale_image(image, c_thumb, max_width, 190)
241261

242262

243263
def setup(app):
244264
# to hide/show the prompt in code examples:
245265
app.add_javascript('js/copybutton.js')
246-
app.connect('autodoc-process-docstring', generate_example_rst)
266+
app.connect('build-finished', make_carousel_thumbs)
247267

248268

249269
# The following is used by sphinx.ext.linkcode to provide links to github

doc/datasets/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ and pipeline on 2D data.
8282
load_sample_images
8383
load_sample_image
8484

85-
.. image:: ../auto_examples/cluster/images/plot_color_quantization_001.png
85+
.. image:: ../auto_examples/cluster/images/sphx_glr_plot_color_quantization_001.png
8686
:target: ../auto_examples/cluster/plot_color_quantization.html
8787
:scale: 30
8888
:align: right
@@ -98,7 +98,7 @@ and pipeline on 2D data.
9898

9999
.. topic:: Examples:
100100

101-
* :ref:`example_cluster_plot_color_quantization.py`
101+
* :ref:`sphx_glr_auto_examples_cluster_plot_color_quantization.py`
102102

103103

104104
.. _sample_generators:
@@ -130,7 +130,7 @@ per class; and linear transformations of the feature space.
130130
near-equal-size classes separated by concentric hyperspheres.
131131
:func:`make_hastie_10_2` generates a similar binary, 10-dimensional problem.
132132

133-
.. image:: ../auto_examples/datasets/images/plot_random_dataset_001.png
133+
.. image:: ../auto_examples/datasets/images/sphx_glr_plot_random_dataset_001.png
134134
:target: ../auto_examples/datasets/plot_random_dataset.html
135135
:scale: 50
136136
:align: center
@@ -159,7 +159,7 @@ respect to true bag-of-words mixtures include:
159159
* Documents without labels words at random, rather than from a base
160160
distribution.
161161

162-
.. image:: ../auto_examples/datasets/images/plot_random_multilabel_dataset_001.png
162+
.. image:: ../auto_examples/datasets/images/sphx_glr_plot_random_multilabel_dataset_001.png
163163
:target: ../auto_examples/datasets/plot_random_multilabel_dataset.html
164164
:scale: 50
165165
:align: center

doc/datasets/labeled_faces.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ an evaluation ``10_folds`` set meant to compute performance metrics using a
115115
Examples
116116
--------
117117

118-
:ref:`example_applications_face_recognition.py`
118+
:ref:`sphx_glr_auto_examples_applications_face_recognition.py`

doc/datasets/twenty_newsgroups.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ which is fast to train and achieves a decent F-score::
135135
>>> metrics.f1_score(newsgroups_test.target, pred, average='macro')
136136
0.88213592402729568
137137

138-
(The example :ref:`example_text_document_classification_20newsgroups.py` shuffles
138+
(The example :ref:`sphx_glr_auto_examples_text_document_classification_20newsgroups.py` shuffles
139139
the training and test data, instead of segmenting by time, and in that case
140140
multinomial Naive Bayes gets a much higher F-score of 0.88. Are you suspicious
141141
yet of what's going on inside this classifier?)
@@ -201,7 +201,7 @@ It loses even more if we also strip this metadata from the training data:
201201
0.76995175184521725
202202

203203
Some other classifiers cope better with this harder version of the task. Try
204-
running :ref:`example_model_selection_grid_search_text_feature_extraction.py` with and without
204+
running :ref:`sphx_glr_auto_examples_model_selection_grid_search_text_feature_extraction.py` with and without
205205
the ``--filter`` option to compare the results.
206206

207207
.. topic:: Recommendation
@@ -213,6 +213,6 @@ the ``--filter`` option to compare the results.
213213

214214
.. topic:: Examples
215215

216-
* :ref:`example_model_selection_grid_search_text_feature_extraction.py`
216+
* :ref:`sphx_glr_auto_examples_model_selection_grid_search_text_feature_extraction.py`
217217

218-
* :ref:`example_text_document_classification_20newsgroups.py`
218+
* :ref:`sphx_glr_auto_examples_text_document_classification_20newsgroups.py`

doc/developers/performance.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ for interactively exploring the relevant part for the code.
127127

128128
Suppose we want to profile the Non Negative Matrix Factorization module
129129
of the scikit. Let us setup a new IPython session and load the digits
130-
dataset and as in the :ref:`example_classification_plot_digits_classification.py` example::
130+
dataset and as in the :ref:`sphx_glr_auto_examples_classification_plot_digits_classification.py` example::
131131

132132
In [1]: from sklearn.decomposition import NMF
133133

doc/modules/biclustering.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ biclusters on the diagonal. Here is an example of this structure
4444
where biclusters have higher average values than the other rows and
4545
columns:
4646

47-
.. figure:: ../auto_examples/bicluster/images/plot_spectral_coclustering_003.png
48-
:target: ../auto_examples/bicluster/images/plot_spectral_coclustering_003.png
47+
.. figure:: ../auto_examples/bicluster/images/sphx_glr_plot_spectral_coclustering_003.png
48+
:target: ../auto_examples/bicluster/images/sphx_glr_plot_spectral_coclustering_003.png
4949
:align: center
5050
:scale: 50
5151

@@ -56,8 +56,8 @@ each column belongs to all row clusters. Here is an example of this
5656
structure where the variance of the values within each bicluster is
5757
small:
5858

59-
.. figure:: ../auto_examples/bicluster/images/plot_spectral_biclustering_003.png
60-
:target: ../auto_examples/bicluster/images/plot_spectral_biclustering_003.png
59+
.. figure:: ../auto_examples/bicluster/images/sphx_glr_plot_spectral_biclustering_003.png
60+
:target: ../auto_examples/bicluster/images/sphx_glr_plot_spectral_biclustering_003.png
6161
:align: center
6262
:scale: 50
6363

@@ -150,11 +150,11 @@ and the remaining ``n_columns`` labels provide the column partitioning.
150150

151151
.. topic:: Examples:
152152

153-
* :ref:`example_bicluster_plot_spectral_coclustering.py`: A simple example
153+
* :ref:`sphx_glr_auto_examples_bicluster_plot_spectral_coclustering.py`: A simple example
154154
showing how to generate a data matrix with biclusters and apply
155155
this method to it.
156156

157-
* :ref:`example_bicluster_bicluster_newsgroups.py`: An example of finding
157+
* :ref:`sphx_glr_auto_examples_bicluster_bicluster_newsgroups.py`: An example of finding
158158
biclusters in the twenty newsgroup dataset.
159159

160160

@@ -237,7 +237,7 @@ clustering this :math:`n \times q` matrix yields the column labels.
237237

238238
.. topic:: Examples:
239239

240-
* :ref:`example_bicluster_plot_spectral_biclustering.py`: a simple example
240+
* :ref:`sphx_glr_auto_examples_bicluster_plot_spectral_biclustering.py`: a simple example
241241
showing how to generate a checkerboard matrix and bicluster it.
242242

243243

doc/modules/calibration.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ such that among the samples to which it gave a predict_proba value close to 0.8,
2222
approximately 80% actually belong to the positive class. The following plot compares
2323
how well the probabilistic predictions of different classifiers are calibrated:
2424

25-
.. figure:: ../auto_examples/calibration/images/plot_compare_calibration_001.png
25+
.. figure:: ../auto_examples/calibration/images/sphx_glr_plot_compare_calibration_001.png
2626
:target: ../auto_examples/calibration/plot_compare_calibration.html
2727
:align: center
2828

@@ -87,7 +87,7 @@ The first image present a dataset with 2 classes and 3 blobs of
8787
data. The blob in the middle contains random samples of each class.
8888
The probability for the samples in this blob should be 0.5.
8989

90-
.. figure:: ../auto_examples/calibration/images/plot_calibration_001.png
90+
.. figure:: ../auto_examples/calibration/images/sphx_glr_plot_calibration_001.png
9191
:target: ../auto_examples/calibration/plot_calibration.html
9292
:align: center
9393

@@ -98,7 +98,7 @@ calibration. One can observe that the non-parametric model
9898
provides the most accurate probability estimates for samples
9999
in the middle, i.e., 0.5.
100100

101-
.. figure:: ../auto_examples/calibration/images/plot_calibration_002.png
101+
.. figure:: ../auto_examples/calibration/images/sphx_glr_plot_calibration_002.png
102102
:target: ../auto_examples/calibration/plot_calibration.html
103103
:align: center
104104

@@ -113,7 +113,7 @@ both isotonic calibration and sigmoid calibration. The calibration performance
113113
is evaluated with Brier score :func:`brier_score_loss`, reported in the legend
114114
(the smaller the better).
115115

116-
.. figure:: ../auto_examples/calibration/images/plot_calibration_curve_002.png
116+
.. figure:: ../auto_examples/calibration/images/sphx_glr_plot_calibration_curve_002.png
117117
:target: ../auto_examples/calibration/plot_calibration_curve.html
118118
:align: center
119119

@@ -126,7 +126,7 @@ kinds of calibration can fix this issue and yield nearly identical results.
126126
The next figure shows the calibration curve of Gaussian naive Bayes on
127127
the same data, with both kinds of calibration and also without calibration.
128128

129-
.. figure:: ../auto_examples/calibration/images/plot_calibration_curve_001.png
129+
.. figure:: ../auto_examples/calibration/images/sphx_glr_plot_calibration_curve_001.png
130130
:target: ../auto_examples/calibration/plot_calibration_curve.html
131131
:align: center
132132

@@ -167,7 +167,7 @@ probability vectors predicted by the same classifier after sigmoid calibration
167167
on a hold-out validation set. Colors indicate the true class of an instance
168168
(red: class 1, green: class 2, blue: class 3).
169169

170-
.. figure:: ../auto_examples/calibration/images/plot_calibration_multiclass_000.png
170+
.. figure:: ../auto_examples/calibration/images/sphx_glr_plot_calibration_multiclass_000.png
171171
:target: ../auto_examples/calibration/plot_calibration_multiclass.html
172172
:align: center
173173

@@ -179,7 +179,7 @@ method='sigmoid' on the remaining 200 datapoints reduces the confidence of the
179179
predictions, i.e., moves the probability vectors from the edges of the simplex
180180
towards the center:
181181

182-
.. figure:: ../auto_examples/calibration/images/plot_calibration_multiclass_001.png
182+
.. figure:: ../auto_examples/calibration/images/sphx_glr_plot_calibration_multiclass_001.png
183183
:target: ../auto_examples/calibration/plot_calibration_multiclass.html
184184
:align: center
185185

0 commit comments

Comments
 (0)