Large Margin Nearest Neighbor implementation in python
Project description
PyLMNN is a python implementation of the Large Margin Nearest Neighbor algorithm for metric learning.
This implementation follows closely the original MATLAB code by Kilian Weinberger found at 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 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
GPy>=1.5.6
GPyOpt>=1.0.3
matplotlib>=1.5.3
Usage
The simplest use case would be something like:
X, y = load_my_data(dataset_name) x_tr, x_te, y_tr, y_te = train_test_split(X, y, train_size=0.5, stratify=y) k_tr, k_te, dim_out, max_iter = 3, 1, X.shape[1], 180 lmnn = LMNN(k=k_tr, max_iter=max_iter, dim_out=dim_out) lmnn = lmnn.fit(x_tr, y_tr) test_acc = test_knn(x_tr, y_tr, x_te, y_te, k=k_te, L=lmnn.L)
You can check the examples directory for examples of how to use the code.
References
If you use this code in your work, please cite the following publication.
@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).
Contact John Chiotellis :envelope: for questions, comments and reporting bugs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file PyLMNN-1.0.1.tar.gz.
File metadata
- Download URL: PyLMNN-1.0.1.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
120e46679217f8b95e668620daf0ad717b0b4d108c3d9de6d22538408539e79c
|
|
| MD5 |
d6ad4258f91a823b479bf4461672c4f5
|
|
| BLAKE2b-256 |
ef390efb54d3cb03b644692276b9cce4b08d3b2c0d376736edd7e52b8ad837cf
|
File details
Details for the file PyLMNN-1.0.1-py3-none-any.whl.
File metadata
- Download URL: PyLMNN-1.0.1-py3-none-any.whl
- Upload date:
- Size: 28.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d98dfd9d6b9e7dee3dd87a0d7c4bcad1b9dcb0a9c46f0f2bec2804188ab6c133
|
|
| MD5 |
5bf08494eac5012545651f156cf52283
|
|
| BLAKE2b-256 |
871fc5e2ce0679b6c1bfe2b22458f2e56b649e5ad490da50a1e8f99c3f9f010b
|