neural_trees.HardDecisionTree#

class neural_trees.HardDecisionTree(weights, biases, node_distributions, classes, n_features_in, is_split=None)[source]#

Bases: object

A trained Soft Decision Tree with its gates read as hard decisions.

Each internal node routes right when w . x + b > 0 and left otherwise, and each leaf carries the class distribution the soft tree learned for it. Prediction is a walk of depth steps in numpy, with no PyTorch involved.

Built by SoftDecisionTree.to_hard_tree() rather than directly.

Attributes:
depthint
classes_ndarray of shape (n_classes,)
n_features_in_int
weights_ndarray of shape (n_internal, n_features)

One hyperplane per internal node, in breadth-first order.

biases_ndarray of shape (n_internal,)
node_distributions_ndarray of shape (n_nodes, n_classes)

A distribution per node. leaf_distributions_ selects the ones that act as leaves.

is_split_ndarray of shape (n_internal,)

Whether each internal node routes onward. All True for a complete tree.

export_text(feature_names=None, max_features=3, decimals=3) str[source]#

Render the tree as readable rules.

Parameters:
feature_nameslist of str, optional

Defaults to x0, x1, …

max_featuresint, default=3

Features shown per split, largest absolute weight first. A multivariate split uses every feature; printing all of them stops being readable, which is the thing this method is for.

decimalsint, default=3
Returns:
str
property leaf_distributions_: ndarray#

Distributions of the nodes that actually behave as leaves.

predict(X) ndarray[source]#

Predicted class labels, shape (n_samples,).

predict_proba(X) ndarray[source]#

Class probabilities of the reached leaf, shape (n_samples, n_classes).

score(X, y) float[source]#

Mean accuracy on the given data.