closely finds the closest pairs of points in a dataset
Project description
Closest Pairs :triangular_ruler:
Find the closest pairs in an array.
Getting Started
pip install closely
or install from source:
git clone https://github.com/justinshenk/closest-pairs
cd closely
pip install .
How to use
import closely
# X is an n x m numpy array
pairs, distances = closely.solve(X, n=1)
You can specify how many pairs you want to identify with n
.
Example
import closely
import numpy as np
import matplotlib.pyplot as plt
# Create dataset
X = np.random.random((100,2))
pairs, distance = closely.solve(X, n=1)
# Plot points
z, y = np.split(X, 2, axis=1)
fig, ax = plt.subplots()
ax.scatter(z, y)
for i, txt in enumerate(X):
if i in pairs:
ax.annotate(i, (z[i], y[i]), color='red')
else:
ax.annotate(i, (z[i], y[i]))
Check pairs:
In [10]: pairs
Out[10]:
array([[[ 7],
[16]],
[[96],
[50]]])
Output:
Caveats
closely
will reduce the dimensionality with PCA of your data to two-dimensions for faster processing.
It also removes the first point in a pair if n
>1. In rare cases this leads to false negatives if the data is highly overlapping.
Credit and Explanation
Python code modified from Andriy Lazorenko, packaged and made useful for >2 features by Justin Shenk.
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
closely-0.1.5.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file closely-0.1.5.tar.gz
.
File metadata
- Download URL: closely-0.1.5.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39b8af5bee870e1ada2cc90516aeca4bad97027aa846ddd82b4b03cd3a6769a5 |
|
MD5 | 5af4dd3c06ad82106dab8d2cc335370a |
|
BLAKE2b-256 | 9558efefaf3100a1f7aaa0c493a9264ed478e5b755860e915f7b133a65c4be10 |
File details
Details for the file closely-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: closely-0.1.5-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba55a01b166b024dbd16ebec6e2447ab8f9ad726e3ce1e1de04d28687821b4e6 |
|
MD5 | ce242b860d0f761afe5c55ec3346563f |
|
BLAKE2b-256 | ee1542d1141b345da4ee527e9a69e638f0e406f3c982e45157f214b5994fbdf2 |