neural_trees.MultivariateDecisionTree#
- class neural_trees.MultivariateDecisionTree(max_depth: int = 4, min_samples_split: int = 10, min_samples_leaf: int = 3, min_impurity_decrease: float = 0.0, random_state: int | None = None, class_weight=None, min_weight_fraction_leaf: float = 0.0)[source]#
Bases:
ClassifierMixin,BaseEstimatorMultivariate Decision Tree Classifier (sklearn-compatible).
Each internal node splits on a linear combination of all features, w . x + b > 0, where w is a linear discriminant fitted on the samples reaching that node. Boundaries are oblique rather than axis-aligned, so correlated features are handled in one node instead of a staircase of univariate cuts.
- Parameters:
- max_depthint, default=4
Maximum depth of the tree.
- min_samples_splitint, default=10
Minimum samples required to attempt a split at a node.
- min_samples_leafint, default=3
Minimum samples that must land on each side of a split.
- min_impurity_decreasefloat, default=0.0
Minimum weighted Gini decrease required to keep a split.
- min_weight_fraction_leaffloat, default=0.0
Smallest fraction of the total sample weight a child may hold, as in scikit-learn’s trees. Only meaningful with sample_weight or class_weight; it stops a split from isolating a region whose weight is negligible, which is how a down-weighted class would otherwise keep leaves of its own.
- random_stateint or None, default=None
Seed for the centroid clustering used to build two-group problems when a node holds more than two classes.
- class_weightdict, “balanced” or None, default=None
Weights per class, combined multiplicatively with sample_weight. “balanced” uses n_samples / (n_classes * bincount(y)).
- Attributes:
- classes_ndarray of shape (n_classes,)
- n_features_in_int
- root_internal node object
- tree_depth_int
Depth actually reached after fitting.
- n_nodes_int
Number of internal (splitting) nodes.
References
Alpaydın, E., & Çetin, Ü. (1995). Multivariate Statistical Techniques for Constructive Induction. Yıldız, O. T., & Alpaydın, E. (2001). Omnivariate Decision Trees. IEEE TNN.
Examples
>>> from neural_trees import MultivariateDecisionTree >>> from sklearn.datasets import load_wine >>> X, y = load_wine(return_X_y=True) >>> mdt = MultivariateDecisionTree(max_depth=3, random_state=0) >>> mdt.fit(X, y) >>> mdt.score(X, y)
- fit(X, y, sample_weight=None) MultivariateDecisionTree[source]#
Fit the multivariate tree.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
- yarray-like of shape (n_samples,)
- sample_weightarray-like of shape (n_samples,), default=None
Enters the discriminant at every node (weighted class means, pooled covariance and prior ratio), the Gini decrease and the leaf distributions. min_samples_split and min_samples_leaf keep counting rows, as scikit-learn’s trees do, so weighting a row is not the same as repeating it where those limits bind. Without weights the node discriminant is scikit-learn’s own solver, unchanged.
- Returns:
- self
- get_split_weights() List[Tuple[ndarray, float]][source]#
Return the hyperplane of every internal node as (w, b) pairs, in pre-order. Useful for reading off which features drive a split.
- predict(X) ndarray[source]#
Predict class labels.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
- Returns:
- y_predndarray of shape (n_samples,)
- predict_proba(X) ndarray[source]#
Predict class probabilities from the reached leaf’s class distribution.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
- Returns:
- probandarray of shape (n_samples, n_classes)
- set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MultivariateDecisionTree#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter infit.
- Returns:
- selfobject
The updated object.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MultivariateDecisionTree#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
- Returns:
- selfobject
The updated object.