Class-guided region clustering

Find interpretable Iris regions enriched for one target class. This workflow does not predict species; it assigns region-cluster IDs.

Fit the clusterer

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from InsideForest import InsideForestClassRegionClusterer

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.3, stratify=y, random_state=15
)
model = InsideForestClassRegionClusterer(
    rf_params={"n_estimators": 40, "max_depth": 5, "random_state": 15},
    leaf_percentile=90,
    min_support=2,
    branch_aggregation="none",
    random_state=15,
)
train_clusters = model.fit_predict(X_train, y_train)

Assign and evaluate holdout rows

test_clusters = model.predict(X_test)
assignments = model.assign_regions(X_test)
report = model.region_quality_report(X_test, y_test)

Inspect coverage, unmatched_rate, ami, cluster_purity, and rows whose source is unmatched. No class prediction fills those rows.

Interpret the regions

top = model.explain_regions(top_n=10)
class_zero = model.regions_for_class(0, top_n=5)
ambiguous = model.ambiguous_regions(top_n=10)
coverage_by_class = model.class_coverage_report()

Every row in regions_ represents one selected physical leaf and contains its target class, complete class distribution, lift, entropy, class margin, support, and geometric bounds.