Skip to content

ENH: update html parameter display to match scikit-learn style#504

Draft
AnimeshPatra2005 wants to merge 5 commits into
sktime:mainfrom
AnimeshPatra2005:enh/html-param-display-503
Draft

ENH: update html parameter display to match scikit-learn style#504
AnimeshPatra2005 wants to merge 5 commits into
sktime:mainfrom
AnimeshPatra2005:enh/html-param-display-503

Conversation

@AnimeshPatra2005
Copy link
Copy Markdown

@AnimeshPatra2005 AnimeshPatra2005 commented Feb 26, 2026

Reference Issues/PRs

Closes #503. Related to sktime/sktime#9497.

What does this implement/fix? Explain your changes.

scikit-learn has updated how they display parameters in the HTML representation of estimators. This PR updates scikit-base to match.

Previously, clicking an estimator box in a Jupyter notebook showed a raw <pre> string like MyEstimator(alpha=0.5).

This PR replaces that with a structured two-column parameter table built from get_params(deep=False), showing each parameter name and its current value in a cleaner, more readable format.

Changes:

  • New _params_to_html_table() helper that generates the table HTML
  • _write_label_html() gains an optional estimator parameter; when provided, renders the table instead of the pre block
  • _write_base_object_html() passes the estimator through
  • CSS styles for the table appended to _STYLE

Does your contribution introduce a new dependency? If yes, which one?

No.

What should a reviewer concentrate their feedback on?

  • The CSS styling choices for the parameter table
  • Whether the fallback to <pre> for non-estimator objects is correct

Any other comments?

Marked as Draft, happy to add unit tests once the approach is confirmed as the right direction.

How it looks like:

Screenshot 2026-03-25 152701

@mateuszkasprowicz
Copy link
Copy Markdown

hey @AnimeshPatra2005, this is a solid start!

I created a simple comparison between sklearn 1.8+ and your PR handling of params display:

skbase

single estimator

Code
class SkbaseDemo(BaseEstimator):
    """Tiny estimator for HTML repr smoke tests."""

    def __init__(self, foo=1, bar="hello", multiplier=0.5):
        self.foo = foo
        self.bar = bar
        self.multiplier = multiplier
        super().__init__()


display(SkbaseDemo(foo=42, bar="notebook", multiplier=2.0))
obraz

skbase

composite estimator

Code
class SkbaseComponent(BaseObject):
    def __init__(self, a=1, flag=True):
        self.a = a
        self.flag = flag
        super().__init__()


class DemoMeta(BaseMetaObject):
    def __init__(self, steps=None):
        self.steps = steps
        super().__init__()


composite = DemoMeta(
    steps=[
        ("first", SkbaseComponent(a=10, flag=False)),
        ("second", SkbaseComponent(a=99, flag=True)),
    ]
)
display(composite)
obraz

sklearn

single estimator

Code
from sklearn.linear_model import LogisticRegression

display(
    LogisticRegression(
        C=0.5, max_iter=200, solver="liblinear", random_state=0
    )
)
obraz

sklearn

composite estimator

Code
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler

display(
    Pipeline(
        [
            ("scale", StandardScaler(with_mean=False)),
            ("clf", LogisticRegression(C=2.0, max_iter=500)),
        ]
    )
)
obraz

Overview of what's missing

  • Separate “Parameters” collapsible - sklearn: class row stays clean, then an inner Parameters section toggles the table;
  • Per-parameter documentation on hover - sklearn: dashed-underline names + tooltip text from the docstring.
  • Copy parameter name (or name/value) to clipboard - sklearn: small copy control per row;
  • See which params differ from defaults - sklearn: emphasizes changed params (e.g. orange); skbase: no default vs user-set distinction.
  • Readable values for large/nested objects - sklearn shortens repr (reprlib-style); skbase uses full repr(value) in HTML - can freeze or clutter the cell.
  • And of course a small test to ensure we have sk-params-table in the HTML

Where to look in sklearn code

(courtesy of Codex)

sklearn/utils/_repr_html/estimator.py — estimator tree / overall HTML repr
sklearn/utils/_repr_html/params.py — parameter table HTML (ParamsDict, _params_html_repr, etc.)
sklearn/utils/_repr_html/common.py — helpers (e.g. doc links, docstring snippets for params)
sklearn/utils/_repr_html/base.py — ReprHTMLMixin and shared HTML bits
sklearn/utils/_repr_html/estimator.css — layout / estimator chrome
sklearn/utils/_repr_html/params.css — parameter table styling
sklearn/utils/_repr_html/__init__.py — package exports
sklearn/utils/_repr_html/tests/ — tests for the above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH] update html parameter display to match scikit-learn style

2 participants