-
Notifications
You must be signed in to change notification settings - Fork 228
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
Changes from all commits
61856b3
d5dd517
b54ee34
7495b68
18325cd
0ddaee3
e998652
41b9182
0adb3c0
26306ba
4eb8495
3db2653
813f658
3891b93
7dcfb54
1b83569
70f16a9
ed0a00e
868d42b
1fe3357
ea487b7
16ba60a
95f0702
6cb328f
ff4d30e
37cd11c
6eee862
bee4a8c
d49ba68
202e3fe
c107584
9de2e9c
1371122
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ dist/ | |
.coverage | ||
htmlcov/ | ||
.cache/ | ||
doc/auto_examples/* |
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 | ||
=========== | ||
|
||
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing a few other generic methods, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, thanks. I've added |
||
- ``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). |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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