Code Monkey home page Code Monkey logo

gagolews / genieclust Goto Github PK

View Code? Open in Web Editor NEW
58.0 7.0 10.0 68.37 MB

Genie: Fast and Robust Hierarchical Clustering with Noise Point Detection - in Python and R

Home Page: https://genieclust.gagolewski.com

License: Other

Python 21.38% C++ 39.52% Makefile 0.68% R 8.90% Batchfile 0.11% Smarty 0.01% TeX 1.71% CSS 5.85% HTML 0.99% Cython 20.46% Shell 0.41%
clustering-algorithm cluster-analysis python3 hdbscan python machine-learning-algorithms nmslib mlpack sparse hierarchical-clustering-algorithm

genieclust's Introduction

genieclust Package for R and Python

Genie: Fast and Robust Hierarchical Clustering with Noise Point Detection

genieclust for Python genieclust for R

Genie finds meaningful clusters quickly – even on large data sets.

A comprehensive tutorial, benchmarks, and a reference manual is available at https://genieclust.gagolewski.com/.

When using genieclust in research publications, please cite (Gagolewski, 2021) and (Gagolewski, Bartoszuk, Cena, 2016) as specified below. Thank you.

About

A faster and more powerful version of Genie – a robust and outlier resistant clustering algorithm (see Gagolewski, Bartoszuk, Cena, 2016), originally included in the R package genie.

The idea behind Genie is beautifully simple. First, make each individual point the only member of its own cluster. Then, keep merging pairs of the closest clusters, one after another. However, to prevent the formation of clusters of highly imbalanced sizes a point group of the smallest size will sometimes be matched with its nearest neighbour.

Genie's appealing simplicity goes hand in hand with its usability; it often outperforms other clustering approaches such as K-means, BIRCH, or average, Ward, and complete linkage on benchmark data. Of course, there is no, nor will there ever be, a single best universal clustering approach for every kind of problem, but Genie is definitely worth a try!

Thanks to its being based on minimal spanning trees of the pairwise distance graphs, Genie is also very fast – determining the whole cluster hierarchy for datasets of millions of points can be completed within minutes. Therefore, it is nicely suited for solving extreme clustering tasks (large datasets with any number of clusters to detect) for data (also sparse) that fit into memory. Thanks to the use of nmslib (if available), sparse or string inputs are also supported.

It also allows clustering with respect to mutual reachability distances so that it can act as a noise point detector or a robustified version of HDBSCAN* (see Campello et al., 2013) that is able to detect a predefined number of clusters and hence it doesn't dependent on the DBSCAN's somewhat difficult-to-set eps parameter.

The package also features an implementation of economic inequality indices (the Gini, Bonferroni index), external cluster validity measures (e.g., the normalised clustering accuracy and partition similarity scores such as the adjusted Rand, Fowlkes-Mallows, adjusted mutual information, and the pair sets index), and internal cluster validity indices (e.g., the Calinski-Harabasz, Davies-Bouldin, Ball-Hall, Silhouette, and generalised Dunn indices).

Author and Contributors

Author and Maintainer: Marek Gagolewski

Contributors: Maciej Bartoszuk, Anna Cena (R packages genie and CVI), Peter M. Larsen (rectangular_lsap).

Examples, Tutorials, and Documentation

R's interface is compatible with stats::hclust(), but there is more.

X <- ... # some data
h <- gclust(X)
plot(h) # plot cluster dendrogram
cutree(h, k=2)
# or genie(X, k=2)

To learn more about R, check out Marek's open-access (free!) textbook Deep R Programming.

The Python language version of genieclust has a familiar scikit-learn-like look-and-feel:

import genieclust
X = ... # some data
g = genieclust.Genie(n_clusters=2)
labels = g.fit_predict(X)

Tutorials and the package documentation are available here.

To learn more about Python, check out Marek's recent open-access (free!) textbook Minimalist Data Wrangling in Python.

How to Install

Python Version

To install via pip (see PyPI):

pip3 install genieclust

The package requires Python 3.7+ together with cython as well as numpy, scipy, matplotlib, and scikit-learn. Optional dependencies: nmslib and mlpack.

R Version

To install the most recent release, call:

install.packages("genieclust")

See the package entry on CRAN.

Other

The core functionality is implemented in the form of a header-only C++ library. It can thus be easily adapted for use in other environments.

Any contributions are welcome (e.g., Julia, Matlab, ...).

License

Copyright (C) 2018–2024 Marek Gagolewski https://www.gagolewski.com/

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License Version 3, 19 November 2007, published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License Version 3 for more details. You should have received a copy of the License along with this program. If not, see (https://www.gnu.org/licenses/).


The file src/c_scipy_rectangular_lsap.h is adapted from the scipy project (https://scipy.org/scipylib), source: /scipy/optimize/rectangular_lsap/rectangular_lsap.cpp. Author: Peter M. Larsen. Distributed under the BSD-3-Clause license.

The implementation of internal cluster validity measures were adapted from our previous project (Gagolewski, Bartoszuk, Cena, 2021); see optim_cvi. Originally distributed under the GNU Affero General Public License Version 3.

References

Gagolewski M., genieclust: Fast and robust hierarchical clustering, SoftwareX 15, 2021, 100722. DOI: 10.1016/j.softx.2021.100722. https://genieclust.gagolewski.com/.

Gagolewski M., Bartoszuk M., Cena A., Genie: A new, fast, and outlier-resistant hierarchical clustering algorithm, Information Sciences 363, 2016, 8–23. DOI: 10.1016/j.ins.2016.05.003.

Gagolewski M., Bartoszuk M., Cena A., Are cluster validity measures (in)valid?, Information Sciences 581, 2021, 620–636. DOI: 10.1016/j.ins.2021.10.004.

Gagolewski M., Cena A., Bartoszuk M., Brzozowski L., Clustering with minimum spanning trees: How good can it be?, 2023, under review (preprint), DOI: 10.48550/arXiv.2303.05679.

Gagolewski M., Normalised clustering accuracy: An asymmetric external cluster validity measure, 2023, under review (preprint), DOI: 10.48550/arXiv.2209.02935.

Gagolewski M., A framework for benchmarking clustering algorithms, SoftwareX 20, 2022, 101270. DOI: 10.1016/j.softx.2022.101270. https://clustering-benchmarks.gagolewski.com/.

Campello R.J.G.B., Moulavi D., Sander J., Density-based clustering based on hierarchical density estimates, Lecture Notes in Computer Science 7819, 2013, 160–172. DOI: 10.1007/978-3-642-37456-2_14.

Mueller A., Nowozin S., Lampert C.H., Information theoretic clustering using minimum spanning trees, DAGM-OAGM, 2012.

Rezaei M., Fränti P., Set matching measures for external cluster validity, IEEE Transactions on Knowledge and Data Engineering 28(8), 2016, 2173–2186 DOI: 10.1109/TKDE.2016.2551240.

See the package's homepage for more references.

genieclust's People

Contributors

dicorynia avatar gagolews avatar gokceneraslan avatar mrucker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

genieclust's Issues

new_merge + tests

seek first pair of sets that yields g <= threshold, otherwise, choose arg min g

exception handling in rcpp

> genieclust::adjusted_rand_score(c("a", "b"), 1:2)
Not compatible with requested type: [type=character; target=integer].Aborted (core dumped)

OWA-based linkages

Add support for the "smoothed" single linkage (OWAs over few nearest neighbours) as described in our manuscript submitted for publication in Information Sciences.

cache intermediate results to make the next call to fit() faster

Computing mst_dist, mst_ind is the slowest part

Getting nn_dist, nn_ind (needed to compute d_core before mst_dist, mst_ind) is also slow (M>1)

compute_full_tree, postprocess, gini_threshold, n_clusters are only applied after mst_dist, mst_ind are computed

Changing X, M, affinity, cast_float32, exact require mst_dist, mst_ind be recomputed

However, decreasing M only does not invalidate nn_dist, nn_ind - at least d_core could be generated faster.

apply_genie(), apply_gic(): return a hierarchy, not a k-partition

https://github.com/gagolews/genie/blob/master/src/hclust2_result.h
https://github.com/gagolews/genie/blob/master/src/hclust2_result.cpp

merge matrix

?hclust Value in R

 merge: an n-1 by 2 matrix.  Row i of ‘merge’ describes the merging
          of clusters at step i of the clustering.  If an element j in
          the row is negative, then observation -j was merged at this
          stage.  If j is positive then the merge was with the cluster
          formed at the (earlier) stage j of the algorithm.  Thus
          negative entries in ‘merge’ indicate agglomerations of
          singletons, and positive entries indicate agglomerations of
          non-singletons.

  height: a set of n-1 real values (non-decreasing for ultrametric
          trees).  The clustering _height_: that is, the value of the
          criterion associated with the clustering ‘method’ for the
          particular agglomeration.

   order: a vector giving the permutation of the original observations
          suitable for plotting, in the sense that a cluster plot using
          this ordering and matrix ‘merge’ will not have crossings of
          the branches.

Question: would you consider a BSD-licence?

Hi,

this is a very nice package for performing hierarchical clustering. I see that you have licenced is as GPL. At the moment a large part of the python ML community (see the scikit-* family) releases BSD-licenced libraries to allow commercial usage of code, which helps build a business ecosystem around a library. Would you consider licencing your library as BSD?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.