Skip to content

Commit 73851b3

Browse files
DOC - Update documentation (#118)
Co-authored-by: PAB <[email protected]>
1 parent 21c675f commit 73851b3

File tree

12 files changed

+346
-61
lines changed

12 files changed

+346
-61
lines changed

doc/changes/whats_new.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. _whats_new:
2+
3+
What's new
4+
==========
5+
6+
.. currentmodule:: skglm
7+
8+
.. include:: 0.3.rst
9+
10+
.. include:: 0.2.rst
11+
12+
.. include:: 0.1.rst
13+

doc/conf.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
'sphinx.ext.mathjax',
5757
'sphinx_gallery.gen_gallery',
5858
'sphinx.ext.autosectionlabel',
59+
'sphinx_copybutton',
5960
'numpydoc',
6061
'sphinx.ext.linkcode',
6162
'gh_substitutions',
@@ -148,26 +149,44 @@
148149

149150
# The theme to use for HTML and HTML Help pages. See the documentation for
150151
# a list of builtin themes.
151-
html_theme = 'bootstrap'
152+
html_theme = 'furo'
152153

153154
# Theme options are theme-specific and customize the look and feel of a theme
154155
# further. For a list of options available for each theme, see the
155156
# documentation.
156157
html_theme_options = {
157-
'navbar_sidebarrel': False,
158-
'navbar_pagenav': False,
159-
'navbar_links': [
160-
("Examples", "auto_examples/index"),
161-
("API", "api"),
162-
("Add custom datafit", "add_datafit"),
163-
("Add custom penalty", "add_penalty"),
164-
("GitHub", "https://github.com/scikit-learn-contrib/skglm", True)
158+
"light_css_variables": {
159+
"color-brand-primary": "#b91c1c",
160+
"color-brand-content": "#b91c1c",
161+
"font-stack": 'ui-sans-serif, system-ui',
162+
"color-background-secondary": "#fef2f2"
163+
},
164+
"dark_css_variables": {
165+
"color-brand-primary": "#f87171",
166+
"color-brand-content": "#f87171",
167+
},
168+
"footer_icons": [
169+
{
170+
"name": "GitHub",
171+
"url": "https://github.com/scikit-learn-contrib/skglm",
172+
"html": """
173+
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
174+
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
175+
</svg>
176+
""",
177+
"class": "",
178+
},
165179
],
166-
'bootswatch_theme': "united"
167180
}
168181

182+
# -- Options for copybutton ---------------------------------------------
183+
# complete explanation of the regex expression can be found here
184+
# https://sphinx-copybutton.readthedocs.io/en/latest/use.html#using-regexp-prompt-identifiers
185+
copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
186+
copybutton_prompt_is_regexp = True
187+
169188
# Add any paths that contain custom themes here, relative to this directory.
170-
html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
189+
# html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
171190

172191
# The name for this set of Sphinx documents. If None, it defaults to
173192
# "<project> v<release> documentation".

doc/contribute.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.. _contribute:
2+
3+
Contribute to ``skglm``
4+
=======================
5+
-----------------------
6+
7+
8+
``skglm`` is a continuous endeavour that relies on the community efforts to last and evolve.
9+
Your contribution is welcome and highly valuable. It can be
10+
11+
**bug report**
12+
``skglm`` runs continuously unit tests on the code base to prevent bugs.
13+
Help us tighten these tests by reporting any bug that you encountered while using ``skglm``.
14+
To do so, use the `issue section <https://github.com/scikit-learn-contrib/skglm/issues>`_ ``skglm`` repository.
15+
16+
**feature request**
17+
We are constantly improving ``skglm`` and we would like to align that with the user needs.
18+
We highly appreciate any suggestion to extend or add new features to ``skglm``.
19+
You can use the `the issue section <https://github.com/scikit-learn-contrib/skglm/issues>`_ to make suggestions.
20+
21+
**pull request**
22+
you may have fixed a bug, added a feature, or even fixed a small typo in the documentation, ...
23+
You can submit a `pull request <https://github.com/scikit-learn-contrib/skglm/pulls>`_
24+
to integrate your changes and we will reach out to you shortly.
25+
26+
.. note::
27+
28+
- If you are willing to contribute with code to ``skglm``, check the section below to learn how to install
29+
the development version of ``skglm``
30+
31+
32+
33+
Setup ``skglm`` on your local machine
34+
---------------------------------------
35+
36+
Here are key steps to help you setup ``skglm`` on your local machine in case you wanted to
37+
contribute with code or documentation.
38+
39+
1. Fork the repository and run the following command to clone it on your local machine
40+
41+
.. code-block:: shell
42+
43+
$ git clone https://github.com/{YOUR_GITHUB_USERNAME}/skglm.git
44+
45+
46+
2. ``cd`` to ``skglm`` directory and install it in edit mode by running
47+
48+
.. code-block:: shell
49+
50+
$ cd skglm
51+
$ pip install -e .
52+
53+
54+
3. To run the gallery of examples and build the documentation, run
55+
56+
.. code-block:: shell
57+
58+
$ cd doc
59+
$ pip install -r doc-requirements.txt
60+
$ make html

doc/doc-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ myst_parser
55
numpydoc
66
pillow
77
sphinx-bootstrap-theme
8+
sphinx_copybutton
89
sphinx-gallery
910
pytest
11+
furo

doc/getting_started.rst

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
.. _getting_started:
2+
3+
===============
4+
Getting started
5+
===============
6+
---------------
7+
8+
This page provides a starter example to get familiar with ``skglm`` and explore some of its features.
9+
10+
In the first section, we fit a Lasso estimator on a high dimensional
11+
toy dataset (number of features is largely greater than the number of samples). Linear models don't generalize well
12+
for unseen dataset. By adding a penalty, :math:`\ell_1` penalty, we can train estimator that overcome this drawback.
13+
14+
The last section, we explore other combinations of datafit and penalty to create a custom estimator that achieves a lower prediction error,
15+
in the sequel :math:`\ell_1` Huber regression. We show that ``skglm`` is perfectly adapted to these experiments thanks to its modular design.
16+
17+
Beforehand, make sure that you have already installed ``skglm``
18+
19+
.. code-block:: shell
20+
21+
# using pip
22+
pip install -U skglm
23+
24+
# using conda
25+
conda install skglm
26+
27+
-------------------------
28+
29+
30+
Fitting a Lasso estimator
31+
-------------------------
32+
33+
Let's start first by generating a toy dataset and splitting it to train and test sets.
34+
For that, we will use ``scikit-learn``
35+
`make_regression <https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_regression.html#sklearn.datasets.make_regression>`_
36+
37+
.. code-block:: python
38+
39+
# imports
40+
from sklearn.datasets import make_regression
41+
from sklearn.model_selection import train_test_split
42+
43+
# generate toy data
44+
X, y = make_regression(n_samples=100, n_features=1000)
45+
46+
# split data
47+
X_train, X_test, y_train, y_test = train_test_split(X, y)
48+
49+
Then let's fit ``skglm`` :ref:`Lasso <skglm.Lasso>` estimator and prints its score on the test set.
50+
51+
.. code-block:: python
52+
53+
# import estimator
54+
from skglm import Lasso
55+
56+
# init and fit
57+
estimator = Lasso()
58+
estimator.fit(X_train, y_train)
59+
60+
# compute R²
61+
estimator.score(X_test, y_test)
62+
63+
64+
.. note::
65+
66+
- The first fit after importing ``skglm`` has an overhead as ``skglm`` uses `Numba <https://numba.pydata.org/>`_
67+
The subsequent fits will achieve top speed since Numba compilation is cached.
68+
69+
``skglm`` has several other ``scikit-learn`` compatible estimators.
70+
Check the :ref:`API <Estimators>` for more information about the available estimators.
71+
72+
73+
Fitting :math:`\ell_1` Huber regression
74+
---------------------------------------
75+
76+
Suppose that the latter dataset contains outliers and we would like to mitigate their effects on the learned coefficients
77+
while having an estimator that generalizes well to unseen data. Ideally, we would like to fit a :math:`\ell_1` Huber regressor.
78+
79+
``skglm`` offers high flexibility to compose custom estimators. Through a simple API, it is possible to combine any
80+
``skglm`` :ref:`datafit <Datafits>` and :ref:`penalty <Penalties>`.
81+
82+
.. note::
83+
84+
- :math:`\ell_1` regularization is not supported in ``scikit-learn`` for HuberRegressor
85+
86+
Let's explore how to achieve that.
87+
88+
89+
Generate corrupt data
90+
*********************
91+
92+
We will use the same script as before except that we will take 10 samples and corrupt their values.
93+
94+
.. code-block:: python
95+
96+
# imports
97+
import numpy as np
98+
from sklearn.datasets import make_regression
99+
from sklearn.model_selection import train_test_split
100+
101+
# generate toy data
102+
X, y = make_regression(n_samples=100, n_features=1000)
103+
104+
# select and corrupt 10 random samples
105+
y[np.random.choice(n_samples, 10)] = 100 * y.max()
106+
107+
# split data
108+
X_train, X_test, y_train, y_test = train_test_split(X, y)
109+
110+
111+
Now let's compose a custom estimator using :ref:`GeneralizedLinearEstimator <skglm.GeneralizedLinearEstimator>`.
112+
It's the go-to way to create custom estimator by combining a datafit and a penalty.
113+
114+
.. code-block:: python
115+
116+
# import penalty and datafit
117+
from skglm.penalties import L1
118+
from skglm.datafits import Huber
119+
120+
# import GLM estimator
121+
from skglm import GeneralizedLinearEstimator
122+
123+
# build and fit estimator
124+
estimator = GeneralizedLinearEstimator(
125+
Huber(1.),
126+
L1(alpha=1.)
127+
)
128+
estimator.fit(X_train, y_train)
129+
130+
131+
.. note::
132+
133+
- Here the arguments given to the datafit and penalty are arbitrary and given just for sake of illustration.
134+
135+
``GeneralizedLinearEstimator`` allows to combine any penalties and datafits implemented in ``skglm``.
136+
If you don't find an estimator in the ``estimators`` module, you can build it by combining the appropriate datafit and penalty
137+
and pass it to ``GeneralizedLinearEstimator``. Explore the list of supported :ref:`datafits <Datafits>` and :ref:`penalties <Penalties>`.
138+
139+
.. important::
140+
141+
- It is possible to create your own datafit and penalties. Check the tutorials on :ref:`how to add a custom datafit <how_to_add_custom_datafit>`
142+
and :ref:`how to add a custom penalty <how_to_add_custom_penalty>`.
143+
144+
145+
Explore further advanced topics and get hands-on examples on the :ref:`tutorials page <tutorials>`

0 commit comments

Comments
 (0)