chameleon-cluster 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- chameleon_cluster-0.1.0/.gitignore +57 -0
- chameleon_cluster-0.1.0/LICENSE +21 -0
- chameleon_cluster-0.1.0/PKG-INFO +112 -0
- chameleon_cluster-0.1.0/README.md +66 -0
- chameleon_cluster-0.1.0/benchmarks/reference_moonpuck/aggregation/labels.csv +789 -0
- chameleon_cluster-0.1.0/pyproject.toml +125 -0
- chameleon_cluster-0.1.0/src/pychameleon/__init__.py +12 -0
- chameleon_cluster-0.1.0/src/pychameleon/_datasets.py +114 -0
- chameleon_cluster-0.1.0/src/pychameleon/_types.py +31 -0
- chameleon_cluster-0.1.0/src/pychameleon/chameleon.py +155 -0
- chameleon_cluster-0.1.0/src/pychameleon/graph.py +81 -0
- chameleon_cluster-0.1.0/src/pychameleon/merger.py +116 -0
- chameleon_cluster-0.1.0/src/pychameleon/metrics.py +209 -0
- chameleon_cluster-0.1.0/src/pychameleon/partition.py +200 -0
- chameleon_cluster-0.1.0/src/pychameleon/py.typed +0 -0
- chameleon_cluster-0.1.0/tests/conftest.py +36 -0
- chameleon_cluster-0.1.0/tests/data/Aggregation.csv +788 -0
- chameleon_cluster-0.1.0/tests/data/karypis/aggregation-gt.csv +789 -0
- chameleon_cluster-0.1.0/tests/data/karypis/cluto-t4-8k.csv +8001 -0
- chameleon_cluster-0.1.0/tests/data/karypis/cluto-t5-8k.csv +8001 -0
- chameleon_cluster-0.1.0/tests/data/karypis/cluto-t7-10k.csv +10001 -0
- chameleon_cluster-0.1.0/tests/data/karypis/cluto-t8-8k.csv +8001 -0
- chameleon_cluster-0.1.0/tests/data/smileface.csv +644 -0
- chameleon_cluster-0.1.0/tests/data/t4.8k.csv +8000 -0
- chameleon_cluster-0.1.0/tests/test_chameleon.py +114 -0
- chameleon_cluster-0.1.0/tests/test_graph.py +116 -0
- chameleon_cluster-0.1.0/tests/test_merger.py +83 -0
- chameleon_cluster-0.1.0/tests/test_metrics.py +143 -0
- chameleon_cluster-0.1.0/tests/test_partition.py +101 -0
- chameleon_cluster-0.1.0/tests/test_sklearn_api.py +19 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Virtual environments
|
|
2
|
+
.venv/
|
|
3
|
+
venv/
|
|
4
|
+
env/
|
|
5
|
+
|
|
6
|
+
# Python
|
|
7
|
+
__pycache__/
|
|
8
|
+
*.py[cod]
|
|
9
|
+
*$py.class
|
|
10
|
+
*.so
|
|
11
|
+
.Python
|
|
12
|
+
|
|
13
|
+
# Build artifacts
|
|
14
|
+
dist/
|
|
15
|
+
build/
|
|
16
|
+
*.egg-info/
|
|
17
|
+
*.egg
|
|
18
|
+
|
|
19
|
+
# Testing / coverage
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
.coverage
|
|
22
|
+
.coverage.*
|
|
23
|
+
htmlcov/
|
|
24
|
+
.tox/
|
|
25
|
+
|
|
26
|
+
# Type checking / linting
|
|
27
|
+
.mypy_cache/
|
|
28
|
+
.ruff_cache/
|
|
29
|
+
.dmypy.json
|
|
30
|
+
|
|
31
|
+
# Experiments
|
|
32
|
+
experiments/results/
|
|
33
|
+
results/
|
|
34
|
+
|
|
35
|
+
# Jupyter
|
|
36
|
+
.ipynb_checkpoints/
|
|
37
|
+
|
|
38
|
+
# Editor / OS
|
|
39
|
+
.vscode/
|
|
40
|
+
.idea/
|
|
41
|
+
*.swp
|
|
42
|
+
.DS_Store
|
|
43
|
+
Thumbs.db
|
|
44
|
+
|
|
45
|
+
# Claude Code
|
|
46
|
+
.claude/
|
|
47
|
+
|
|
48
|
+
# Reference implementation (not versioned; re-created via scripts/setup_reference.sh)
|
|
49
|
+
external/chameleon_cluster_reference/
|
|
50
|
+
|
|
51
|
+
# Temporary files
|
|
52
|
+
/tmp/
|
|
53
|
+
*.log
|
|
54
|
+
|
|
55
|
+
# Course materials and third-party papers (kept locally, not published)
|
|
56
|
+
docs/presentation/
|
|
57
|
+
docs/*.pdf
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Oliwier Szypczyn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: chameleon-cluster
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CHAMELEON hierarchical clustering using dynamic modeling
|
|
5
|
+
Project-URL: Homepage, https://github.com/oszypczy/pychameleon
|
|
6
|
+
Project-URL: Repository, https://github.com/oszypczy/pychameleon
|
|
7
|
+
Project-URL: Issues, https://github.com/oszypczy/pychameleon/issues
|
|
8
|
+
Author-email: Oliwier Szypczyn <oliwier.szypczyn@tenvalleys.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: chameleon,clustering,data-mining,hierarchical-clustering,unsupervised-learning
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Requires-Dist: numpy>=1.24
|
|
25
|
+
Requires-Dist: pymetis>=2025.2
|
|
26
|
+
Requires-Dist: scikit-learn>=1.6
|
|
27
|
+
Requires-Dist: scipy>=1.11
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: mypy>=1.7; extra == 'dev'
|
|
30
|
+
Requires-Dist: pre-commit>=3.5; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest-cov>=4.1; extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest>=7.4; extra == 'dev'
|
|
33
|
+
Requires-Dist: ruff>=0.1; extra == 'dev'
|
|
34
|
+
Provides-Extra: experiments
|
|
35
|
+
Requires-Dist: jupyter>=1.0; extra == 'experiments'
|
|
36
|
+
Requires-Dist: nbconvert>=7.0; extra == 'experiments'
|
|
37
|
+
Requires-Dist: nbstripout>=0.7; extra == 'experiments'
|
|
38
|
+
Requires-Dist: notebook>=7.0; extra == 'experiments'
|
|
39
|
+
Requires-Dist: pandas>=2.0; extra == 'experiments'
|
|
40
|
+
Requires-Dist: pyyaml>=6.0; extra == 'experiments'
|
|
41
|
+
Requires-Dist: seaborn>=0.13; extra == 'experiments'
|
|
42
|
+
Requires-Dist: tqdm>=4.65; extra == 'experiments'
|
|
43
|
+
Provides-Extra: viz
|
|
44
|
+
Requires-Dist: matplotlib>=3.7; extra == 'viz'
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
|
|
47
|
+
# pychameleon
|
|
48
|
+
|
|
49
|
+
Implementation of the CHAMELEON hierarchical clustering algorithm ([Karypis, Han, Kumar, 1999](https://glaros.dtc.umn.edu/gkhome/fetch/papers/chameleonCOMPUTER99.pdf)) with a scikit-learn compatible API.
|
|
50
|
+
|
|
51
|
+
CHAMELEON discovers clusters of arbitrary shapes, densities, and sizes by using a two-phase approach:
|
|
52
|
+
|
|
53
|
+
1. **Phase I**: partition a k-nearest-neighbor graph into many small sub-clusters via [METIS](https://www.cs.umn.edu/~metis).
|
|
54
|
+
2. **Phase II**: agglomeratively merge sub-clusters using **dynamic modeling** — decisions consider each cluster's internal inter-connectivity and closeness, not a fixed global threshold.
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
uv add chameleon-cluster # with uv
|
|
60
|
+
# or
|
|
61
|
+
pip install chameleon-cluster # with pip
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The distribution is named `chameleon-cluster`; the import name is `pychameleon`.
|
|
65
|
+
|
|
66
|
+
> **Windows:** the `pymetis` dependency has no Windows wheels on PyPI. Install it
|
|
67
|
+
> from conda-forge first (`conda install -c conda-forge pymetis`), then
|
|
68
|
+
> `pip install chameleon-cluster`.
|
|
69
|
+
|
|
70
|
+
## Quick start
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import numpy as np
|
|
74
|
+
from pychameleon import Chameleon
|
|
75
|
+
|
|
76
|
+
X = np.random.rand(500, 2)
|
|
77
|
+
|
|
78
|
+
model = Chameleon(n_clusters=5, k_nn=10, min_cluster_size=0.025, alpha=2.0)
|
|
79
|
+
labels = model.fit_predict(X)
|
|
80
|
+
|
|
81
|
+
print(f"Found {model.n_clusters_} clusters, labels: {np.unique(labels)}")
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Parameters
|
|
85
|
+
|
|
86
|
+
| Parameter | Default | Description |
|
|
87
|
+
|-----------|---------|-------------|
|
|
88
|
+
| `n_clusters` | `8` | Target number of final clusters |
|
|
89
|
+
| `k_nn` | `10` | Number of neighbors in the k-NN graph |
|
|
90
|
+
| `min_cluster_size` | `0.025` | Minimum Phase-I sub-cluster size (fraction of `n` if `< 1`, else absolute count) |
|
|
91
|
+
| `alpha` | `2.0` | Exponent for relative closeness in the merge score: `RI · RC^alpha` |
|
|
92
|
+
|
|
93
|
+
## Development
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
git clone https://github.com/oszypczy/pychameleon.git
|
|
97
|
+
cd pychameleon
|
|
98
|
+
uv sync --all-extras
|
|
99
|
+
|
|
100
|
+
uv run pytest # tests + coverage
|
|
101
|
+
uv run ruff check . # lint
|
|
102
|
+
uv run mypy src/ # type check
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## References
|
|
106
|
+
|
|
107
|
+
- Karypis, G., Han, E.-H., & Kumar, V. (1999). *Chameleon: hierarchical clustering using dynamic modeling*. Computer, 32(8), 68–75.
|
|
108
|
+
- Karypis, G., & Kumar, V. (1998). *A fast and high quality multilevel scheme for partitioning irregular graphs*. SIAM J. Sci. Comput., 20(1), 359–392.
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
MIT
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# pychameleon
|
|
2
|
+
|
|
3
|
+
Implementation of the CHAMELEON hierarchical clustering algorithm ([Karypis, Han, Kumar, 1999](https://glaros.dtc.umn.edu/gkhome/fetch/papers/chameleonCOMPUTER99.pdf)) with a scikit-learn compatible API.
|
|
4
|
+
|
|
5
|
+
CHAMELEON discovers clusters of arbitrary shapes, densities, and sizes by using a two-phase approach:
|
|
6
|
+
|
|
7
|
+
1. **Phase I**: partition a k-nearest-neighbor graph into many small sub-clusters via [METIS](https://www.cs.umn.edu/~metis).
|
|
8
|
+
2. **Phase II**: agglomeratively merge sub-clusters using **dynamic modeling** — decisions consider each cluster's internal inter-connectivity and closeness, not a fixed global threshold.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
uv add chameleon-cluster # with uv
|
|
14
|
+
# or
|
|
15
|
+
pip install chameleon-cluster # with pip
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The distribution is named `chameleon-cluster`; the import name is `pychameleon`.
|
|
19
|
+
|
|
20
|
+
> **Windows:** the `pymetis` dependency has no Windows wheels on PyPI. Install it
|
|
21
|
+
> from conda-forge first (`conda install -c conda-forge pymetis`), then
|
|
22
|
+
> `pip install chameleon-cluster`.
|
|
23
|
+
|
|
24
|
+
## Quick start
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import numpy as np
|
|
28
|
+
from pychameleon import Chameleon
|
|
29
|
+
|
|
30
|
+
X = np.random.rand(500, 2)
|
|
31
|
+
|
|
32
|
+
model = Chameleon(n_clusters=5, k_nn=10, min_cluster_size=0.025, alpha=2.0)
|
|
33
|
+
labels = model.fit_predict(X)
|
|
34
|
+
|
|
35
|
+
print(f"Found {model.n_clusters_} clusters, labels: {np.unique(labels)}")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Parameters
|
|
39
|
+
|
|
40
|
+
| Parameter | Default | Description |
|
|
41
|
+
|-----------|---------|-------------|
|
|
42
|
+
| `n_clusters` | `8` | Target number of final clusters |
|
|
43
|
+
| `k_nn` | `10` | Number of neighbors in the k-NN graph |
|
|
44
|
+
| `min_cluster_size` | `0.025` | Minimum Phase-I sub-cluster size (fraction of `n` if `< 1`, else absolute count) |
|
|
45
|
+
| `alpha` | `2.0` | Exponent for relative closeness in the merge score: `RI · RC^alpha` |
|
|
46
|
+
|
|
47
|
+
## Development
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
git clone https://github.com/oszypczy/pychameleon.git
|
|
51
|
+
cd pychameleon
|
|
52
|
+
uv sync --all-extras
|
|
53
|
+
|
|
54
|
+
uv run pytest # tests + coverage
|
|
55
|
+
uv run ruff check . # lint
|
|
56
|
+
uv run mypy src/ # type check
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## References
|
|
60
|
+
|
|
61
|
+
- Karypis, G., Han, E.-H., & Kumar, V. (1999). *Chameleon: hierarchical clustering using dynamic modeling*. Computer, 32(8), 68–75.
|
|
62
|
+
- Karypis, G., & Kumar, V. (1998). *A fast and high quality multilevel scheme for partitioning irregular graphs*. SIAM J. Sci. Comput., 20(1), 359–392.
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT
|