Skip to content

Add documentation for the new API #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
61856b3
Create some text to initialize the PR
Nov 21, 2018
d5dd517
DOC: add doc outline
Dec 3, 2018
b54ee34
DOC: Add data visualisation to possible examples
Dec 3, 2018
7495b68
Update documentation outline
Dec 11, 2018
18325cd
Add doc from master
Dec 13, 2018
0ddaee3
DOC: add beginning of doc tree
Dec 17, 2018
e998652
DOC: add some beginning of example to get started with the examples s…
Dec 17, 2018
41b9182
DOC: modify gitignore to ignore auto_examples
Dec 17, 2018
0adb3c0
WIP: add preprocessor section and some section about weakly supervise…
Dec 19, 2018
26306ba
A few style improvements (text wraping to line limit, better referenc…
Dec 19, 2018
4eb8495
Address https://github.com/metric-learn/metric-learn/pull/133#pullreq…
Dec 19, 2018
3db2653
raise instead of return
Dec 20, 2018
813f658
Merge branch 'new_api_design' into doc/add_documentation
Dec 20, 2018
3891b93
Fix quickstart example
Dec 20, 2018
7dcfb54
Emphasize scikit-learn compatibility
Dec 20, 2018
1b83569
Update introduction with new methods
Dec 20, 2018
70f16a9
address https://github.com/metric-learn/metric-learn/pull/133#discuss…
Dec 20, 2018
ed0a00e
explain what happens when preprocessor=None
Dec 20, 2018
868d42b
Precisions in doc about the input accepted by the preprocessor
Dec 20, 2018
1fe3357
address https://github.com/metric-learn/metric-learn/pull/133#discuss…
Dec 20, 2018
ea487b7
Better formulation of sentences
Dec 20, 2018
16ba60a
change title formatting in index
Dec 20, 2018
95f0702
Fix references and some numering issue
Dec 20, 2018
6cb328f
Reformat link to preprocessor
Dec 20, 2018
ff4d30e
Fix automatic link to algorithms for the supervised section
Dec 20, 2018
37cd11c
Reformatting and adding examples about supervised version in the end …
Dec 20, 2018
6eee862
add precisions in the intro
Dec 20, 2018
bee4a8c
add precisions for score_pairs in the intro
Dec 20, 2018
d49ba68
Change examples for weakly supervised section
Dec 20, 2018
202e3fe
add _Supervised section in Supervised section
Dec 20, 2018
c107584
change examples in weakly supervised section
Dec 20, 2018
9de2e9c
fix empty module contents
Dec 20, 2018
1371122
rename sandwich.py into plot_sandwich.py to be found by sphinx-gallery
Dec 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist/
.coverage
htmlcov/
.cache/
doc/auto_examples/*
6 changes: 5 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'sphinx.ext.viewcode',
'sphinx.ext.mathjax',
'numpydoc',
'sphinx_gallery.gen_gallery'
]

templates_path = ['_templates']
Expand All @@ -15,7 +16,7 @@

# General information about the project.
project = u'metric-learn'
copyright = u'2015-2017, CJ Carey and Yuan Tang'
copyright = u'2015-2018, CJ Carey and Yuan Tang'
author = u'CJ Carey and Yuan Tang'
version = '0.4.0'
release = '0.4.0'
Expand All @@ -31,3 +32,6 @@
html_static_path = ['_static']
htmlhelp_basename = 'metric-learndoc'

# Option to only need single backticks to refer to symbols
default_role = 'any'

42 changes: 42 additions & 0 deletions doc/getting_started.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
###############
Getting started
###############

Installation and Setup
======================

Run ``pip install metric-learn`` to download and install from PyPI.

Alternately, download the source repository and run:

- ``python setup.py install`` for default installation.
- ``python setup.py test`` to run all tests.

**Dependencies**

- Python 2.7+, 3.4+
- numpy, scipy, scikit-learn
- (for running the examples only: matplotlib)

**Notes**

If a recent version of the Shogun Python modular (``modshogun``) library
is available, the LMNN implementation will use the fast C++ version from
there. The two implementations differ slightly, and the C++ version is
more complete.


Quick start
===========

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just add a sentence or two to briefly describe what the code snippet does (compute cross validation score of NCA on iris dataset)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I've added a quick description and also modified the example since it didn't work in fact (for now we don't have a scoring for cross-validation on supervised metric learners), so I updated the example with a pipeline nca + knn

This example loads the iris dataset, and evaluates a k-nearest neighbors
algorithm on an embedding space learned with `NCA`.

>>> from metric_learn import NCA
>>> from sklearn.datasets import load_iris
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.pipeline import make_pipeline
>>>
>>> X, y = load_iris(return_X_y=True)
>>> clf = make_pipeline(NCA(), KNeighborsClassifier())
>>> cross_val_score(clf, X, y)
73 changes: 13 additions & 60 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,31 @@ metric-learn: Metric Learning in Python
=======================================
|License| |PyPI version|

Distance metrics are widely used in the machine learning literature.
Traditionally, practicioners would choose a standard distance metric
(Euclidean, City-Block, Cosine, etc.) using a priori knowledge of
the domain.
Distance metric learning (or simply, metric learning) is the sub-field of
machine learning dedicated to automatically constructing optimal distance
metrics.

This package contains efficient Python implementations of several popular
metric learning algorithms.
Welcome to metric-learn's documentation !
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this appears with same title level as the main title (metric-learn: Metric Learning in Python)
better to use lower level / smaller text size

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, done

-----------------------------------------

.. toctree::
:caption: Algorithms
:maxdepth: 1

metric_learn.covariance
metric_learn.lmnn
metric_learn.itml
metric_learn.sdml
metric_learn.lsml
metric_learn.nca
metric_learn.lfda
metric_learn.rca

Each metric supports the following methods:

- ``fit(...)``, which learns the model.
- ``transformer()``, which returns a transformation matrix
:math:`L \in \mathbb{R}^{D \times d}`, which can be used to convert a
data matrix :math:`X \in \mathbb{R}^{n \times d}` to the
:math:`D`-dimensional learned metric space :math:`X L^{\top}`,
in which standard Euclidean distances may be used.
- ``transform(X)``, which applies the aforementioned transformation.
- ``metric()``, which returns a Mahalanobis matrix
:math:`M = L^{\top}L` such that distance between vectors ``x`` and
``y`` can be computed as :math:`\left(x-y\right)M\left(x-y\right)`.
:maxdepth: 2

getting_started

Installation and Setup
======================

Run ``pip install metric-learn`` to download and install from PyPI.

Alternately, download the source repository and run:

- ``python setup.py install`` for default installation.
- ``python setup.py test`` to run all tests.
.. toctree::
:maxdepth: 2

**Dependencies**
user_guide

- Python 2.7+, 3.4+
- numpy, scipy, scikit-learn
- (for running the examples only: matplotlib)
.. toctree::
:maxdepth: 2

**Notes**
Package Overview <metric_learn>

If a recent version of the Shogun Python modular (``modshogun``) library
is available, the LMNN implementation will use the fast C++ version from
there. The two implementations differ slightly, and the C++ version is
more complete.
.. toctree::
:maxdepth: 2

Navigation
----------
auto_examples/index

:ref:`genindex` | :ref:`modindex` | :ref:`search`

.. toctree::
:maxdepth: 4
:hidden:

Package Overview <metric_learn>

.. |PyPI version| image:: https://badge.fury.io/py/metric-learn.svg
:target: http://badge.fury.io/py/metric-learn
.. |License| image:: http://img.shields.io/:license-mit-blue.svg?style=flat
Expand Down
38 changes: 38 additions & 0 deletions doc/introduction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
============
Introduction
============

Distance metrics are widely used in the machine learning literature.
Traditionally, practitioners would choose a standard distance metric
(Euclidean, City-Block, Cosine, etc.) using a priori knowledge of
the domain.
Distance metric learning (or simply, metric learning) is the sub-field of
machine learning dedicated to automatically construct task-specific distance
metrics from (weakly) supervised data.
The learned distance metric often corresponds to a Euclidean distance in a new
embedding space, hence distance metric learning can be seen as a form of
representation learning.

This package contains a efficient Python implementations of several popular
metric learning algorithms, compatible with scikit-learn. This allows to use
all the scikit-learn routines for pipelining and model selection for
metric learning algorithms.


Currently, each metric learning algorithm supports the following methods:

- ``fit(...)``, which learns the model.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a few other generic methods, like score_pairs etc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thanks. I've added score_pairs and replaced transformer() by the newtransformer_from_metric(metric). I didn't put _prepare_inputs since it is private, and neither check_preprocessor because it is public for now but probably should rather be private ?

- ``metric()``, which returns a Mahalanobis matrix
:math:`M = L^{\top}L` such that distance between vectors ``x`` and
``y`` can be computed as :math:`\left(x-y\right)M\left(x-y\right)`.
- ``transformer_from_metric(metric)``, which returns a transformation matrix
:math:`L \in \mathbb{R}^{D \times d}`, which can be used to convert a
data matrix :math:`X \in \mathbb{R}^{n \times d}` to the
:math:`D`-dimensional learned metric space :math:`X L^{\top}`,
in which standard Euclidean distances may be used.
- ``transform(X)``, which applies the aforementioned transformation.
- ``score_pairs(pairs)`` which returns the distance between pairs of
points. ``pairs`` should be a 3D array-like of pairs of shape ``(n_pairs,
2, n_features)``, or it can be a 2D array-like of pairs indicators of
shape ``(n_pairs, 2)`` (see section :ref:`preprocessor_section` for more
details).
1 change: 1 addition & 0 deletions doc/metric_learn.covariance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Covariance metric (baseline method)
:undoc-members:
:inherited-members:
:show-inheritance:
:special-members: __init__

Example Code
------------
Expand Down
1 change: 1 addition & 0 deletions doc/metric_learn.itml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Information Theoretic Metric Learning (ITML)
:undoc-members:
:inherited-members:
:show-inheritance:
:special-members: __init__

Example Code
------------
Expand Down
1 change: 1 addition & 0 deletions doc/metric_learn.lfda.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Local Fisher Discriminant Analysis (LFDA)
:undoc-members:
:inherited-members:
:show-inheritance:
:special-members: __init__

Example Code
------------
Expand Down
1 change: 1 addition & 0 deletions doc/metric_learn.lmnn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Large Margin Nearest Neighbor (LMNN)
:undoc-members:
:inherited-members:
:show-inheritance:
:special-members: __init__

Example Code
------------
Expand Down
1 change: 1 addition & 0 deletions doc/metric_learn.lsml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Least Squares Metric Learning (LSML)
:undoc-members:
:inherited-members:
:show-inheritance:
:special-members: __init__

Example Code
------------
Expand Down
1 change: 1 addition & 0 deletions doc/metric_learn.mlkr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Metric Learning for Kernel Regression (MLKR)
:undoc-members:
:inherited-members:
:show-inheritance:
:special-members: __init__

Example Code
------------
Expand Down
1 change: 1 addition & 0 deletions doc/metric_learn.mmc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Mahalanobis Metric Learning for Clustering (MMC)
:undoc-members:
:inherited-members:
:show-inheritance:
:special-members: __init__

Example Code
------------
Expand Down
1 change: 1 addition & 0 deletions doc/metric_learn.nca.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Neighborhood Components Analysis (NCA)
:undoc-members:
:inherited-members:
:show-inheritance:
:special-members: __init__

Example Code
------------
Expand Down
1 change: 1 addition & 0 deletions doc/metric_learn.rca.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Relative Components Analysis (RCA)
:undoc-members:
:inherited-members:
:show-inheritance:
:special-members: __init__

Example Code
------------
Expand Down
12 changes: 2 additions & 10 deletions doc/metric_learn.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
metric_learn package
====================

Submodules
----------
Module Contents
---------------

.. toctree::

Expand All @@ -16,11 +16,3 @@ Submodules
metric_learn.nca
metric_learn.rca
metric_learn.sdml

Module contents
---------------

.. automodule:: metric_learn
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions doc/metric_learn.sdml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Sparse Determinant Metric Learning (SDML)
:undoc-members:
:inherited-members:
:show-inheritance:
:special-members: __init__

Example Code
------------
Expand Down
Loading