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."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. - No function calls
plt.show()or changesrcParams.
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 |
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 |
ax
|
Any
|
Two axes to draw on. |
None
|
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
|
ax
|
Any
|
Axes to draw on. |
None
|
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 |
ax
|
Any
|
Two axes to draw on, for the features and for the rules. |
None
|
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) show the phases one after the other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
Any
|
A fitted estimator. |
required |
metric
|
str | None
|
Name of a metric recorded during |
None
|
ax
|
Any
|
Axes to draw on. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The |
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
|
ax
|
Any
|
Axes to draw on, one per feature. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The |
Source code in highfis/plotting.py
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
|
ax
|
Any
|
Axes to draw on. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The |