scikit-learn-contrib / scikit-matter

A collection of scikit-learn compatible utilities that implement methods born out of the materials science and chemistry communities
https://scikit-matter.readthedocs.io/en/v0.2.0/
BSD 3-Clause "New" or "Revised" License
76 stars 20 forks source link

Add doctests / inline examples in API reference #90

Open Luthaf opened 3 years ago

Luthaf commented 3 years ago

We already have some end-to-end examples/tutorials. These show how to accomplish a high level goal with this library ("how do I create a projection of my dataset using KPCovR").

It would be nice to also have "inline" examples inside the reference documentation, showing how to use each function separately ("how do I call FPS.fit with warm_start=True"). For a good example of how this would look like, see https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html#sklearn.decomposition.PCA.transform.

The standard tool to add such example in Python is called doctests: one write input code as if there was a python prompt (>>>); and the corresponding output. Then, there are tools to run the input code and check that output match. Check out the corresponding module in python standard library: https://docs.python.org/3/library/doctest.html

The first task for this issue would be to make sure doctests are part of the test suite checked on CI

We already have some classes with such examples (https://scikit-cosmo.readthedocs.io/en/latest/preprocessing.html#skcosmo.preprocessing.flexible_scaler.KernelNormalizer), but I think all classes should come with such a small example.

The second task for this issue would be to add doctests/examples to all classes in skcosmo.

Luthaf commented 1 year ago

Looks like we have examples for most of the functions!

Luthaf commented 1 year ago

Actually, I closed this a bit too fast: we have examples for most functions, but not all of them have doctests.

Here is an example of a doctest, actually checking the output of the code: https://github.com/lab-cosmo/scikit-matter/blob/45cff6a81c9136126518bb621101c53ec6e7565a/src/skmatter/decomposition/_pcovr.py#L174-L193

Here is a list of functions/classes without doctests:

agoscinski commented 1 year ago

PR https://github.com/scikit-learn-contrib/scikit-matter/pull/201 moved examples to doctest for several of them, I ticket the boxes.