Skip to main content

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:

  1. A cluster is chosen for splitting based on second eigenvalue criteria.
  2. 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.
  3. 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_jobs parameter support to VarClusHi (e.g. VarClusHi(df, n_jobs=-1, n_rs=10)).
  • Multi-process parallelization via joblib.Parallel distributes 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 .loc appends, and scalar calculations in vc.rsquare with a single matrix projection ($\mathbf{R}{N \times K} = \mathbf{C}{N \times N} \cdot \mathbf{W}_{N \times K}$).
  • User Implication: Querying vc.rsquare on 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 float32 precision support for 50% lower RAM footprint and SIMD vectorization.

6. 100% Bitwise Backward Compatibility

  • Guarantees exact mathematical equivalence with SAS PROC VARCLUS and original VarClusHi outputs 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 VARCLUS looking 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

fast_varclushi-0.1.0.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

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

fast_varclushi-0.1.0-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file fast_varclushi-0.1.0.tar.gz.

File metadata

  • Download URL: fast_varclushi-0.1.0.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for fast_varclushi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8f4126a0503a7262ddd16a275343c5bd05e52b78fc5ea3ea66d7334ab6d0e5cb
MD5 3f67f3384d26d8be8fc6082ef150e426
BLAKE2b-256 1dacc13f434b6ba6ec67c4049a3a52c6b6dddf94518a01174a870e25cceee25d

See more details on using hashes here.

File details

Details for the file fast_varclushi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fast_varclushi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for fast_varclushi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2496bcbfec98b8621891e20233c57fbaace2854c7677ea40cb9357b32cb7a17f
MD5 eb443e1b37a904439ff404008600914e
BLAKE2b-256 9949c0b3610967aa829df0b648b4dca4e0e268c3d762b25da9d119d3feb65f55

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 Sentry Error logging StatusPage Status page