Skip to main content

Spectral Clustering Using Deep Neural Networks

Project description

SpectralNet

SpectralNet is a Python package that performs spectral clustering with deep neural networks.

This package is based on the following paper - SpectralNet

Installation

You can install the latest package version via

pip install spectralnet

Usage

Clustering

The basic functionality is quite intuitive and easy to use, e.g.,

from spectralnet import SpectralNet

spectralnet = SpectralNet(n_clusters=10)
spectralnet.fit(X) # X is the dataset and it should be a torch.Tensor
cluster_assignments = spectralnet.predict(X) # Get the final assignments to clusters

If you have labels to your dataset and you want to measure ACC and NMI you can do the following:

from spectralnet import SpectralNet
from spectralnet import Metrics


spectralnet = SpectralNet(n_clusters=2)
spectralnet.fit(X, y) # X is the dataset and it should be a torch.Tensor
cluster_assignments = spectralnet.predict(X) # Get the final assignments to clusters

y = y_train.detach().cpu().numpy() # In case your labels are of torch.Tensor type.
acc_score = Metrics.acc_score(cluster_assignments, y, n_clusters=2)
nmi_score = Metrics.nmi_score(cluster_assignments, y)
print(f"ACC: {np.round(acc_score, 3)}")
print(f"NMI: {np.round(nmi_score, 3)}")

You can read the code docs for more information and functionalities

Running examples

In order to run the model on twomoons or MNIST datasets, you should first cd to the examples folder and then run:
python3 cluster_twomoons.py
or
python3 cluster_mnist.py

Citation


@inproceedings{shaham2018,
author = {Uri Shaham and Kelly Stanton and Henri Li and Boaz Nadler and Ronen Basri and Yuval Kluger},
title = {SpectralNet: Spectral Clustering Using Deep Neural Networks},
booktitle = {Proc. ICLR 2018},
year = {2018}
}

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

spectralnet-0.1.2.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

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

spectralnet-0.1.2-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file spectralnet-0.1.2.tar.gz.

File metadata

  • Download URL: spectralnet-0.1.2.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for spectralnet-0.1.2.tar.gz
Algorithm Hash digest
SHA256 72d6cb0d5a8857fd2777774d83264bbce00cf41b7bbe5b245dd3de01ec3498a1
MD5 67598da5609eb68668d1fed7b38ae1d7
BLAKE2b-256 41ec88477758055b802e7989ccb71d9622e73ed4021bb1518b92b8584d5eeb08

See more details on using hashes here.

File details

Details for the file spectralnet-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: spectralnet-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for spectralnet-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 202dd4ed5952cfc46b45f52ebca45c43261d25412c631d0e70f931b6c5172f8d
MD5 b5541d5f707ff3a6cd728337e51768d5
BLAKE2b-256 69237914f792641d340ac63ea86cc32a7237bfa8700e7c70aa3a10040ef2c1a5

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