Utilities#

Exceptions#

MissingOptionalDependencyError

Raised when a feature needs a package that is not installed because it is optional.

NoSplitFoundWarning

Raised by a stump (or splitter, or transformer) that cannot split the instances of a node.

Optional dependencies#

import_optional

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.

plot_tree

Draw the subtree of a node with matplotlib.

export_graphviz

The subtree of a node as a Graphviz graph, with the boxes, colors and media of plot_tree (see RuleTree.export_graphviz for the parameters).

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.

ImageEmbedder

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.

TextEmbedder

Representation of texts as the embeddings of a sentence transformer (sentence-transformers), the representation used for the texts in the PivotTree paper (all-mpnet-base-v2).

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_numpy_encoder

JSON encoder that handles NumPy data types.

Fairness and privacy#

balance_metric

Computes the balance fairness metric between protected attributes and class labels.

max_fairness_cost

Calculates the maximum fairness cost based on deviation from an ideal distribution.

privacy_metric

Evaluates privacy preservation based on k-anonymity, l-diversity, and t-closeness.

Clustering#

bic

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

Shapelets transformer for time series classification.

TabularShapelets

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.

PCA

Principal Component Analysis.

CA

Correspondence Analysis of a contingency table.

MCA

Multiple Correspondence Analysis of categorical data: a CA of their one-hot encoding.

MFA

Multiple Factor Analysis: a PCA of groups of features, each normalized by its first singular value.

FAMD

Factor Analysis of Mixed Data: an MFA with a group of numerical features and a group of categorical features.