Skip to content

Commit c2e284e

Browse files
committed
integrating sphinx doctest
1 parent d56ccbd commit c2e284e

File tree

4 files changed

+45
-19
lines changed

4 files changed

+45
-19
lines changed

docs/src/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"sphinx.ext.intersphinx",
4646
"sphinx.ext.napoleon",
4747
"sphinx.ext.viewcode",
48+
"sphinx.ext.doctest",
4849
"sphinx_gallery.gen_gallery",
4950
"sphinx_toggleprompt",
5051
]

docs/src/selection.rst

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,46 @@ where at each iteration the model scores each
1818
feature or sample (without an estimator) and chooses that with the maximum score.
1919
This can be executed using:
2020

21-
.. code-block:: python
22-
23-
selector = Selector(
24-
# the number of selections to make
25-
# if None, set to half the samples or features
26-
# if float, fraction of the total dataset to select
27-
# if int, absolute number of selections to make
28-
n_to_select=4,
29-
# option to use `tqdm <https://tqdm.github.io/>`_ progress bar
30-
progress_bar=True,
31-
# float, cutoff score to stop selecting
32-
score_threshold=1e-12,
33-
# boolean, whether to select randomly after non-redundant selections are exhausted
34-
full=False,
35-
)
36-
selector.fit(X, y)
37-
38-
Xr = selector.transform(X)
21+
.. doctest::
22+
23+
>>> import numpy as np
24+
>>> from skmatter.feature_selection import CUR, FPS, PCovCUR, PCovFPS
25+
>>> selector = CUR(
26+
... # the number of selections to make
27+
... # if None, set to half the samples or features
28+
... # if float, fraction of the total dataset to select
29+
... # if int, absolute number of selections to make
30+
... n_to_select=2,
31+
... # option to use `tqdm <https://tqdm.github.io/>`_ progress bar
32+
... progress_bar=True,
33+
... # float, cutoff score to stop selecting
34+
... score_threshold=1e-12,
35+
... # boolean, whether to select randomly after non-redundant selections
36+
... # are exhausted
37+
... full=False,
38+
... )
39+
>>> X = np.array([[ 0.12, 0.21, 0.02], # 3 samples, 3 features
40+
... [-0.09, 0.32, -0.10],
41+
... [-0.03, -0.53, 0.08]])
42+
>>> y = np.array([0., 0., 1.]) # classes of each sample
43+
>>> selector.fit(X)
44+
CUR(n_to_select=2, progress_bar=True, score_threshold=1e-12)
45+
>>> Xr = selector.transform(X)
46+
>>> print(Xr.shape)
47+
(3, 2)
48+
>>> selector = PCovCUR(n_to_select=2)
49+
>>> selector.fit(X, y)
50+
PCovCUR(n_to_select=2)
51+
>>> Xr = selector.transform(X)
52+
>>> print(Xr.shape)
53+
(3, 2)
54+
>>> from skmatter.sample_selection import CUR, FPS, PCovCUR, PCovFPS
55+
>>> selector = CUR(n_to_select=2)
56+
>>> selector.fit(X)
57+
CUR(n_to_select=2)
58+
>>> Xr = X[selector.selected_idx_]
59+
>>> print(Xr.shape)
60+
(2, 3)
3961

4062
where `Selector` is one of the classes below that overwrites the method
4163
:py:func:`score`.

src/skmatter/decomposition/_pcovr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class PCovR(_BasePCA, LinearModel):
5555
This can be done with the companion preprocessing classes, where
5656
5757
>>> from skmatter.preprocessing import StandardFlexibleScaler as SFS
58+
>>> import numpy as np
5859
>>>
5960
>>> # Set column_wise to True when the columns are relative to one another,
6061
>>> # False otherwise.

tox.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ deps =
7070
-r docs/requirements.txt
7171
# The documentation runs "examples" to produce outputs via sphinx-gallery.
7272
extras = examples
73-
commands = sphinx-build {posargs:-E} -W -b html docs/src docs/build/html
73+
commands =
74+
sphinx-build {posargs:-E} -W -b doctest docs/src docs/build/doctest
75+
sphinx-build {posargs:-E} -W -b html docs/src docs/build/html
7476

7577
[flake8]
7678
max_line_length = 88

0 commit comments

Comments
 (0)