Cluster selector helpers
The InsideForest.cluster_selector module exposes utilities that rebalance or consolidate clusters produced by Regions.labels. Instead of a single ClusterSelector class, use the dedicated functions and classes described below.
Key utilities
balance_lists_n_clusters(df_reres, seed=None): returns consolidated labels after enforcing similar cluster sizes.max_prob_clusters(df_reres): favors the clusters with highest probability per record.match_class_distribution(df_reres, y): adjusts assignments to mirror the original class distribution.MenuClusterSelector(quota=0.0, seed=None): fits a menu of candidate clusters and selects the best configuration according to information-theoretic scores.ChimeraValuesSelector(quota=0.0, seed=None): combines silhouettes and quota enforcement to smooth assignments.
Example
from InsideForest import cluster_selector
# After calling InsideForestRegionClusterer(..., get_detail=True).fit(X, y)
menu = cluster_selector.MenuClusterSelector(quota=0.2)
menu.fit(clf.df_reres_, y)
rebalanced = menu.predict(clf.df_reres_)
# Alternatively apply a functional helper
balanced = cluster_selector.balance_lists_n_clusters(clf.df_reres_, seed=42)
All helpers operate on the DataFrame returned by Regions.prio_ranges, which is stored as df_reres_ inside the high-level wrappers when get_detail=True.