BatiClust 🏘️
BatiClust is a Python framework designed to generate and validate building stock archetypes. It leverages unsupervised machine learning to segment residential dwellings into representative groups and provides a rigorous external validation suite using Energy Performance Certificate (EPC) data.
Unlike static typologies, BatiClust allows researchers to define archetypes at any level of granularity, quantifying the trade-off between model simplicity and its accuracy in representing national energy signatures.
It is built on top of Polars for high-performance data manipulation and uses Faiss and Fastcluster for efficient clustering.
Key Features
- Stratified Subsampling: Automatically split large building databases into homogeneous subsamples based on categorical attributes (e.g., construction era, heating system) before clustering.
- Scalable Clustering: Implements flexible clustering algorithms (K-Means via Faiss, Hierarchical via Fastcluster) to identify natural archetypes within building stocks.
- External Validation: A dedicated module to compare cluster-derived distributions against real-world energy performance data.
- Medoid Selection: Identifies representative building archetypes (medoids) for each cluster.
Installation
pip install baticlust
Note: This package requires polars, numpy, faiss-cpu, fastcluster, scipy, matplotlib, and scikit-learn.
Quick Start
1. Data Preparation
Prepare your dataset with descriptive features and target performance metrics. BatiClust uses Polars DataFrames.
import polars as pl
from baticlust import scale_features
# Load your data
df = pl.read_parquet("housing_stock.parquet")
# Define features
strata_cols = ['construction_year_class', 'heating_energy_type']
features = ['living_area', 'wall_insulation_thickness']
# Scale numerical features
df_scaled = scale_features(df, features, method="standard")
2. Stratified Clustering
BatiClust splits your database into strategic subsamples before applying clustering.
from baticlust import generate_archetypes
# Generate archetypes
clustered_df = generate_archetypes(
df_scaled,
strata_cols=strata_cols,
features=features,
method="kmeans",
total_n_clusters=1000,
niter=20,
verbose=True
)
# The result is the original DataFrame with a new 'cluster_id' column
print(clustered_df.head())
3. Medoid Selection & Validation
Identify representative archetypes and validate them against actual performance data.
from baticlust import select_medoids, validate_typology_with_medoids
# Create a unique cluster identifier if needed (combining strata and cluster_id)
clustered_df = clustered_df.with_columns(
pl.concat_str([pl.col(c) for c in strata_cols] + [pl.col("cluster_id").cast(pl.Utf8)], separator="_")
.alias("unique_cluster_id")
)
# Select medoids (representative buildings)
medoids_df = select_medoids(clustered_df, "unique_cluster_id", features)
# Validate using a target column (e.g., energy consumption)
metrics = validate_typology_with_medoids(
clustered_df,
medoids_df,
cluster_col="unique_cluster_id",
target_col="energy_consumption"
)
print(f"Wasserstein Distance: {metrics['wasserstein_distance']}")
print(f"KS Statistic: {metrics['ks_statistic']}")
Methodology
The BatiClust workflow follows the methodology established in recent building stock research:
- Pre-processing: Cleaning and scaling of building characteristics using Polars.
- Stratification: Subdividing the stock into logical categories to ensure rare but important building types are not lost.
- Clustering: Applying algorithms like K-Means (Faiss) or Hierarchical Clustering (Fastcluster) to find representative centroids within each stratum.
- Validation: Using Kolmogorov-Smirnov tests and Wasserstein distance to verify if the clusters accurately mirror the energy performance distribution of the original stock.
Citing BatiClust
If you use this package in your research, please cite the following paper:
A Scalable Framework for Generating and Validating Dwelling Archetypes: A Clustering Approach for Energy Performance Analysis (2026). [Link to Paper]
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for baticlust 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| baticlust-0.1.0.tar.gz | 8.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| baticlust-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.2 kB
Release files / baticlust-0.1.0.tar.gz
| Download URL | baticlust-0.1.0.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65d9a6561144398b26da778afe1c0e415449dd9f8200e711ac98f42fae08036b
|
|
BLAKE2b-256 checksum How to use checksums |
30a23aeb968c1fe02ffccce622341c0f2e7bfe8c035dfb47783b835ec978811d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / baticlust-0.1.0-py3-none-any.whl
| Download URL | baticlust-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7bf178dc158701880845b811769134f30d933a1895d8be763c22010e979a8275
|
|
BLAKE2b-256 checksum How to use checksums |
6ea2f7a68338c3cc5b8d373b820f7d648ba93981854fdb07644c179043f22269
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|