Implementation:Scikit learn Scikit learn EstimatorPrettyPrint
| 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
- Repository: scikit-learn
- File: sklearn/utils/_pprint.py
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)