Plotting
Diagnostic plots for fitted estimators.
Every function takes a fitted estimator and draws on matplotlib axes. The same plots are
available as methods: estimator.plot(kind=...) and estimator.plot_<kind>(...).
Available kinds
"memberships"— the learned fuzzy sets, one panel per feature."history"— loss or a metric per epoch, with the validation curve and the best epoch when they were recorded."rules"— the rule base as a table: the fuzzy set that each rule uses on each feature."rule_activation"— mean normalized firing strength of each rule, split by class when labels are given."diagnostics"— confusion matrix and decision margin for classifiers; predicted against observed and residuals for regressors."feature_importance"— the features that weigh most in the consequents."gates"— the gates of the features and rules that a gated family kept, with the thresholds they passed.
Conventions
- matplotlib is an optional dependency (
pip install highfis[plot]) and is only imported when a plot is requested. - Single-panel plots accept
axand return theAxes. Multi-panel plots accept a sequence of axes inaxand return theFigure. - In an interactive session or a notebook a plot is displayed and nothing is returned,
as with a plot command; in a script, or with
show=False, theAxesor theFigureis returned and nothing is displayed.save="figure.pdf"writes the figure to a file in both cases. - The colours come from one theme, changed with :func:
set_plot_theme, and each plot takescolorsorcmapfor a single figure. No function changesrcParams.
PlotTheme
dataclass
Colours shared by every plot of the package.
Attributes:
| Name | Type | Description |
|---|---|---|
colors |
tuple[str, ...]
|
Colours of the things that are told apart by name: the fuzzy sets of a feature, in the membership plot and in the table of the rule base, the training and validation curves, the classes. |
sequential |
str
|
Colormap of the tables whose cells are amounts, from little to much: the confusion matrix and the rule activation. |
reference |
str
|
Colour of the lines that mark a reference: thresholds, the decision boundary, the best epoch. |
Source code in highfis/plotting.py
get_plot_theme
plot
Draw the plot named kind for a fitted estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
Any
|
A fitted estimator. |
required |
kind
|
str
|
One of |
'memberships'
|
**kwargs
|
Any
|
Arguments of the corresponding |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The |
Any
|
was displayed. |
Source code in highfis/plotting.py
plot_diagnostics
Plot two views of the predictions on (X, y).
For a classifier: the confusion matrix, and the decision margin of every sample grouped by its true class. The margin is the probability given to the true class minus the highest probability given to another class, so it is negative for the samples that are misclassified.
For a regressor: predicted against observed values, and the residuals against the observed values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
Any
|
A fitted estimator. |
required |
X
|
Any
|
Data to predict. |
required |
y
|
Any
|
True labels or targets for |
required |
cmap
|
str | None
|
Colormap of the confusion matrix. |
None
|
colors
|
Sequence[str] | None
|
Colours of the classes in the decision margin, or of the points of a
regressor. |
None
|
ax
|
Any
|
Two axes to draw on. |
None
|
show
|
Display the figure and return nothing ( |
required | |
save
|
Path of a file to write the figure to, in the format of its extension. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The |
Source code in highfis/plotting.py
plot_feature_importance
Plot the features that weigh most in the consequents of the fitted model.
The importance is the one of estimator.feature_importance(): the mean magnitude of
the consequent coefficients of each feature, normalized to sum to one. Features are
named as in fit when the data had names, and by their column otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
Any
|
A fitted estimator. |
required |
top
|
int | None
|
Number of features to draw, from the most important. |
20
|
colors
|
Sequence[str] | None
|
Colour of the bars, as a sequence whose first colour is used. |
None
|
ax
|
Any
|
Axes to draw on. |
None
|
show
|
Display the figure and return nothing ( |
required | |
save
|
Path of a file to write the figure to, in the format of its extension. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The |
Source code in highfis/plotting.py
plot_gates
Plot the gates of the features and of the rules that a gated family kept.
Only DG-TSK, DG-ALETSK and FSRE-ADATSK have gates. The bars are the gate values at the
end of the phase that trained them, for the features in selected_features_ and for
the rules of the fitted model, and the dashed line is the threshold they passed. The
gate of FSRE-ADATSK is an odd function, so its magnitude is drawn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
Any
|
A fitted estimator of a gated family. |
required |
colors
|
Sequence[str] | None
|
Colour of the bars, as a sequence whose first colour is used. |
None
|
ax
|
Any
|
Two axes to draw on, for the features and for the rules. |
None
|
show
|
Display the figure and return nothing ( |
required | |
save
|
Path of a file to write the figure to, in the format of its extension. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The |
Source code in highfis/plotting.py
plot_history
Plot the training loss, or a metric, per epoch.
The validation curve is drawn when a validation set was passed to fit, and the
best epoch is marked when early stopping recorded one. Families that train in several
phases (DG-TSK, DG-ALETSK, FSRE-ADATSK) get one panel per phase, side by side and on
the same vertical scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
Any
|
A fitted estimator. |
required |
metric
|
str | None
|
Name of a metric recorded during |
None
|
colors
|
Sequence[str] | None
|
Colours of the training and of the validation curve. |
None
|
ax
|
Any
|
Axes to draw on, one per training phase. |
None
|
show
|
Display the figure and return nothing ( |
required | |
save
|
Path of a file to write the figure to, in the format of its extension. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The |
Any
|
family that trains in several phases. |
Source code in highfis/plotting.py
plot_memberships
Plot the learned fuzzy sets, one panel per feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
Any
|
A fitted estimator. |
required |
features
|
Sequence[int | str] | None
|
Features to show, as names or as column indices of the data seen in
|
None
|
X
|
Any
|
Optional data. When given, each panel spans the range of its column; otherwise the range is taken from the parameters of the fuzzy sets. |
None
|
max_features
|
int
|
Number of features shown when |
6
|
n_points
|
int
|
Number of points used to draw each curve. |
200
|
set_names
|
Sequence[str] | None
|
Names of the fuzzy sets of a feature, from the lowest to the highest,
used when their number matches. By default two, three and five sets are named
|
None
|
colors
|
Sequence[str] | None
|
Colours of the fuzzy sets, from the lowest to the highest. |
None
|
ax
|
Any
|
Axes to draw on, one per feature. |
None
|
show
|
Display the figure and return nothing ( |
required | |
save
|
Path of a file to write the figure to, in the format of its extension. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The |
Source code in highfis/plotting.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
plot_rule_activation
Plot the mean normalized firing strength of each rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
Any
|
A fitted estimator. |
required |
X
|
Any
|
Data on which the rules are evaluated. |
required |
y
|
Any
|
Optional class labels, for classifiers only. When given, the mean activation is computed separately for the samples of each class. |
None
|
cmap
|
str | None
|
Colormap of the table drawn when |
None
|
colors
|
Sequence[str] | None
|
Colour of the bars drawn when |
None
|
ax
|
Any
|
Axes to draw on. |
None
|
show
|
Display the figure and return nothing ( |
required | |
save
|
Path of a file to write the figure to, in the format of its extension. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The |
Source code in highfis/plotting.py
plot_rules
Plot the rule base as a table: one row per rule, one column per feature.
Each cell is the fuzzy set that the rule uses on the feature. A set has the colour it
has in :func:plot_memberships, the first colour for the lowest set of a feature, and
in small rule bases it is labelled with the initials of its name: VL for very
low, M for medium. A blank cell is a feature that the rule does not use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
Any
|
A fitted estimator. |
required |
features
|
Sequence[int | str] | None
|
Features to show, as names or as column indices of the data seen in
|
None
|
max_features
|
int
|
Number of features shown when |
12
|
set_names
|
Sequence[str] | None
|
Names of the fuzzy sets of a feature, as in :func: |
None
|
colors
|
Sequence[str] | None
|
Colours of the fuzzy sets, from the lowest to the highest. |
None
|
cmap
|
str | None
|
Colormap that shades the cells from the lowest set to the highest, in place of one colour per set. It is also what is used, with the sequential colormap of the theme, when a feature has more sets than there are colours. |
None
|
ax
|
Any
|
Axes to draw on. |
None
|
show
|
Display the figure and return nothing ( |
required | |
save
|
Path of a file to write the figure to, in the format of its extension. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The |
Source code in highfis/plotting.py
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | |
reset_plot_theme
set_plot_theme
Change the colours of every plot drawn from now on.
Only the arguments given are changed. Colours are anything matplotlib accepts as a colour, and colormaps are names of matplotlib colormaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colors
|
Sequence[str] | None
|
Colours of the things told apart by name, in the order they are used. |
None
|
sequential
|
str | None
|
Colormap of the confusion matrix and of the rule activation. |
None
|
reference
|
str | None
|
Colour of the reference lines. |
None
|
Returns:
| Type | Description |
|---|---|
PlotTheme
|
The theme now in use. |