---
url: /stable/api/sklink.plotting.md
description: >-
  API reference of sklink.plotting. Figures that show what a relational model
  reads, learns and predicts.
---

::: v-pre

# `sklink.plotting` {#sklink.plotting}

Figures that show what a relational model reads, learns and predicts.

Each figure is a display object, created with `from_estimator` (or
`from_database`) or from the dictionaries of [`sklink.inspection`](./sklink.inspection#sklink.inspection):

* `SchemaDisplay`: the tables, keys and relationships given to a model,
  the entity and the target, and the columns the model reads.
* `TreeDisplay`: a relational decision tree, with the detail of every
  node and, optionally, the path of one sample.
* `ExplanationDisplay`: why one sample got its prediction, question by
  question for a tree and expression by expression for a forest.
* `ImportanceDisplay`: how the importance of a tree or forest flows from
  tables to columns to primitives.
* `ForestDisplay`: how a forest fitted: its score as trees are added,
  the size of its trees and where they ask each expression.
* `SearchDisplay`: the questions a tree scored at one node, the chosen
  one first.
* `CutoffSplitDisplay`: which cutoff dates train and which test in each
  split of a temporal cross-validation.
* `LiveFit`: a callback that draws the progress of `fit` while it
  runs, and the fitted model when it ends.

In Jupyter, VS Code, Colab and marimo a display shows as interactive HTML,
with inline CSS and JavaScript and nothing loaded from the network. The figure
is static SVG drawn in Python, so it stays complete where JavaScript does not
run. Terminals show a text summary. Every display also offers `show()`,
`save()` (HTML, SVG or JSON) and `to_dict()`.

The figures use the colors of the scikit-link visual identity and follow the
light or dark theme of the notebook.

**Classes:**

* [**CutoffSplitDisplay**](#sklink.plotting.CutoffSplitDisplay): Which cutoffs train and which test in each split of a cross-validation.
* [**ExplanationDisplay**](#sklink.plotting.ExplanationDisplay): Why one sample got its prediction.
* [**ForestDisplay**](#sklink.plotting.ForestDisplay): How a relational random forest or gradient boosting model fitted.
* [**ImportanceDisplay**](#sklink.plotting.ImportanceDisplay): How the importance of a model flows from tables to columns to primitives.
* [**LiveFit**](#sklink.plotting.LiveFit): Draw the progress of `fit` while it runs, and the model when it ends.
* [**SchemaDisplay**](#sklink.plotting.SchemaDisplay): Tables, keys and relationships of a database, as given to a model.
* [**SearchDisplay**](#sklink.plotting.SearchDisplay): The questions a relational tree scored at one node, the chosen one first.
* [**TreeDisplay**](#sklink.plotting.TreeDisplay): Relational decision tree, drawn from [`export_dict`](./sklink.inspection#sklink.inspection.export_dict).

## `sklink.plotting.CutoffSplitDisplay` {#sklink.plotting.CutoffSplitDisplay}

```python
CutoffSplitDisplay(cutoffs: Sequence[str], counts: Sequence[int], splits: Sequence[Mapping[str, Any]], *, label_horizon: float | None = None, gap: float | None = None, splitter: str | None = None) -> None
```

Bases: Display

Which cutoffs train and which test in each split of a cross-validation.

Each split is a row on one time axis: the training cutoffs as filled
squares, the test cutoffs as open ones and, after the last training
cutoff, how far its label looks ahead (the label horizon, then the gap).
Cutoffs left out of a split because their label would reach the test
period are dashed. A training cutoff at or after the first test cutoff,
or whose label reaches it, trains on the future: it is drawn in coral and
counted, which is what happens with [`KFold`](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html)
on temporal data.

**Guides:** [Plot schemas, trees and predictions](../tutorials/plotting)

**Parameters:**

* **cutoffs** (list of str): The distinct cutoffs, in increasing order, as ISO dates or datetimes.
* **counts** (list of int): Number of rows of `X` at each cutoff.
* **splits** (list of dict): One dictionary per split with `"train"` and `"test"`: lists of
  `[i, n]` pairs, `n` rows at `cutoffs[i]`.
* **label_horizon** (([float](https://docs.python.org/3/library/functions.html#float), [str](https://docs.python.org/3/library/stdtypes.html#str), timedelta or None)): How far the label of a sample looks after its cutoff, and the extra
  separation required before the test period: in seconds, or a
  duration as in [`TemporalCutoffSplit`](./sklink.model_selection#sklink.model_selection.TemporalCutoffSplit).
* **gap** (([float](https://docs.python.org/3/library/functions.html#float), [str](https://docs.python.org/3/library/stdtypes.html#str), timedelta or None)): How far the label of a sample looks after its cutoff, and the extra
  separation required before the test period: in seconds, or a
  duration as in [`TemporalCutoffSplit`](./sklink.model_selection#sklink.model_selection.TemporalCutoffSplit).
* **splitter** ([str](https://docs.python.org/3/library/stdtypes.html#str) or None): How the splitter is written, for the subtitle.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If the cutoffs are not increasing, a split refers to a cutoff that
  does not exist or `counts` does not match `cutoffs`.

sklink.model_selection.TemporalCutoffSplit : The splitter it is made for.

**Examples:**

```pycon
>>> import numpy as np
>>> from sklink.model_selection import TemporalCutoffSplit
>>> from sklink.plotting import CutoffSplitDisplay
>>> X = np.empty((8, 1), dtype=object)
>>> X[:, 0] = np.repeat(
...     np.array(["2024-01-01", "2024-02-01", "2024-03-01", "2024-04-01"],
...              dtype="datetime64[D]"), 2)
>>> cv = TemporalCutoffSplit(time=0, n_splits=2, label_horizon="40D")
>>> text = CutoffSplitDisplay.from_splitter(cv, X).to_text()
>>> for line in text.splitlines()[1:]:
...     print(line)
  split 1: train 2024-01-01 (2 rows) · test 2024-03-01 (2 rows)
  split 2: train 2024-01-01 to 2024-02-01 (4 rows) · test 2024-04-01 (2 rows)
```

**Functions:**

* [**from_splitter**](#sklink.plotting.CutoffSplitDisplay.from_splitter): Run a splitter on `X` and draw its splits on the cutoff axis.
* [**save**](#sklink.plotting.CutoffSplitDisplay.save): Write the figure to a file chosen by its extension.
* [**show**](#sklink.plotting.CutoffSplitDisplay.show): Show the figure where the code runs.
* [**to_dict**](#sklink.plotting.CutoffSplitDisplay.to_dict): Return the data of the figure as a JSON-serializable dictionary.
* [**to_html**](#sklink.plotting.CutoffSplitDisplay.to_html): Return the figure as an HTML fragment with inline CSS and JavaScript.
* [**to_svg**](#sklink.plotting.CutoffSplitDisplay.to_svg): Return the figure as a standalone SVG document, without interaction.
* [**to_text**](#sklink.plotting.CutoffSplitDisplay.to_text): Return a plain-text summary of the figure.

**Attributes:**

* [**counts**](#sklink.plotting.CutoffSplitDisplay.counts):
* [**cutoffs**](#sklink.plotting.CutoffSplitDisplay.cutoffs):
* [**gap**](#sklink.plotting.CutoffSplitDisplay.gap):
* [**label_horizon**](#sklink.plotting.CutoffSplitDisplay.label_horizon):
* [**splits**](#sklink.plotting.CutoffSplitDisplay.splits):
* [**splitter**](#sklink.plotting.CutoffSplitDisplay.splitter):

### `sklink.plotting.CutoffSplitDisplay.counts` {#sklink.plotting.CutoffSplitDisplay.counts}

```python
counts = [int(c) for c in counts]
```

### `sklink.plotting.CutoffSplitDisplay.cutoffs` {#sklink.plotting.CutoffSplitDisplay.cutoffs}

```python
cutoffs = cutoffs
```

### `sklink.plotting.CutoffSplitDisplay.from_splitter` {#sklink.plotting.CutoffSplitDisplay.from_splitter}

```python
from_splitter(splitter: Any, X: Any, y: Any = None, groups: Any = None, *, time: str | int | None = None, label_horizon: Any = None) -> CutoffSplitDisplay
```

Run a splitter on `X` and draw its splits on the cutoff axis.

**Parameters:**

* **splitter** (cross-validation splitter): A [`TemporalCutoffSplit`](./sklink.model_selection#sklink.model_selection.TemporalCutoffSplit), or any
  scikit-learn splitter, such as
  [`KFold`](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html), to see what it does with
  temporal data.
* **X** (DataFrame or array-like of shape (n_samples, n_columns)): Population table with the cutoff column.
* **y** (array - like): Passed to `splitter.split`.
* **groups** (array - like): Passed to `splitter.split`.
* **time** ([str](https://docs.python.org/3/library/stdtypes.html#str) or [int](https://docs.python.org/3/library/functions.html#int) or None): Cutoff column of `X`. `None` uses `splitter.time`.
* **label_horizon** (([str](https://docs.python.org/3/library/stdtypes.html#str), timedelta or None)): How far the label looks after the cutoff, as in
  [`TemporalCutoffSplit`](./sklink.model_selection#sklink.model_selection.TemporalCutoffSplit). `None`
  uses `splitter.label_horizon` when it has one.

**Returns:**

* **display** ([CutoffSplitDisplay](#sklink.plotting.CutoffSplitDisplay)):

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If there is no cutoff column, or the splitter cannot split `X`.

### `sklink.plotting.CutoffSplitDisplay.gap` {#sklink.plotting.CutoffSplitDisplay.gap}

```python
gap = self._gap_ns / 1000000000.0 or None
```

### `sklink.plotting.CutoffSplitDisplay.label_horizon` {#sklink.plotting.CutoffSplitDisplay.label_horizon}

```python
label_horizon = self._horizon_ns / 1000000000.0 or None
```

### `sklink.plotting.CutoffSplitDisplay.save` {#sklink.plotting.CutoffSplitDisplay.save}

```python
save(path: str | Path, *, theme: Theme = 'auto') -> None
```

Write the figure to a file chosen by its extension.

**Parameters:**

* **path** ([str](https://docs.python.org/3/library/stdtypes.html#str) or path - like): `.html` writes a standalone page with interaction, `.svg` the
  static figure and `.json` the output of `to_dict`.
* **theme** ((auto, light, dark)): Theme of HTML and SVG files.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If the extension is not `.html`, `.htm`, `.svg` or `.json`.

### `sklink.plotting.CutoffSplitDisplay.show` {#sklink.plotting.CutoffSplitDisplay.show}

```python
show(*, theme: Theme = 'auto') -> None
```

Show the figure where the code runs.

In a notebook the figure is displayed in the output of the cell. In a
script or a terminal, it is written to a temporary HTML file that opens
in the web browser; if no browser can be opened, the text summary is
printed instead.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

### `sklink.plotting.CutoffSplitDisplay.splits` {#sklink.plotting.CutoffSplitDisplay.splits}

```python
splits = checked
```

### `sklink.plotting.CutoffSplitDisplay.splitter` {#sklink.plotting.CutoffSplitDisplay.splitter}

```python
splitter = splitter
```

### `sklink.plotting.CutoffSplitDisplay.to_dict` {#sklink.plotting.CutoffSplitDisplay.to_dict}

```python
to_dict() -> dict[str, Any]
```

Return the data of the figure as a JSON-serializable dictionary.

**Returns:**

* **data** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): `"format_version"`, `"kind"` (the figure), `"sklink_version"`
  and `"data"`, the inputs the figure is drawn from.

### `sklink.plotting.CutoffSplitDisplay.to_html` {#sklink.plotting.CutoffSplitDisplay.to_html}

```python
to_html(*, theme: Theme = 'auto') -> str
```

Return the figure as an HTML fragment with inline CSS and JavaScript.

The fragment loads nothing from the network. Without JavaScript, as in
an untrusted notebook or an exported page, it shows the same static
figure.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **html** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.CutoffSplitDisplay.to_svg` {#sklink.plotting.CutoffSplitDisplay.to_svg}

```python
to_svg(*, theme: Theme = 'auto') -> str
```

Return the figure as a standalone SVG document, without interaction.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **svg** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.CutoffSplitDisplay.to_text` {#sklink.plotting.CutoffSplitDisplay.to_text}

```python
to_text() -> str
```

Return a plain-text summary of the figure.

## `sklink.plotting.ExplanationDisplay` {#sklink.plotting.ExplanationDisplay}

```python
ExplanationDisplay(explanation: Mapping[str, Any], *, classes: Sequence[Any] | None = None, n_estimators: int | None = None) -> None
```

Bases: Display

Why one sample got its prediction.

For a tree, each question on the decision path of the sample is a row: the
expression, the value computed for the sample from the database, and, for
numeric questions, a number line with the threshold, the side the sample
took and the sample itself in coral. For a forest or a gradient boosting
model, each row is one of the expressions its trees asked about, with its
share of the paths and the number of trees that asked; for boosting, also
the signed effect of the expression on the raw prediction (the log-odds of
the last class for two classes, the score of the predicted class for more,
the predicted value for a regressor). The predicted class probabilities,
the predicted value or the cluster close the figure.

**Guides:** [Plot schemas, trees and predictions](../tutorials/plotting)

**Parameters:**

* **explanation** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): One entry of [`sklink.inspection.explain`](./sklink.inspection#sklink.inspection.explain).
* **classes** ([list](https://docs.python.org/3/library/stdtypes.html#list) or None): Class labels of a classifier, in the order of `value`. `None` for a
  regressor.
* **n\_estimators** ([int](https://docs.python.org/3/library/functions.html#int) or None): Number of trees of a forest or a boosting model, to read `n_trees`
  against.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If `explanation` is not an entry of
  [`explain`](./sklink.inspection#sklink.inspection.explain), or `classes` does not match its
  `"value"`.

sklink.inspection.explain : The same explanation as a dictionary.
TreeDisplay : The whole tree, with the decision path of one sample.

**Examples:**

```pycon
>>> from sklink.datasets import load_shop
>>> from sklink.plotting import ExplanationDisplay
>>> from sklink.tree import RelationalDecisionTreeClassifier
>>> shop = load_shop()
>>> tree = RelationalDecisionTreeClassifier(
...     shop.database, entity="customers", key=0, max_depth=1
... ).fit(shop.X, shop.y)
>>> display = ExplanationDisplay.from_estimator(tree, shop.X, sample=0)
>>> print(display.to_text())
sample 0: class 1
  1. count(orders) = 5 > 2.5, goes right
```

**Functions:**

* [**from_estimator**](#sklink.plotting.ExplanationDisplay.from_estimator): Explain the prediction of one row of `X`.
* [**save**](#sklink.plotting.ExplanationDisplay.save): Write the figure to a file chosen by its extension.
* [**show**](#sklink.plotting.ExplanationDisplay.show): Show the figure where the code runs.
* [**to_dict**](#sklink.plotting.ExplanationDisplay.to_dict): Return the data of the figure as a JSON-serializable dictionary.
* [**to_html**](#sklink.plotting.ExplanationDisplay.to_html): Return the figure as an HTML fragment with inline CSS and JavaScript.
* [**to_svg**](#sklink.plotting.ExplanationDisplay.to_svg): Return the figure as a standalone SVG document, without interaction.
* [**to_text**](#sklink.plotting.ExplanationDisplay.to_text): Return the explanation as text, one line per question or expression.

**Attributes:**

* [**classes**](#sklink.plotting.ExplanationDisplay.classes):
* [**explanation**](#sklink.plotting.ExplanationDisplay.explanation):
* [**n\_estimators**](#sklink.plotting.ExplanationDisplay.n_estimators):

### `sklink.plotting.ExplanationDisplay.classes` {#sklink.plotting.ExplanationDisplay.classes}

```python
classes = None if classes is None else list(classes)
```

### `sklink.plotting.ExplanationDisplay.explanation` {#sklink.plotting.ExplanationDisplay.explanation}

```python
explanation = dict(explanation)
```

### `sklink.plotting.ExplanationDisplay.from_estimator` {#sklink.plotting.ExplanationDisplay.from_estimator}

```python
from_estimator(estimator: Any, X: Any, *, sample: int = 0) -> ExplanationDisplay
```

Explain the prediction of one row of `X`.

**Parameters:**

* **estimator** (relational tree, forest or gradient boosting model): A fitted relational tree (also a clustering tree), forest or
  gradient boosting model, a
  [`Pipeline`](https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html) ending with one, or a fitted
  search whose `best_estimator_` is one. It needs its database: a
  detached model must be rebound.
* **X** (DataFrame or array-like of shape (n_samples, n_columns)): Population table with the same columns as in `fit`.
* **sample** ([int](https://docs.python.org/3/library/functions.html#int)): Position of the row of `X` to explain.

**Returns:**

* **display** ([ExplanationDisplay](#sklink.plotting.ExplanationDisplay)):

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If `sample` is not a position of a row of `X`.
* [TypeError](https://docs.python.org/3/library/exceptions.html#TypeError): If `estimator` is not a relational tree, forest or gradient
  boosting model.
* [NotFittedError](https://scikit-learn.org/stable/modules/generated/sklearn.exceptions.NotFittedError.html): If it is not fitted.
* [DetachedDatabaseError](./sklink.exceptions#sklink.exceptions.DetachedDatabaseError): If the model was detached from its database.

### `sklink.plotting.ExplanationDisplay.n_estimators` {#sklink.plotting.ExplanationDisplay.n_estimators}

```python
n_estimators = n_estimators
```

### `sklink.plotting.ExplanationDisplay.save` {#sklink.plotting.ExplanationDisplay.save}

```python
save(path: str | Path, *, theme: Theme = 'auto') -> None
```

Write the figure to a file chosen by its extension.

**Parameters:**

* **path** ([str](https://docs.python.org/3/library/stdtypes.html#str) or path - like): `.html` writes a standalone page with interaction, `.svg` the
  static figure and `.json` the output of `to_dict`.
* **theme** ((auto, light, dark)): Theme of HTML and SVG files.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If the extension is not `.html`, `.htm`, `.svg` or `.json`.

### `sklink.plotting.ExplanationDisplay.show` {#sklink.plotting.ExplanationDisplay.show}

```python
show(*, theme: Theme = 'auto') -> None
```

Show the figure where the code runs.

In a notebook the figure is displayed in the output of the cell. In a
script or a terminal, it is written to a temporary HTML file that opens
in the web browser; if no browser can be opened, the text summary is
printed instead.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

### `sklink.plotting.ExplanationDisplay.to_dict` {#sklink.plotting.ExplanationDisplay.to_dict}

```python
to_dict() -> dict[str, Any]
```

Return the data of the figure as a JSON-serializable dictionary.

**Returns:**

* **data** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): `"format_version"`, `"kind"` (the figure), `"sklink_version"`
  and `"data"`, the inputs the figure is drawn from.

### `sklink.plotting.ExplanationDisplay.to_html` {#sklink.plotting.ExplanationDisplay.to_html}

```python
to_html(*, theme: Theme = 'auto') -> str
```

Return the figure as an HTML fragment with inline CSS and JavaScript.

The fragment loads nothing from the network. Without JavaScript, as in
an untrusted notebook or an exported page, it shows the same static
figure.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **html** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.ExplanationDisplay.to_svg` {#sklink.plotting.ExplanationDisplay.to_svg}

```python
to_svg(*, theme: Theme = 'auto') -> str
```

Return the figure as a standalone SVG document, without interaction.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **svg** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.ExplanationDisplay.to_text` {#sklink.plotting.ExplanationDisplay.to_text}

```python
to_text() -> str
```

Return the explanation as text, one line per question or expression.

**Returns:**

* **text** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

## `sklink.plotting.ForestDisplay` {#sklink.plotting.ForestDisplay}

```python
ForestDisplay(forest: Mapping[str, Any], *, scores: Mapping[str, Any] | None = None, top: int = 12) -> None
```

Bases: Display

How a relational random forest or gradient boosting model fitted.

The figure has three parts. The score of the forest as trees are added:
out of bag when the training data are given, and on a test set when one
is given, to see whether more trees would still help. The number of leaves
of each tree, one dot per tree (bars when the trees are too many to
stack), with the median. And a matrix of the
expressions most trees ask, one column per tree: a dot is bigger and
stronger the closer to the root the tree first asks the expression.

A gradient boosting model is drawn the same way, its trees in the order
they were fitted (one per class and iteration for more than two classes),
with its test score by iteration.

**Guides:** [Plot schemas, trees and predictions](../tutorials/plotting)

**Parameters:**

* **forest** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): Output of [`sklink.inspection.export_dict`](./sklink.inspection#sklink.inspection.export_dict) for a fitted relational
  forest or gradient boosting model. Only the estimator name, the task,
  the parameters and the nodes of the trees are kept.
* **scores** ([dict](https://docs.python.org/3/library/stdtypes.html#dict) or None): Scores after each tree, as returned by `from_estimator` in
  `to_dict()["data"]["scores"]`: `"metric"`, `"oob"`, `"test"`
  and `"coverage"` (the share of training samples with an
  out-of-bag tree), each a list with one value per tree or `None`,
  and `"unit"`: `"trees"`, or `"iterations"` for boosting.
* **top** ([int](https://docs.python.org/3/library/functions.html#int)): Number of expressions in the matrix, those asked by most trees.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If `forest` is not the export of a forest or gradient boosting
  model, a list of `scores` is longer than the forest (than its
  iterations, for `"unit": "iterations"`) or `top` is not a
  positive int.

TreeDisplay : One tree, node by node.
ImportanceDisplay : The importance of tables, columns and primitives.

**Examples:**

```pycon
>>> from sklink.datasets import load_shop
>>> from sklink.ensemble import RelationalRandomForestClassifier
>>> from sklink.plotting import ForestDisplay
>>> shop = load_shop()
>>> forest = RelationalRandomForestClassifier(
...     shop.database, entity="customers", key=0, n_estimators=5,
...     max_depth=2, random_state=0,
... ).fit(shop.X, shop.y)
>>> display = ForestDisplay.from_estimator(forest, shop.X, shop.y)
>>> print(display.to_text().splitlines()[0])
Relational random forest classifier: 5 trees, max_depth 2
```

**Functions:**

* [**from_estimator**](#sklink.plotting.ForestDisplay.from_estimator): Draw a fitted relational forest.
* [**save**](#sklink.plotting.ForestDisplay.save): Write the figure to a file chosen by its extension.
* [**show**](#sklink.plotting.ForestDisplay.show): Show the figure where the code runs.
* [**to_dict**](#sklink.plotting.ForestDisplay.to_dict): Return the data of the figure as a JSON-serializable dictionary.
* [**to_html**](#sklink.plotting.ForestDisplay.to_html): Return the figure as an HTML fragment with inline CSS and JavaScript.
* [**to_svg**](#sklink.plotting.ForestDisplay.to_svg): Return the figure as a standalone SVG document, without interaction.
* [**to_text**](#sklink.plotting.ForestDisplay.to_text): Return a plain-text summary of the figure.

**Attributes:**

* [**forest**](#sklink.plotting.ForestDisplay.forest):
* [**scores**](#sklink.plotting.ForestDisplay.scores):
* [**top**](#sklink.plotting.ForestDisplay.top):

### `sklink.plotting.ForestDisplay.forest` {#sklink.plotting.ForestDisplay.forest}

```python
forest = {'estimator': forest.get('estimator', 'RelationalRandomForest'), 'task': forest.get('task'), 'params': {k: params[k] for k in ('n_estimators', 'max_depth', 'max_features', 'bootstrap', 'learning_rate') if k in params}, 'n_iterations': n_iterations, 'estimators': [{'nodes': [{k: n[k] for k in _NODE_KEYS if k in n} for n in e['nodes']]} for e in estimators]}
```

### `sklink.plotting.ForestDisplay.from_estimator` {#sklink.plotting.ForestDisplay.from_estimator}

```python
from_estimator(estimator: Any, X: Any = None, y: Any = None, *, X_test: Any = None, y_test: Any = None, top: int = 12) -> ForestDisplay
```

Draw a fitted relational forest.

**Parameters:**

* **estimator** (relational forest or gradient boosting model): A fitted relational random forest or gradient boosting model, a
  [`Pipeline`](https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html) ending with one, or a fitted
  search whose `best_estimator_` is one.
* **X** (DataFrame or array - like): The training data, in the order given to `fit`, for the
  out-of-bag score after each tree. It needs the database, so a
  detached model must be rebound, and `bootstrap=True`. A boosting
  model has no out-of-bag score and does not use them.
* **y** (DataFrame or array - like): The training data, in the order given to `fit`, for the
  out-of-bag score after each tree. It needs the database, so a
  detached model must be rebound, and `bootstrap=True`. A boosting
  model has no out-of-bag score and does not use them.
* **X\_test** (DataFrame or array - like): Held-out data, for the score of the first `k` trees, or of the
  first `k` iterations of a boosting model.
* **y\_test** (DataFrame or array - like): Held-out data, for the score of the first `k` trees, or of the
  first `k` iterations of a boosting model.
* **top** ([int](https://docs.python.org/3/library/functions.html#int)): Number of expressions in the matrix.

**Returns:**

* **display** ([ForestDisplay](#sklink.plotting.ForestDisplay)):

**Raises:**

* [TypeError](https://docs.python.org/3/library/exceptions.html#TypeError): If `estimator` is not a relational forest or gradient boosting
  model.
* [NotFittedError](https://scikit-learn.org/stable/modules/generated/sklearn.exceptions.NotFittedError.html): If it is not fitted.

### `sklink.plotting.ForestDisplay.save` {#sklink.plotting.ForestDisplay.save}

```python
save(path: str | Path, *, theme: Theme = 'auto') -> None
```

Write the figure to a file chosen by its extension.

**Parameters:**

* **path** ([str](https://docs.python.org/3/library/stdtypes.html#str) or path - like): `.html` writes a standalone page with interaction, `.svg` the
  static figure and `.json` the output of `to_dict`.
* **theme** ((auto, light, dark)): Theme of HTML and SVG files.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If the extension is not `.html`, `.htm`, `.svg` or `.json`.

### `sklink.plotting.ForestDisplay.scores` {#sklink.plotting.ForestDisplay.scores}

```python
scores = _check_scores(scores, len(estimators), n_iterations)
```

### `sklink.plotting.ForestDisplay.show` {#sklink.plotting.ForestDisplay.show}

```python
show(*, theme: Theme = 'auto') -> None
```

Show the figure where the code runs.

In a notebook the figure is displayed in the output of the cell. In a
script or a terminal, it is written to a temporary HTML file that opens
in the web browser; if no browser can be opened, the text summary is
printed instead.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

### `sklink.plotting.ForestDisplay.to_dict` {#sklink.plotting.ForestDisplay.to_dict}

```python
to_dict() -> dict[str, Any]
```

Return the data of the figure as a JSON-serializable dictionary.

**Returns:**

* **data** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): `"format_version"`, `"kind"` (the figure), `"sklink_version"`
  and `"data"`, the inputs the figure is drawn from.

### `sklink.plotting.ForestDisplay.to_html` {#sklink.plotting.ForestDisplay.to_html}

```python
to_html(*, theme: Theme = 'auto') -> str
```

Return the figure as an HTML fragment with inline CSS and JavaScript.

The fragment loads nothing from the network. Without JavaScript, as in
an untrusted notebook or an exported page, it shows the same static
figure.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **html** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.ForestDisplay.to_svg` {#sklink.plotting.ForestDisplay.to_svg}

```python
to_svg(*, theme: Theme = 'auto') -> str
```

Return the figure as a standalone SVG document, without interaction.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **svg** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.ForestDisplay.to_text` {#sklink.plotting.ForestDisplay.to_text}

```python
to_text() -> str
```

Return a plain-text summary of the figure.

### `sklink.plotting.ForestDisplay.top` {#sklink.plotting.ForestDisplay.top}

```python
top = top
```

## `sklink.plotting.ImportanceDisplay` {#sklink.plotting.ImportanceDisplay}

```python
ImportanceDisplay(importances: Mapping[str, float], expressions: Sequence[Mapping[str, Any]], *, top: int = 10) -> None
```

Bases: Display

How the importance of a model flows from tables to columns to primitives.

The three stages show the same total split three ways, as
[`aggregate_importances`](./sklink.inspection#sklink.inspection.aggregate_importances) splits it with
`by="table"`, `by="column"` and `by="primitive"`: each expression
counts for the last table of its path and for its primitive, and shares
its importance equally among the columns it reads. Columns of `X` count
for the table `X`. Hovering a node in a notebook highlights its flows.

The impurity-based importances of a relational tree, forest or boosting
model favour expressions with many possible cuts.
[`sklearn.inspection.permutation_importance`](https://scikit-learn.org/stable/modules/generated/sklearn.inspection.permutation_importance.html) on held-out data is less
biased.

**Guides:** [Plot schemas, trees and predictions](../tutorials/plotting)

**Parameters:**

* **importances** (dict of str to float): Importance of each expression by canonical name, such as
  `aggregate_importances(model, by="expression")`.
* **expressions** (list of dict): Output of [`sklink.inspection.describe_expressions`](./sklink.inspection#sklink.inspection.describe_expressions), which names
  the table, columns and primitive of every expression.
* **top** ([int](https://docs.python.org/3/library/functions.html#int)): Number of columns drawn; the others are drawn together as
  `other columns`.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If `top` is not a positive int, or `importances` names an
  expression that `expressions` does not describe.

sklink.inspection.aggregate_importances : The same shares as a dictionary.

**Examples:**

```pycon
>>> from sklink.datasets import load_shop
>>> from sklink.plotting import ImportanceDisplay
>>> from sklink.tree import RelationalDecisionTreeClassifier
>>> shop = load_shop()
>>> tree = RelationalDecisionTreeClassifier(
...     shop.database, entity="customers", key=0, max_depth=1
... ).fit(shop.X, shop.y)
>>> print(ImportanceDisplay.from_estimator(tree).to_text())
orders 100.0%
    orders.* 100.0%
by primitive: count 100.0%
```

**Functions:**

* [**from_estimator**](#sklink.plotting.ImportanceDisplay.from_estimator): Draw the importances of a fitted relational model.
* [**save**](#sklink.plotting.ImportanceDisplay.save): Write the figure to a file chosen by its extension.
* [**show**](#sklink.plotting.ImportanceDisplay.show): Show the figure where the code runs.
* [**to_dict**](#sklink.plotting.ImportanceDisplay.to_dict): Return the data of the figure as a JSON-serializable dictionary.
* [**to_html**](#sklink.plotting.ImportanceDisplay.to_html): Return the figure as an HTML fragment with inline CSS and JavaScript.
* [**to_svg**](#sklink.plotting.ImportanceDisplay.to_svg): Return the figure as a standalone SVG document, without interaction.
* [**to_text**](#sklink.plotting.ImportanceDisplay.to_text): Return the importance of each table with its columns, and of each primitive.

**Attributes:**

* [**expressions**](#sklink.plotting.ImportanceDisplay.expressions):
* [**importances**](#sklink.plotting.ImportanceDisplay.importances):
* [**top**](#sklink.plotting.ImportanceDisplay.top):

### `sklink.plotting.ImportanceDisplay.expressions` {#sklink.plotting.ImportanceDisplay.expressions}

```python
expressions = [dict(e) for e in expressions]
```

### `sklink.plotting.ImportanceDisplay.from_estimator` {#sklink.plotting.ImportanceDisplay.from_estimator}

```python
from_estimator(estimator: Any, *, normalize: bool = True, top: int = 10, importances: Any = None) -> ImportanceDisplay
```

Draw the importances of a fitted relational model.

**Parameters:**

* **estimator** (relational model, featurizer or pipeline): What [`aggregate_importances`](./sklink.inspection#sklink.inspection.aggregate_importances) accepts: a
  fitted relational tree, forest or gradient boosting model, a
  [`Pipeline`](https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html) ending with one or holding a
  `RelationalFeaturizer` in front of a scikit-learn model, a
  fitted featurizer with `importances`, or a fitted search whose
  `best_estimator_` is one of them. A detached model works.
* **normalize** ([bool](https://docs.python.org/3/library/functions.html#bool)): Passed to [`aggregate_importances`](./sklink.inspection#sklink.inspection.aggregate_importances).
  For a relational model, `True` starts from
  `expression_importances_` and `False` from the mean decrease
  in impurity before normalization, which gives other shares for a
  forest or a boosting model. Pass `False` to draw importances
  that can be negative, such as permutation importances. The figure
  shows shares of the total of the positive importances either way
  and leaves out the others.
* **top** ([int](https://docs.python.org/3/library/functions.html#int)): Number of columns drawn; the others are drawn together as
  `other columns`.
* **importances** (array-like of shape (n_columns,)): Passed to [`aggregate_importances`](./sklink.inspection#sklink.inspection.aggregate_importances): the
  importance of each column that the model behind a featurizer
  receives, or of each output column of a featurizer.

**Returns:**

* **display** ([ImportanceDisplay](#sklink.plotting.ImportanceDisplay)):

**Raises:**

* [TypeError](https://docs.python.org/3/library/exceptions.html#TypeError): If `estimator` is none of the above, or `importances` is
  missing or not accepted, as in
  [`aggregate_importances`](./sklink.inspection#sklink.inspection.aggregate_importances).
* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If `importances` does not describe the columns, as in
  [`aggregate_importances`](./sklink.inspection#sklink.inspection.aggregate_importances).
* [NotFittedError](https://scikit-learn.org/stable/modules/generated/sklearn.exceptions.NotFittedError.html): If it is not fitted.

### `sklink.plotting.ImportanceDisplay.importances` {#sklink.plotting.ImportanceDisplay.importances}

```python
importances = {k: float(v) for k, v in importances.items()}
```

### `sklink.plotting.ImportanceDisplay.save` {#sklink.plotting.ImportanceDisplay.save}

```python
save(path: str | Path, *, theme: Theme = 'auto') -> None
```

Write the figure to a file chosen by its extension.

**Parameters:**

* **path** ([str](https://docs.python.org/3/library/stdtypes.html#str) or path - like): `.html` writes a standalone page with interaction, `.svg` the
  static figure and `.json` the output of `to_dict`.
* **theme** ((auto, light, dark)): Theme of HTML and SVG files.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If the extension is not `.html`, `.htm`, `.svg` or `.json`.

### `sklink.plotting.ImportanceDisplay.show` {#sklink.plotting.ImportanceDisplay.show}

```python
show(*, theme: Theme = 'auto') -> None
```

Show the figure where the code runs.

In a notebook the figure is displayed in the output of the cell. In a
script or a terminal, it is written to a temporary HTML file that opens
in the web browser; if no browser can be opened, the text summary is
printed instead.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

### `sklink.plotting.ImportanceDisplay.to_dict` {#sklink.plotting.ImportanceDisplay.to_dict}

```python
to_dict() -> dict[str, Any]
```

Return the data of the figure as a JSON-serializable dictionary.

**Returns:**

* **data** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): `"format_version"`, `"kind"` (the figure), `"sklink_version"`
  and `"data"`, the inputs the figure is drawn from.

### `sklink.plotting.ImportanceDisplay.to_html` {#sklink.plotting.ImportanceDisplay.to_html}

```python
to_html(*, theme: Theme = 'auto') -> str
```

Return the figure as an HTML fragment with inline CSS and JavaScript.

The fragment loads nothing from the network. Without JavaScript, as in
an untrusted notebook or an exported page, it shows the same static
figure.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **html** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.ImportanceDisplay.to_svg` {#sklink.plotting.ImportanceDisplay.to_svg}

```python
to_svg(*, theme: Theme = 'auto') -> str
```

Return the figure as a standalone SVG document, without interaction.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **svg** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.ImportanceDisplay.to_text` {#sklink.plotting.ImportanceDisplay.to_text}

```python
to_text() -> str
```

Return the importance of each table with its columns, and of each primitive.

**Returns:**

* **text** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.ImportanceDisplay.top` {#sklink.plotting.ImportanceDisplay.top}

```python
top = int(top)
```

## `sklink.plotting.LiveFit` {#sklink.plotting.LiveFit}

```python
LiveFit(*, oob: bool = True, refresh: float = 0.25, output: Output = 'auto') -> None
```

Bases: Display

Draw the progress of `fit` while it runs, and the model when it ends.

A callback for the experimental callbacks of scikit-learn 1.9 or later:
pass it to `set_callbacks` of a relational tree, forest or gradient
boosting model. While a forest fits, each tree is a cell that fills as
the tree ends (each iteration, for boosting), with the
time spent and an estimate of the time left. While a tree fits, the count
of its nodes grows. In a notebook the figure updates in the output of the
cell (the fits run by one cell, as in a search, share it); in a terminal
one line updates in place.

When the fit ends, the figure reads the fitted model: the number of
trees, leaves and nodes and, for a forest grown with `bootstrap=True`,
the out-of-bag score after each tree, and for a boosting model its
training (and validation) loss. The callback keeps the last fit,
so it can be shown again, saved or turned into a dictionary like any
display. It never stops a fit, and an error while drawing is recorded
in `record_["error"]` instead of failing the fit.

**Guides:** [Plot schemas, trees and predictions](../tutorials/plotting)

**Parameters:**

* **oob** ([bool](https://docs.python.org/3/library/functions.html#bool)): For a forest grown with `bootstrap=True`, compute the out-of-bag
  score after each tree once the fit ends, on the training samples
  that have an out-of-bag tree (see `ForestDisplay`). It
  predicts the training data with every tree, which takes about as long
  as `oob_score=True`.
* **refresh** ([float](https://docs.python.org/3/library/functions.html#float)): Least time, in seconds, between two updates of the figure.
* **output** ((auto, text, none)): Where progress shows: `"auto"` updates the figure in a notebook and
  a line in a terminal, `"text"` always writes the line (to
  `sys.stderr`; where it is not a console, as in a log, only the
  last line) and `"none"` only records the fit.

**Attributes:**

* [**record\_**](#sklink.plotting.LiveFit.record_) ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): The last fit: `"estimator"`, `"unit"` (`"tree"`,
  `"iteration"` or `"node"`), `"total"` (`None` when not known
  in advance), `"done"`, `"ends"` (seconds from the start at which
  each subtask ended), `"status"` (`"running"`, `"finished"`,
  `"stopped"` or `"failed"`), `"elapsed"`, `"summary"`,
  `"scores"` and `"error"`: the
  last error while drawing, or why the fit was not followed.

ForestDisplay : The fitted forest, with its scores by number of trees.

Trees of a forest are reported in order, in the main process, whatever
`n_jobs` is; the trees of a forest report no nodes. It follows one fit
at a time: a fit that starts while another one runs, as in a search
with a threading backend, is not recorded. The callback is
not propagated to the estimators inside a meta-estimator: set it on the
relational model itself.

**Examples:**

```pycon
>>> from sklink.datasets import load_shop
>>> from sklink.ensemble import RelationalRandomForestClassifier
>>> from sklink.plotting import LiveFit
>>> shop = load_shop()
>>> forest = RelationalRandomForestClassifier(
...     shop.database, entity="customers", key=0, n_estimators=5,
...     max_depth=2, random_state=0,
... )
>>> live = LiveFit(output="none")
>>> forest = forest.set_callbacks(live).fit(shop.X, shop.y)
>>> print(live.record_["status"], live.record_["done"])
finished 5
```

**Functions:**

* [**on_fit_task_begin**](#sklink.plotting.LiveFit.on_fit_task_begin): Note the size of the fit when its root task begins.
* [**on_fit_task_end**](#sklink.plotting.LiveFit.on_fit_task_end): Count a tree or a node as it ends; never asks to stop.
* [**save**](#sklink.plotting.LiveFit.save): Write the figure to a file chosen by its extension.
* [**setup**](#sklink.plotting.LiveFit.setup): Start recording a fit; called by scikit-learn before `fit` runs.
* [**show**](#sklink.plotting.LiveFit.show): Show the figure where the code runs.
* [**teardown**](#sklink.plotting.LiveFit.teardown): Read the fitted model and draw the final figure.
* [**to_dict**](#sklink.plotting.LiveFit.to_dict): Return the data of the figure as a JSON-serializable dictionary.
* [**to_html**](#sklink.plotting.LiveFit.to_html): Return the figure as an HTML fragment with inline CSS and JavaScript.
* [**to_svg**](#sklink.plotting.LiveFit.to_svg): Return the figure as a standalone SVG document, without interaction.
* [**to_text**](#sklink.plotting.LiveFit.to_text): Return a plain-text summary of the last fit.

### `sklink.plotting.LiveFit.on_fit_task_begin` {#sklink.plotting.LiveFit.on_fit_task_begin}

```python
on_fit_task_begin(estimator: Any, context: Any, *, X: Any = None, y: Any = None) -> None
```

Note the size of the fit when its root task begins.

### `sklink.plotting.LiveFit.on_fit_task_end` {#sklink.plotting.LiveFit.on_fit_task_end}

```python
on_fit_task_end(estimator: Any, context: Any) -> bool
```

Count a tree or a node as it ends; never asks to stop.

### `sklink.plotting.LiveFit.oob` {#sklink.plotting.LiveFit.oob}

```python
oob = bool(oob)
```

### `sklink.plotting.LiveFit.output` {#sklink.plotting.LiveFit.output}

```python
output = output
```

### `sklink.plotting.LiveFit.record_` {#sklink.plotting.LiveFit.record\_}

```python
record_: dict[str, Any] = _empty()
```

### `sklink.plotting.LiveFit.refresh` {#sklink.plotting.LiveFit.refresh}

```python
refresh = float(refresh)
```

### `sklink.plotting.LiveFit.save` {#sklink.plotting.LiveFit.save}

```python
save(path: str | Path, *, theme: Theme = 'auto') -> None
```

Write the figure to a file chosen by its extension.

**Parameters:**

* **path** ([str](https://docs.python.org/3/library/stdtypes.html#str) or path - like): `.html` writes a standalone page with interaction, `.svg` the
  static figure and `.json` the output of `to_dict`.
* **theme** ((auto, light, dark)): Theme of HTML and SVG files.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If the extension is not `.html`, `.htm`, `.svg` or `.json`.

### `sklink.plotting.LiveFit.setup` {#sklink.plotting.LiveFit.setup}

```python
setup(estimator: Any, context: Any) -> None
```

Start recording a fit; called by scikit-learn before `fit` runs.

### `sklink.plotting.LiveFit.show` {#sklink.plotting.LiveFit.show}

```python
show(*, theme: Theme = 'auto') -> None
```

Show the figure where the code runs.

In a notebook the figure is displayed in the output of the cell. In a
script or a terminal, it is written to a temporary HTML file that opens
in the web browser; if no browser can be opened, the text summary is
printed instead.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

### `sklink.plotting.LiveFit.teardown` {#sklink.plotting.LiveFit.teardown}

```python
teardown(estimator: Any, context: Any) -> None
```

Read the fitted model and draw the final figure.

Errors here are recorded in `record_["error"]` and never raised:
scikit-learn raises the errors of `teardown`, and the figure must
not fail a fit that succeeded.

### `sklink.plotting.LiveFit.to_dict` {#sklink.plotting.LiveFit.to_dict}

```python
to_dict() -> dict[str, Any]
```

Return the data of the figure as a JSON-serializable dictionary.

**Returns:**

* **data** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): `"format_version"`, `"kind"` (the figure), `"sklink_version"`
  and `"data"`, the inputs the figure is drawn from.

### `sklink.plotting.LiveFit.to_html` {#sklink.plotting.LiveFit.to_html}

```python
to_html(*, theme: Theme = 'auto') -> str
```

Return the figure as an HTML fragment with inline CSS and JavaScript.

The fragment loads nothing from the network. Without JavaScript, as in
an untrusted notebook or an exported page, it shows the same static
figure.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **html** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.LiveFit.to_svg` {#sklink.plotting.LiveFit.to_svg}

```python
to_svg(*, theme: Theme = 'auto') -> str
```

Return the figure as a standalone SVG document, without interaction.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **svg** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.LiveFit.to_text` {#sklink.plotting.LiveFit.to_text}

```python
to_text() -> str
```

Return a plain-text summary of the last fit.

## `sklink.plotting.SchemaDisplay` {#sklink.plotting.SchemaDisplay}

```python
SchemaDisplay(schema: Mapping[str, Any], *, n_rows: Mapping[str, int] | None = None, entity: str | None = None, target: Mapping[str, Any] | None = None, used_columns: Sequence[str] | None = None, used_relationships: Sequence[str] | None = None, statistics: Mapping[str, Mapping[str, Any]] | None = None) -> None
```

Bases: Display

Tables, keys and relationships of a database, as given to a model.

Each table is a card with its columns, their semantic types and the
primary (`PK`) and foreign (`FK`) keys. Relationships link a foreign
key to the key it references, with `n` on the side of the many rows.
The entity, the table of the samples, comes first and carries the target
when it is known. For a fitted model, the columns and relationships that
its expressions read are drawn in eucalyptus.

`Database` objects show this figure in notebooks.

**Guides:** [Plot schemas, trees and predictions](../tutorials/plotting)

**Parameters:**

* **schema** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): Output of [`sklink.Schema.to_dict`](./sklink#sklink.Schema.to_dict), or the `"schema"` of
  [`sklink.inspection.export_dict`](./sklink.inspection#sklink.inspection.export_dict).
* **n\_rows** (dict of str to int or None): Number of rows of each table.
* **entity** ([str](https://docs.python.org/3/library/stdtypes.html#str) or None): Table of the samples, drawn first.
* **target** ([dict](https://docs.python.org/3/library/stdtypes.html#dict) or None): Summary of the target: `{"task": "classification", "classes": [...],
  "counts": [...]}` or `{"task": "regression", "n": ..., "min": ...,
  "mean": ..., "max": ...}`. `"counts"` and the statistics are
  optional.
* **used_columns** (list of str or None): Columns read by a model, as `"table.column"`; `"table.*"` marks a
  table whose rows are counted.
* **used_relationships** (list of str or None): Names of the relationships followed by a model.
* **statistics** (dict of str to dict or None): Fan-out of each relationship, by name: the `"statistics"` of
  `Database.describe(statistics=True)`. Each relationship then gets a
  histogram of the number of child rows per parent row.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If `schema` is not the output of [`sklink.Schema.to_dict`](./sklink#sklink.Schema.to_dict),
  `entity` is not one of its tables, or `target` is malformed.

sklink.inspection.describe_expressions : What each expression reads.

**Examples:**

```pycon
>>> from sklink.datasets import load_shop
>>> from sklink.plotting import SchemaDisplay
>>> shop = load_shop()
>>> display = SchemaDisplay.from_database(shop.database, entity="customers")
>>> display
<SchemaDisplay: 4 tables, 3 relationships>
```

**Functions:**

* [**from_database**](#sklink.plotting.SchemaDisplay.from_database): Draw a database.
* [**from_estimator**](#sklink.plotting.SchemaDisplay.from_estimator): Draw the database of a fitted model and what its expressions read.
* [**save**](#sklink.plotting.SchemaDisplay.save): Write the figure to a file chosen by its extension.
* [**show**](#sklink.plotting.SchemaDisplay.show): Show the figure where the code runs.
* [**to_dict**](#sklink.plotting.SchemaDisplay.to_dict): Return the data of the figure as a JSON-serializable dictionary.
* [**to_html**](#sklink.plotting.SchemaDisplay.to_html): Return the figure as an HTML fragment with inline CSS and JavaScript.
* [**to_svg**](#sklink.plotting.SchemaDisplay.to_svg): Return the figure as a standalone SVG document, without interaction.
* [**to_text**](#sklink.plotting.SchemaDisplay.to_text): Return the tables, their columns and the relationships as text.

**Attributes:**

* [**entity**](#sklink.plotting.SchemaDisplay.entity):
* [**n\_rows**](#sklink.plotting.SchemaDisplay.n_rows):
* [**schema**](#sklink.plotting.SchemaDisplay.schema):
* [**statistics**](#sklink.plotting.SchemaDisplay.statistics):
* [**target**](#sklink.plotting.SchemaDisplay.target):
* [**used_columns**](#sklink.plotting.SchemaDisplay.used_columns):
* [**used_relationships**](#sklink.plotting.SchemaDisplay.used_relationships):

### `sklink.plotting.SchemaDisplay.entity` {#sklink.plotting.SchemaDisplay.entity}

```python
entity = entity
```

### `sklink.plotting.SchemaDisplay.from_database` {#sklink.plotting.SchemaDisplay.from_database}

```python
from_database(database: Any, *, entity: str | None = None, y: Any = None) -> SchemaDisplay
```

Draw a database.

**Parameters:**

* **database** ([Database](./sklink.database#sklink.database.Database)): Database to draw.
* **entity** ([str](https://docs.python.org/3/library/stdtypes.html#str) or None): Table of the samples, drawn first.
* **y** (array-like of shape (n_samples,) or None): Target, summarized on the entity: class counts, or minimum, mean and
  maximum when it holds non-integer numbers.

**Returns:**

* **display** ([SchemaDisplay](#sklink.plotting.SchemaDisplay)):

**Raises:**

* [TypeError](https://docs.python.org/3/library/exceptions.html#TypeError): If `database` is not a [`sklink.Database`](./sklink#sklink.Database).
* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If `entity` is not a table of `database` or `y` is not
  one-dimensional.

### `sklink.plotting.SchemaDisplay.from_estimator` {#sklink.plotting.SchemaDisplay.from_estimator}

```python
from_estimator(estimator: Any, y: Any = None) -> SchemaDisplay
```

Draw the database of a fitted model and what its expressions read.

**Parameters:**

* **estimator** (relational tree, forest or featurizer): A fitted estimator, a [`Pipeline`](https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html) ending
  with one or holding one featurizer in front of a scikit-learn
  model, or a fitted search whose `best_estimator_` is one of
  them. A detached model works, without row counts.
* **y** (array-like of shape (n_samples,) or None): Target used to summarize the classes or values. By default, a tree
  summarizes its training samples, a forest shows its classes (or
  that it is a regressor) and a featurizer shows no target.

**Returns:**

* **display** ([SchemaDisplay](#sklink.plotting.SchemaDisplay)):

**Raises:**

* [TypeError](https://docs.python.org/3/library/exceptions.html#TypeError): If `estimator` is not a relational featurizer, tree or forest.
* [NotFittedError](https://scikit-learn.org/stable/modules/generated/sklearn.exceptions.NotFittedError.html): If it is not fitted.

### `sklink.plotting.SchemaDisplay.n_rows` {#sklink.plotting.SchemaDisplay.n_rows}

```python
n_rows = None if n_rows is None else {k: int(v) for k, v in n_rows.items()}
```

### `sklink.plotting.SchemaDisplay.save` {#sklink.plotting.SchemaDisplay.save}

```python
save(path: str | Path, *, theme: Theme = 'auto') -> None
```

Write the figure to a file chosen by its extension.

**Parameters:**

* **path** ([str](https://docs.python.org/3/library/stdtypes.html#str) or path - like): `.html` writes a standalone page with interaction, `.svg` the
  static figure and `.json` the output of `to_dict`.
* **theme** ((auto, light, dark)): Theme of HTML and SVG files.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If the extension is not `.html`, `.htm`, `.svg` or `.json`.

### `sklink.plotting.SchemaDisplay.schema` {#sklink.plotting.SchemaDisplay.schema}

```python
schema = dict(schema)
```

### `sklink.plotting.SchemaDisplay.show` {#sklink.plotting.SchemaDisplay.show}

```python
show(*, theme: Theme = 'auto') -> None
```

Show the figure where the code runs.

In a notebook the figure is displayed in the output of the cell. In a
script or a terminal, it is written to a temporary HTML file that opens
in the web browser; if no browser can be opened, the text summary is
printed instead.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

### `sklink.plotting.SchemaDisplay.statistics` {#sklink.plotting.SchemaDisplay.statistics}

```python
statistics = None if statistics is None else {k: dict(v) for k, v in statistics.items()}
```

### `sklink.plotting.SchemaDisplay.target` {#sklink.plotting.SchemaDisplay.target}

```python
target = None if target is None else dict(target)
```

### `sklink.plotting.SchemaDisplay.to_dict` {#sklink.plotting.SchemaDisplay.to_dict}

```python
to_dict() -> dict[str, Any]
```

Return the data of the figure as a JSON-serializable dictionary.

**Returns:**

* **data** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): `"format_version"`, `"kind"` (the figure), `"sklink_version"`
  and `"data"`, the inputs the figure is drawn from.

### `sklink.plotting.SchemaDisplay.to_html` {#sklink.plotting.SchemaDisplay.to_html}

```python
to_html(*, theme: Theme = 'auto') -> str
```

Return the figure as an HTML fragment with inline CSS and JavaScript.

The fragment loads nothing from the network. Without JavaScript, as in
an untrusted notebook or an exported page, it shows the same static
figure.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **html** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.SchemaDisplay.to_svg` {#sklink.plotting.SchemaDisplay.to_svg}

```python
to_svg(*, theme: Theme = 'auto') -> str
```

Return the figure as a standalone SVG document, without interaction.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **svg** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.SchemaDisplay.to_text` {#sklink.plotting.SchemaDisplay.to_text}

```python
to_text() -> str
```

Return the tables, their columns and the relationships as text.

**Returns:**

* **text** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.SchemaDisplay.used_columns` {#sklink.plotting.SchemaDisplay.used_columns}

```python
used_columns = None if used_columns is None else list(used_columns)
```

### `sklink.plotting.SchemaDisplay.used_relationships` {#sklink.plotting.SchemaDisplay.used_relationships}

```python
used_relationships = None if used_relationships is None else list(used_relationships)
```

## `sklink.plotting.SearchDisplay` {#sklink.plotting.SearchDisplay}

```python
SearchDisplay(tree: Mapping[str, Any], *, node: int = 0) -> None
```

Bases: Display

The questions a relational tree scored at one node, the chosen one first.

Every recorded candidate is a row with its expression, the condition that
sends samples left and, on one axis, its weighted impurity decrease. Dots
are filled for aggregates whose rows are filtered (`[type == 'x']`),
open for aggregates without a filter and gray for columns of `X`. The
question the node asks is ringed, and the figure says by how much it beat
the runner-up and the best question without a filter.

The tree keeps the `record_candidates` best questions of each node
(five by default for a tree, none for a forest). Grow it with a larger
`record_candidates` to see more.

**Guides:** [Plot schemas, trees and predictions](../tutorials/plotting)

**Parameters:**

* **tree** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): Output of [`sklink.inspection.export_dict`](./sklink.inspection#sklink.inspection.export_dict) for a relational tree
  grown with `record_candidates > 0`.
* **node** ([int](https://docs.python.org/3/library/functions.html#int)): Id of a split node.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If `node` is not a split node of `tree`, or it has no recorded
  candidates.

TreeDisplay : The whole tree, node by node.

**Examples:**

```pycon
>>> from sklink.datasets import load_shop
>>> from sklink.plotting import SearchDisplay
>>> from sklink.tree import RelationalDecisionTreeClassifier
>>> shop = load_shop()
>>> tree = RelationalDecisionTreeClassifier(
...     shop.database, entity="customers", key=0, max_depth=1
... ).fit(shop.X, shop.y)
>>> print(SearchDisplay.from_estimator(tree).to_text().splitlines()[0])
node 0 (depth 0, 24 samples): 5 best questions recorded
```

**Functions:**

* [**from_estimator**](#sklink.plotting.SearchDisplay.from_estimator): Draw the questions scored at one node of a fitted relational tree.
* [**save**](#sklink.plotting.SearchDisplay.save): Write the figure to a file chosen by its extension.
* [**show**](#sklink.plotting.SearchDisplay.show): Show the figure where the code runs.
* [**to_dict**](#sklink.plotting.SearchDisplay.to_dict): Return the data of the figure as a JSON-serializable dictionary.
* [**to_html**](#sklink.plotting.SearchDisplay.to_html): Return the figure as an HTML fragment with inline CSS and JavaScript.
* [**to_svg**](#sklink.plotting.SearchDisplay.to_svg): Return the figure as a standalone SVG document, without interaction.
* [**to_text**](#sklink.plotting.SearchDisplay.to_text): Return a plain-text summary of the figure.

**Attributes:**

* [**node**](#sklink.plotting.SearchDisplay.node):
* [**tree**](#sklink.plotting.SearchDisplay.tree) ([dict](https://docs.python.org/3/library/stdtypes.html#dict)\[[str](https://docs.python.org/3/library/stdtypes.html#str), [Any](https://docs.python.org/3/library/typing.html#typing.Any)]):

### `sklink.plotting.SearchDisplay.from_estimator` {#sklink.plotting.SearchDisplay.from_estimator}

```python
from_estimator(estimator: Any, *, node: int = 0) -> SearchDisplay
```

Draw the questions scored at one node of a fitted relational tree.

**Parameters:**

* **estimator** (relational tree): A fitted relational decision tree grown with
  `record_candidates > 0`, a [`Pipeline`](https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html)
  ending with one, or a fitted search whose `best_estimator_` is
  one. To draw a tree of a forest grown with `record_candidates`,
  pass `forest.estimators_[i]`; of a gradient boosting model,
  `model.estimators_[i, k]`.
* **node** ([int](https://docs.python.org/3/library/functions.html#int)): Id of a split node; `0` is the root.

**Returns:**

* **display** ([SearchDisplay](#sklink.plotting.SearchDisplay)):

**Raises:**

* [TypeError](https://docs.python.org/3/library/exceptions.html#TypeError): If `estimator` is not a relational tree.
* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If `node` is not a split node with recorded candidates.

### `sklink.plotting.SearchDisplay.node` {#sklink.plotting.SearchDisplay.node}

```python
node = node
```

### `sklink.plotting.SearchDisplay.save` {#sklink.plotting.SearchDisplay.save}

```python
save(path: str | Path, *, theme: Theme = 'auto') -> None
```

Write the figure to a file chosen by its extension.

**Parameters:**

* **path** ([str](https://docs.python.org/3/library/stdtypes.html#str) or path - like): `.html` writes a standalone page with interaction, `.svg` the
  static figure and `.json` the output of `to_dict`.
* **theme** ((auto, light, dark)): Theme of HTML and SVG files.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If the extension is not `.html`, `.htm`, `.svg` or `.json`.

### `sklink.plotting.SearchDisplay.show` {#sklink.plotting.SearchDisplay.show}

```python
show(*, theme: Theme = 'auto') -> None
```

Show the figure where the code runs.

In a notebook the figure is displayed in the output of the cell. In a
script or a terminal, it is written to a temporary HTML file that opens
in the web browser; if no browser can be opened, the text summary is
printed instead.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

### `sklink.plotting.SearchDisplay.to_dict` {#sklink.plotting.SearchDisplay.to_dict}

```python
to_dict() -> dict[str, Any]
```

Return the data of the figure as a JSON-serializable dictionary.

**Returns:**

* **data** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): `"format_version"`, `"kind"` (the figure), `"sklink_version"`
  and `"data"`, the inputs the figure is drawn from.

### `sklink.plotting.SearchDisplay.to_html` {#sklink.plotting.SearchDisplay.to_html}

```python
to_html(*, theme: Theme = 'auto') -> str
```

Return the figure as an HTML fragment with inline CSS and JavaScript.

The fragment loads nothing from the network. Without JavaScript, as in
an untrusted notebook or an exported page, it shows the same static
figure.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **html** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.SearchDisplay.to_svg` {#sklink.plotting.SearchDisplay.to_svg}

```python
to_svg(*, theme: Theme = 'auto') -> str
```

Return the figure as a standalone SVG document, without interaction.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **svg** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.SearchDisplay.to_text` {#sklink.plotting.SearchDisplay.to_text}

```python
to_text() -> str
```

Return a plain-text summary of the figure.

### `sklink.plotting.SearchDisplay.tree` {#sklink.plotting.SearchDisplay.tree}

```python
tree: dict[str, Any] = {'estimator': tree.get('estimator'), 'entity': tree.get('entity'), 'nodes': [self._entry], 'expressions': [{'name': n, 'definition': d} for n, d in sorted(definitions.items())]}
```

## `sklink.plotting.TreeDisplay` {#sklink.plotting.TreeDisplay}

```python
TreeDisplay(tree: Mapping[str, Any], *, explanation: Mapping[str, Any] | None = None, max_depth: int | None = 4) -> None
```

Bases: Display

Relational decision tree, drawn from [`export_dict`](./sklink.inspection#sklink.inspection.export_dict).

Each node is a card with its question, its number of training samples and
the share of each class (the mean value, in regression; the cluster of
each leaf, for a clustering tree). Edges are as
wide as the samples they carry and are labeled with the condition. In a
notebook, clicking a node shows its detail: the samples that reach it,
how much its split lowers the impurity, what its expression reads from
the database and the rules that lead to it. With a sample, its decision
path is drawn in coral.

Create it with `from_estimator`, or from saved dictionaries with the
constructor.

**Guides:** [Plot schemas, trees and predictions](../tutorials/plotting)

**Parameters:**

* **tree** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): Output of [`sklink.inspection.export_dict`](./sklink.inspection#sklink.inspection.export_dict) for one tree, or of
  `json.loads` on [`sklink.inspection.export_json`](./sklink.inspection#sklink.inspection.export_json).
* **explanation** ([dict](https://docs.python.org/3/library/stdtypes.html#dict) or None): One entry of [`sklink.inspection.explain`](./sklink.inspection#sklink.inspection.explain) for this tree. Its
  decision path is drawn in coral.
* **max_depth** ([int](https://docs.python.org/3/library/functions.html#int) or None): Deepest level drawn; deeper subtrees are folded into their top node,
  which shows how many nodes it hides. `None` draws every node.

sklink.inspection.export_text : The rules of a tree as text.
ExplanationDisplay : The decision path of one sample, step by step.

**Examples:**

```pycon
>>> from sklink.datasets import load_shop
>>> from sklink.plotting import TreeDisplay
>>> from sklink.tree import RelationalDecisionTreeClassifier
>>> shop = load_shop()
>>> tree = RelationalDecisionTreeClassifier(
...     shop.database, entity="customers", key=0, max_depth=2
... ).fit(shop.X, shop.y)
>>> display = TreeDisplay.from_estimator(tree, shop.X)  # follows the first row
>>> display
<TreeDisplay: 3 nodes, depth 1>
>>> print(display.to_text())
|--- count(orders) <= 2.5
|   |--- class: 0
|--- count(orders) > 2.5
|   |--- class: 1
```

**Functions:**

* [**from_estimator**](#sklink.plotting.TreeDisplay.from_estimator): Draw a fitted relational tree.
* [**save**](#sklink.plotting.TreeDisplay.save): Write the figure to a file chosen by its extension.
* [**show**](#sklink.plotting.TreeDisplay.show): Show the figure where the code runs.
* [**to_dict**](#sklink.plotting.TreeDisplay.to_dict): Return the data of the figure as a JSON-serializable dictionary.
* [**to_html**](#sklink.plotting.TreeDisplay.to_html): Return the figure as an HTML fragment with inline CSS and JavaScript.
* [**to_svg**](#sklink.plotting.TreeDisplay.to_svg): Return the figure as a standalone SVG document, without interaction.
* [**to_text**](#sklink.plotting.TreeDisplay.to_text): Return the rules of the drawn tree as text.

**Attributes:**

* [**explanation**](#sklink.plotting.TreeDisplay.explanation):
* [**max_depth**](#sklink.plotting.TreeDisplay.max_depth):
* [**tree**](#sklink.plotting.TreeDisplay.tree):

### `sklink.plotting.TreeDisplay.explanation` {#sklink.plotting.TreeDisplay.explanation}

```python
explanation = None if explanation is None else dict(explanation)
```

### `sklink.plotting.TreeDisplay.from_estimator` {#sklink.plotting.TreeDisplay.from_estimator}

```python
from_estimator(estimator: Any, X: Any = None, *, max_depth: int | None = 4) -> TreeDisplay
```

Draw a fitted relational tree.

**Parameters:**

* **estimator** (relational tree): A fitted relational decision tree or clustering tree, a
  [`Pipeline`](https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html) ending with one, or a fitted
  search whose `best_estimator_` is one. To draw a tree of a forest,
  pass `forest.estimators_[i]`.
* **X** (DataFrame or array - like or None): Population table. The decision path of its first row is drawn in
  coral; it needs the database, so a detached model must be rebound.
* **max_depth** ([int](https://docs.python.org/3/library/functions.html#int) or None): Deepest level drawn. `None` draws every node.

**Returns:**

* **display** ([TreeDisplay](#sklink.plotting.TreeDisplay)):

### `sklink.plotting.TreeDisplay.max_depth` {#sklink.plotting.TreeDisplay.max_depth}

```python
max_depth = max_depth
```

### `sklink.plotting.TreeDisplay.save` {#sklink.plotting.TreeDisplay.save}

```python
save(path: str | Path, *, theme: Theme = 'auto') -> None
```

Write the figure to a file chosen by its extension.

**Parameters:**

* **path** ([str](https://docs.python.org/3/library/stdtypes.html#str) or path - like): `.html` writes a standalone page with interaction, `.svg` the
  static figure and `.json` the output of `to_dict`.
* **theme** ((auto, light, dark)): Theme of HTML and SVG files.

**Raises:**

* [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError): If the extension is not `.html`, `.htm`, `.svg` or `.json`.

### `sklink.plotting.TreeDisplay.show` {#sklink.plotting.TreeDisplay.show}

```python
show(*, theme: Theme = 'auto') -> None
```

Show the figure where the code runs.

In a notebook the figure is displayed in the output of the cell. In a
script or a terminal, it is written to a temporary HTML file that opens
in the web browser; if no browser can be opened, the text summary is
printed instead.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

### `sklink.plotting.TreeDisplay.to_dict` {#sklink.plotting.TreeDisplay.to_dict}

```python
to_dict() -> dict[str, Any]
```

Return the data of the figure as a JSON-serializable dictionary.

**Returns:**

* **data** ([dict](https://docs.python.org/3/library/stdtypes.html#dict)): `"format_version"`, `"kind"` (the figure), `"sklink_version"`
  and `"data"`, the inputs the figure is drawn from.

### `sklink.plotting.TreeDisplay.to_html` {#sklink.plotting.TreeDisplay.to_html}

```python
to_html(*, theme: Theme = 'auto') -> str
```

Return the figure as an HTML fragment with inline CSS and JavaScript.

The fragment loads nothing from the network. Without JavaScript, as in
an untrusted notebook or an exported page, it shows the same static
figure.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **html** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.TreeDisplay.to_svg` {#sklink.plotting.TreeDisplay.to_svg}

```python
to_svg(*, theme: Theme = 'auto') -> str
```

Return the figure as a standalone SVG document, without interaction.

**Parameters:**

* **theme** ((auto, light, dark)): `"auto"` follows the host and the system color scheme.

**Returns:**

* **svg** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.TreeDisplay.to_text` {#sklink.plotting.TreeDisplay.to_text}

```python
to_text() -> str
```

Return the rules of the drawn tree as text.

The layout is the one of [`sklink.inspection.export_text`](./sklink.inspection#sklink.inspection.export_text).
Subtrees folded by `max_depth` read `truncated branch of n nodes`.

**Returns:**

* **text** ([str](https://docs.python.org/3/library/stdtypes.html#str)):

### `sklink.plotting.TreeDisplay.tree` {#sklink.plotting.TreeDisplay.tree}

```python
tree = dict(tree)
```

:::
