Dimensionality reduction by preserving clusters and correlations.
Project description
PCC - Dimensionality reduction with very high global structure preservation
pip install pccdr
⭐ This is a python package for dimensionality reduction (DR) with high global structure preservation.
⭐ That means that unlike in popular DR methods like UMAP, the distances between transformed points - will actually mean something.
⭐ Use PCUMAP for simply enhancing the widely used UMAP method with global structure preservation
⭐ Or use it with our own PCC objective that resutls with extremely high global structure preservation, and competitive local structure
(For spearman correlation support, install torchsort (pip install torchsort))
PCC is built on the idea of sampling reference points, meausring distances of all data points from the reference points, and maximizing the correlations of these distances in the high dimensional data, and the transformed low dimensional data.
Usage examples
See examples/macosko.ipynb for more detailed explanation and usage examples.
There are two modes:
Plugging into UMAP, for getting a meaningful transformation where distances between points mean something
Here we use the excellent recent TorchDR library, and add plug in our objective into UMAP.
from pcc import PCUMAP
pcumap_embedding = PCUMAP(device='cuda').fit_transform(X)
PCC as a standalone DR method with a multi task objective
This optimizes a local structure preservation multi task objective that tries to predict which clusters points belong to, as well as global structure preservation loss that maximizes corerlations between distances of all points to sampled reference points.
First, lets cluster the points with different clustering models:
np.random.seed(0)
clusters = []
n_clusters_list = [4, 8, 16, 32, 64]
for n_clusters in n_clusters_list:
kmeans = KMeans(n_clusters=n_clusters, random_state=0, n_init="auto")
cluster_labels = kmeans.fit_predict(X)
clusters.append(cluster_labels)
Then we can call PCC:
pcc_reducer = PCC(num_components=2, num_epochs=2000, num_points=1000, pearson=True,
spearman=False, beta=5, k_epoch=2)
pcc_embedding = pcc_reducer.fit_transform(X, clusters)
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
File details
Details for the file pccdr-1.0.0.tar.gz.
File metadata
- Download URL: pccdr-1.0.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
807f5ced44490c35b7e3d235b8658ddc34abff62be52f24f6f49fb0b3e9f4668
|
|
| MD5 |
e6ad9f169d87fd0b23a9cb5a2bf987ad
|
|
| BLAKE2b-256 |
79b8ed19a91fa82b1cb43bf4e50b8a442fdaa684ba2d0a0d2cea122e01201c69
|