Utilities#
Exceptions#
Raised when a feature needs a package that is not installed because it is optional. |
|
Raised by a stump (or splitter, or transformer) that cannot split the instances of a node. |
Optional dependencies#
Import an optional dependency. |
Drawing#
RuleTree.plot_tree and RuleTree.export_graphviz draw with this module, whose functions also
draw a subtree from its root node; its default colors are DEFAULT_COLORS.
Drawing of a tree, or of a subtree from its root node, with matplotlib (RuleTree.plot_tree), in the
style of sklearn.tree.plot_tree, and as a Graphviz graph (export_graphviz) with the same boxes.
Each internal node shows what its stump returns from get_plot_rule: the rule as text and the
media of its split, saved in the stump and drawn as images, time series or texts: e.g. the shapelets,
always drawn, and the pivots, drawn with show_media. They are drawn below the rule or, for the
splits that compare two of them (e.g. the proximity stumps), on the arrows of the two children. Each leaf
shows its prediction. The leaves are placed from left to right in the order of the tree, and each
internal node above the middle of its children, so the boxes never overlap.
Draw the subtree of a node with matplotlib. |
|
The subtree of a node as a Graphviz graph, with the boxes, colors and media of |
Embeddings#
Images and texts as vectors, for the pivot stumps (they need the embeddings extra).
Embeddings of images and texts with pretrained neural networks, the embedder of the pivot stumps.
The pivot stumps compare instances by their distance, computed on vectors: with an embedder, on the
embeddings of the instances, as in the PivotTree paper: the representation of an image is the output of
the penultimate layer of a convolutional network (e.g. ResNet or VGG), the one of a text the embedding
of a sentence transformer. Both transformers follow the scikit-learn interface. They need the
embeddings extra (PyTorch, torchvision and sentence-transformers); the weights of the networks are
downloaded the first time.
Representation of images as the output of the penultimate layer of a convolutional network of torchvision, e.g. a ResNet or a VGG pretrained on ImageNet. |
|
Representation of texts as the embeddings of a sentence transformer (sentence-transformers), the representation used for the texts in the PivotTree paper ( |
Constants#
Constants of RuleTree.
- MODEL_TYPE_CLF, MODEL_TYPE_REG, MODEL_TYPE_CLU
Tasks: classification, regression and clustering.
- DATA_TYPE_TABULAR, DATA_TYPE_TS, DATA_TYPE_IMAGE, DATA_TYPE_TEXT
Data types: tabular data, time series, images and texts.
- DATA_INPUT_TYPES
Data type of each input argument of fit and predict (X, X_ts, X_img, X_txt).
Saving#
JSON encoder that handles NumPy data types. |
Fairness and privacy#
Computes the balance fairness metric between protected attributes and class labels. |
|
Calculates the maximum fairness cost based on deviation from an ideal distribution. |
|
Evaluates privacy preservation based on k-anonymity, l-diversity, and t-closeness. |
Clustering#
Bayesian information criterion for the current model on the input X. |
Shapelets#
The shapelet transforms used by the shapelet and proximity stumps (they need the shapelets
extra).
Shapelets transformer for time series classification. |
|
Transform of tabular data into distances from partial pivots: instances restricted to a subset of their features (the other features are nan). |
Factor analysis#
The principal component analyses used by the clustering trees, from the light_famd package.
Principal Component Analysis. |
|
Correspondence Analysis of a contingency table. |
|
Multiple Correspondence Analysis of categorical data: a CA of their one-hot encoding. |
|
Multiple Factor Analysis: a PCA of groups of features, each normalized by its first singular value. |
|
Factor Analysis of Mixed Data: an MFA with a group of numerical features and a group of categorical features. |