Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn EstimatorPrettyPrint

From Leeroopedia
Revision as of 16:34, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Scikit_learn_Scikit_learn_EstimatorPrettyPrint.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Machine Learning, Display Formatting
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete utility module for pretty-printing scikit-learn estimator representations provided by scikit-learn.

Description

The _pprint module contains the _EstimatorPrettyPrinter class used in BaseEstimator.__repr__ for pretty-printing estimators. It extends Python's built-in pprint module with support for compact dict rendering, custom estimator handling, and ellipsis-based truncation of long sequences. The module also provides the _changed_params helper to display only non-default parameters.

Usage

This module is used internally by scikit-learn's BaseEstimator.__repr__ method. It is invoked automatically whenever an estimator is printed or displayed in a notebook or terminal.

Code Reference

Source Location

Signature

class KeyValTuple(tuple):
    ...

class KeyValTupleParam(KeyValTuple):
    ...

def _changed_params(estimator):
    ...

class _EstimatorPrettyPrinter(pprint.PrettyPrinter):
    ...

def _safe_repr(object, context, maxlevels, level, changed_only=False):
    ...

Import

from sklearn.utils._pprint import _EstimatorPrettyPrinter

I/O Contract

Inputs

Name Type Required Description
estimator BaseEstimator Yes The estimator to pretty-print
changed_only bool No If True, only show parameters that differ from defaults

Outputs

Name Type Description
repr_string str A formatted string representation of the estimator

Usage Examples

Basic Usage

from sklearn.linear_model import LogisticRegression

# Pretty printing is automatic via __repr__
lr = LogisticRegression(C=0.5, max_iter=200)
print(lr)
# LogisticRegression(C=0.5, max_iter=200)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment