Chuchu

Pipeline para explorar las fronteras de modelos multiclase y visualizar sus superficies implícitas.

Este ejemplo reproduce las tres visualizaciones compartidas por el equipo. Ejecuta el bloque completo para revisar advertencias y generar las figuras interactivas.


import logging
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier

from sheshe import Chuchu, ChuchuConfig, ChangePointConfig
from sheshe.chuchu import (
    compute_frontier_planes_weighted,
    normalize_pair_order,
    plot_frontiers_implicit_interactive,
)

iris = load_iris()
X = iris.data.astype(float)
y = iris.target.astype(int)
feature_names = iris.feature_names
model = RandomForestClassifier(n_estimators=150, random_state=0).fit(X, y)

cfg = ChuchuConfig(
    log_level=logging.WARNING,
    pair_quota=20,
    max_pairs_total=120,
    secant_iters=2,
    final_bisect=8,
    alpha_change=0.65,
    distance_metric="l3",
    min_pair_margin_end=0.02,
    min_logit_gain=0.2,
    random_state=42,
)
chuchu = Chuchu(cfg).fit(X, model)
records = chuchu.records_

planes = compute_frontier_planes_weighted(records, prefer_cp=True)
fig1 = plot_frontiers_implicit_interactive(
    records,
    X,
    y,
    planes=planes,
    dims=(0, 1, 2),
    plane_mode="slice",
    slice_filter_tol=0.12,
    extend=1.15,
    clamp_extend_to_X=True,
    feature_names=feature_names,
)

planes_softmax = compute_frontier_planes_weighted(records, prefer_cp=True, weight_map="softmax")
fig2 = plot_frontiers_implicit_interactive(
    records,
    X,
    y,
    planes=planes_softmax,
    dims=(0, 1, 3),
    plane_mode="fit_dims",
    slice_filter_tol=2.9,
    extend=1.65,
    clamp_extend_to_X=True,
    feature_names=feature_names,
)

cp_cfg = ChangePointConfig(enabled=True, mode="treefast", per_record_max_points=32)
records_cp = Chuchu(cfg, cp_cfg).fit(X, model).records_
records_norm = normalize_pair_order(records_cp, make_copy=True)
planes_cp = compute_frontier_planes_weighted(records_norm, prefer_cp=True, weight_map="softmax")
fig3 = plot_frontiers_implicit_interactive(
    records_norm,
    X,
    y,
    planes=planes_cp,
    dims=(0, 1, 3),
    plane_mode="fit_dims",
    slice_filter_tol=2.9,
    extend=1.65,
    clamp_extend_to_X=True,
    feature_names=feature_names,
)

Cada figura es un objeto de Plotly con soporte para zoom, rotación y selección de capas.