Skip to main content

LMNN implementation in python

Project description

# pylmnn

**pylmnn** is a python implementation of the [Large Margin Nearest Neighbor](#paper) algorithm for metric learning.

This implementation follows closely the original MATLAB code by Kilian Weinberger found at [https://bitbucket.org/mlcircus/lmnn](https://bitbucket.org/mlcircus/lmnn). This version solves the unconstrained optimisation problem and finds a linear transformation using L-BFGS as the backend optimizer.

This package also uses Bayesian Optimization to find the optimal hyper-parameters for LMNN using the excellent [GPyOpt](http://github.com/SheffieldML/GPyOpt) package.


#### Installation

The code was developed in python 3.5 under Ubuntu 16.04. You can clone the repo with:
```
git clone https://github.com/johny-c/pylmnn.git
```

or install it via pip:
```
pip3 install pylmnn
```

#### Dependencies

* numpy>=1.11.2
* scipy>=0.18.1
* scikit_learn>=0.18.1
* GPyOpt>=1.0.3
* matplotlib>=1.5.3

#### Usage

The simplest use case would be something like:

X, y = load_my_data(dataset_name)
xtr, xte, ytr, yte = train_test_split(X, y, train_size=0.5, stratify=y)
Klmnn, Knn, outdim, maxiter = 3, 1, X.shape[1], 180
lmnn = LMNN(verbose=True, k=Klmnn, max_iter=maxiter, outdim=outdim)
lmnn, loss, details = lmnn.fit(xtr, ytr)
test_acc = test_knn(xtr, ytr, xte, yte, k=Knn, L=lmnn.L)

You can check the examples directory for examples of how to use the code.

#### Disclaimer

This is still under development. The current version of the code is fast but can be very memory hungry.

#### References

If you use this code in your work, please cite the following <a name="paper">publication</a>.

@ARTICLE{weinberger09distance,
title={Distance metric learning for large margin nearest neighbor classification},
author={Weinberger, K.Q. and Saul, L.K.},
journal={The Journal of Machine Learning Research},
volume={10},
pages={207--244},
year={2009},
publisher={MIT Press}
}


#### License and Contact

This work is released under the [GNU General Public License Version 3 (GPLv3)](http://www.gnu.org/licenses/gpl.html).

Contact **John Chiotellis** [:envelope:](mailto:johnyc.code@gmail.com) for questions, comments and reporting bugs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyLMNN-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyLMNN-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file PyLMNN-0.1.0.tar.gz.

File metadata

  • Download URL: PyLMNN-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyLMNN-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8966d4ffe3d5525406b4c061fee5fdbe1ddb897d725a7fafd84cdd06d0058de6
MD5 f8fe72937aa4623fe85a665764cfd19d
BLAKE2b-256 81027712c8d093cbfc2bdff70baaca90b0d3ebc94f11fea999c6429ea384d22a

See more details on using hashes here.

File details

Details for the file PyLMNN-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for PyLMNN-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90ecea13de260687388fbad1c3ff1924d8a2f41cb02668f0453fe4bdf65073bc
MD5 ef0193951281526f1095d32b6365b54e
BLAKE2b-256 81abeb727004d7a0d7ad931ff60ab5352d7ff39e272395f0586d24e6221ef5ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page