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.1.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.1-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fast_varclushi-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 97b025b8160ef0fe9ecf63b37ac816826af213d152c94bc1ced7a6e509e039ad
MD5 11fbd308a675eddc81499a2aab831a40
BLAKE2b-256 47baed9e49de784b9044ec417c6f49f2c8a8728412f2010dfd60320cd17939d0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fast_varclushi-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8c6fb18723f04f9f047e1600a742630d7713546c1bf7f5ec4bc0c0946c69727a
MD5 ab40fa85b6067f41e2b6be86eac93fdf
BLAKE2b-256 aae051e765b7a3f5559964fd29de085ff4ffd4e0e223251354b0bd504e5c7eeb

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