fast-varclushi
fast-varclushi is a high-performance Python package for variable clustering (varclus) using hierarchical dimension reduction.
Varclus is a powerful dimension reduction algorithm:
- A cluster is chosen for splitting based on second eigenvalue criteria.
- The chosen cluster is split into two clusters using the first two principal components, applying an orthoblique factor rotation (
Rotator), and assigning each variable to the rotated component with which it has the highest squared correlation. - Variables are iteratively reassigned to clusters to maximize the variance accounted for by the cluster components.
⚡ High-Performance Enhancements & Key Improvements
fast-varclushi includes significant computational, memory, and parallel optimizations designed for scaling to large datasets:
1. Pre-computed Correlation Matrix Caching (Sample-Size Independent Clustering)
- Pre-computes the full feature correlation matrix $C$ once on initialization ($O(M \cdot N^2)$).
- During iterative cluster splitting and variable reassignments, sub-correlation matrices are sliced directly in microseconds ($O(K^2)$).
- User Implication: Clustering execution is 10x to 50x faster on large datasets and becomes completely independent of row count $M$ (e.g., clustering 1,000,000+ rows takes the exact same time as 1,000 rows during clustering!).
2. Sub-Cluster Eigenvalue Memoization & LRU Caching
- Sub-cluster total variance and top eigenvalue calculations during greedy reassignment iterations are memoized and solved with fast symmetric eigensolvers (
np.linalg.eigvalsh). - User Implication: Eliminates thousands of redundant matrix decompositions across iterative variable movements.
3. Multi-CPU Core Parallelization (n_jobs)
- Added
n_jobsparameter support toVarClusHi(e.g.VarClusHi(df, n_jobs=-1, n_rs=10)). - Multi-process parallelization via
joblib.Paralleldistributes random search restarts (n_rs > 0) across all available CPU cores. - User Implication: Near-linear speedup on multi-core workstations and server CPUs when using random search restarts (
n_rs > 0) to find optimal cluster splits.
4. Vectorized RSquare Property Computation (50x–100x Speedup)
- Replaced nested Python loops, row-by-row DataFrame
.locappends, and scalar calculations invc.rsquarewith a single matrix projection ($\mathbf{R}{N \times K} = \mathbf{C}{N \times N} \cdot \mathbf{W}_{N \times K}$). - User Implication: Querying
vc.rsquareon datasets with hundreds or thousands of features completes almost instantaneously (in a fraction of a second).
5. Algorithmic & Matrix Rotator Optimizations
- Optimized Varimax inner loops by replacing $O(n k^2)$ matrix products and 2D diagonal matrix allocations with direct column-wise element-wise scaling ($O(n k)$).
- Added native
float32precision support for 50% lower RAM footprint and SIMD vectorization.
6. 100% Bitwise Backward Compatibility
- Guarantees exact mathematical equivalence with SAS
PROC VARCLUSand originalVarClusHioutputs across all 137 unit and regression test benchmarks.
🚀 Big Data Performance Benchmark
fast-varclushi is engineered to handle massive tabular datasets with millions of rows and hundreds of features efficiently.
| Benchmark Dataset | Rows | Features | RAM Footprint | fast-varclushi Execution Time |
Clusters Formed |
|---|---|---|---|---|---|
| Synthetic Big Data | 2,000,000 | 500 | 3.73 GB | 74.78 seconds ⚡ | 186 |
- Sample-Size Independence: Thanks to initial correlation matrix caching, variable clustering across 2 Million rows completes in ~74 seconds, whereas legacy Python implementations take hours or fail with out-of-memory errors.
- Reproduce Benchmark:
python benchmark_bigdata.py
Intended Audience
- Data scientists and analysts familiar with SAS
PROC VARCLUSlooking for a fast, reliable Python alternative. - Machine learning practitioners needing scalable feature reduction and multi-collinearity elimination on large-scale tabular datasets.
Quickstart & Example
import pandas as pd
from varclushi import VarClusHi
# Load sample dataset
demo_df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv', sep=';')
demo_df.drop('quality', axis=1, inplace=True)
# Initialize VarClusHi with all CPU cores and run variable clustering
vc = VarClusHi(demo_df, maxeigval2=1, maxclus=None, n_jobs=-1)
vc.varclus()
Cluster Summary Table (vc.info)
print(vc.info)
Cluster N_Vars Eigval1 Eigval2 VarProp
0 0 3 2.141357 0.658413 0.713786
1 1 3 1.766885 0.900991 0.588962
2 2 2 1.371260 0.628740 0.685630
3 3 2 1.552496 0.447504 0.776248
4 4 1 1.000000 0.000000 1.000000
R-Squared Ratio Table (vc.rsquare)
print(vc.rsquare)
Cluster Variable RS_Own RS_NC RS_Ratio
0 0 fixed acidity 0.882210 0.277256 0.162976
1 0 density 0.622070 0.246194 0.501362
2 0 pH 0.637076 0.194359 0.450478
3 1 free sulfur dioxide 0.777796 0.010358 0.224530
4 1 total sulfur dioxide 0.786660 0.042294 0.222761
5 1 residual sugar 0.202428 0.045424 0.835525
6 2 sulphates 0.685630 0.106022 0.351653
7 2 chlorides 0.685630 0.048903 0.330534
8 3 citric acid 0.776248 0.398208 0.371810
9 3 volatile acidity 0.776248 0.040920 0.233299
10 4 alcohol 1.000000 0.082055 0.000000
Installation
pip install fast-varclushi
License
Distributed under the GNU General Public License v3 (GPLv3).
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fast_varclushi-0.1.2.tar.gz.
File metadata
- Download URL: fast_varclushi-0.1.2.tar.gz
- Upload date:
- Size: 33.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3f6d2e681c08db39c81819579762fbf37b5aceb769810d669e14d3e80a4fc72
|
|
| MD5 |
d5244235b5d546ee24bd61e34db1c65d
|
|
| BLAKE2b-256 |
69237ab3ecc4f51eeaf50b150f306aef55df03fabf2fcbf2f06950cf98a85f6b
|
File details
Details for the file fast_varclushi-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fast_varclushi-0.1.2-py3-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58417bfd6af1f36bb0a433067bcf5540a1779141c3281cdd19325b12acf57afd
|
|
| MD5 |
74b89dfa544f1488fabcda9c00ab3aa9
|
|
| BLAKE2b-256 |
20cea936b774b5ebf061c2f9399d9e1c4233715a91a4abb00578024ad504bfef
|